Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go-fuse
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Levin Zimmermann
go-fuse
Commits
bfaeb760
Commit
bfaeb760
authored
Mar 29, 2019
by
Han-Wen Nienhuys
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
nodefs: comment ExampleNewPersistentInode
parent
3377c503
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
28 deletions
+43
-28
nodefs/zip_test.go
nodefs/zip_test.go
+43
-28
No files found.
nodefs/zip_test.go
View file @
bfaeb760
...
@@ -208,43 +208,58 @@ func (zr *zipRoot) OnAdd(ctx context.Context) {
...
@@ -208,43 +208,58 @@ func (zr *zipRoot) OnAdd(ctx context.Context) {
}
}
}
}
// ExampleNewPersistentInode shows how to create a in-memory file
// Persistent inodes can be used to create an in-memory
// system a prefabricated tree.
// prefabricated file system tree.
func
ExampleNewPersistentInode
()
{
func
ExampleInode_NewPersistentInode
()
{
// This is where we'll mount the FS
mntDir
,
_
:=
ioutil
.
TempDir
(
""
,
""
)
mntDir
,
_
:=
ioutil
.
TempDir
(
""
,
""
)
files
:=
map
[
string
]
string
{
files
:=
map
[
string
]
string
{
"file"
:
"content"
,
"file"
:
"content"
,
"subdir/other-file"
:
"content"
,
"subdir/other-file"
:
"
other-
content"
,
}
}
root
:=
&
Inode
{}
root
:=
&
Inode
{}
server
,
err
:=
Mount
(
mntDir
,
root
,
&
Options
{
populate
:=
func
(
ctx
context
.
Context
)
{
MountOptions
:
fuse
.
MountOptions
{
Debug
:
true
},
OnAdd
:
func
(
ctx
context
.
Context
)
{
for
name
,
content
:=
range
files
{
for
name
,
content
:=
range
files
{
dir
,
base
:=
filepath
.
Split
(
name
)
dir
,
base
:=
filepath
.
Split
(
name
)
p
:=
root
p
:=
root
// Add directories leading up to the file.
for
_
,
component
:=
range
strings
.
Split
(
dir
,
"/"
)
{
for
_
,
component
:=
range
strings
.
Split
(
dir
,
"/"
)
{
if
len
(
component
)
==
0
{
if
len
(
component
)
==
0
{
continue
continue
}
}
ch
:=
p
.
GetChild
(
component
)
ch
:=
p
.
GetChild
(
component
)
if
ch
==
nil
{
if
ch
==
nil
{
// Create a directory
ch
=
p
.
NewPersistentInode
(
ctx
,
&
Inode
{},
ch
=
p
.
NewPersistentInode
(
ctx
,
&
Inode
{},
NodeAttr
{
Mode
:
syscall
.
S_IFDIR
})
NodeAttr
{
Mode
:
syscall
.
S_IFDIR
})
// Add it
p
.
AddChild
(
component
,
ch
,
true
)
p
.
AddChild
(
component
,
ch
,
true
)
}
}
p
=
ch
p
=
ch
}
}
// Create the file
child
:=
p
.
NewPersistentInode
(
ctx
,
&
MemRegularFile
{
child
:=
p
.
NewPersistentInode
(
ctx
,
&
MemRegularFile
{
Data
:
[]
byte
(
content
),
Data
:
[]
byte
(
content
),
},
NodeAttr
{})
},
NodeAttr
{})
// And add it
p
.
AddChild
(
base
,
child
,
true
)
p
.
AddChild
(
base
,
child
,
true
)
}
}
},
}
server
,
err
:=
Mount
(
mntDir
,
root
,
&
Options
{
MountOptions
:
fuse
.
MountOptions
{
Debug
:
true
},
// This adds read permissions to the files and
// directories, which is necessary for doing a chdir
// into the mount.
DefaultPermissions
:
true
,
OnAdd
:
populate
,
})
})
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Panic
(
err
)
log
.
Panic
(
err
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment