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
Hide 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) {
}
}
// ExampleNewPersistentInode shows how to create a in-memory file
// system a prefabricated tree.
func
ExampleNewPersistentInode
()
{
// Persistent inodes can be used to create an in-memory
// prefabricated file system tree.
func
ExampleInode_NewPersistentInode
()
{
// This is where we'll mount the FS
mntDir
,
_
:=
ioutil
.
TempDir
(
""
,
""
)
files
:=
map
[
string
]
string
{
"file"
:
"content"
,
"subdir/other-file"
:
"content"
,
"subdir/other-file"
:
"
other-
content"
,
}
root
:=
&
Inode
{}
server
,
err
:=
Mount
(
mntDir
,
root
,
&
Options
{
MountOptions
:
fuse
.
MountOptions
{
Debug
:
true
},
OnAdd
:
func
(
ctx
context
.
Context
)
{
for
name
,
content
:=
range
files
{
dir
,
base
:=
filepath
.
Split
(
name
)
p
:=
root
for
_
,
component
:=
range
strings
.
Split
(
dir
,
"/"
)
{
if
len
(
component
)
==
0
{
continue
}
ch
:=
p
.
GetChild
(
component
)
if
ch
==
nil
{
ch
=
p
.
NewPersistentInode
(
ctx
,
&
Inode
{},
NodeAttr
{
Mode
:
syscall
.
S_IFDIR
})
p
.
AddChild
(
component
,
ch
,
true
)
}
p
=
ch
populate
:=
func
(
ctx
context
.
Context
)
{
for
name
,
content
:=
range
files
{
dir
,
base
:=
filepath
.
Split
(
name
)
p
:=
root
// Add directories leading up to the file.
for
_
,
component
:=
range
strings
.
Split
(
dir
,
"/"
)
{
if
len
(
component
)
==
0
{
continue
}
ch
:=
p
.
GetChild
(
component
)
if
ch
==
nil
{
// Create a directory
ch
=
p
.
NewPersistentInode
(
ctx
,
&
Inode
{},
NodeAttr
{
Mode
:
syscall
.
S_IFDIR
})
// Add it
p
.
AddChild
(
component
,
ch
,
true
)
}
child
:=
p
.
NewPersistentInode
(
ctx
,
&
MemRegularFile
{
Data
:
[]
byte
(
content
),
},
NodeAttr
{})
p
.
AddChild
(
base
,
child
,
true
)
p
=
ch
}
},
// Create the file
child
:=
p
.
NewPersistentInode
(
ctx
,
&
MemRegularFile
{
Data
:
[]
byte
(
content
),
},
NodeAttr
{})
// And add it
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
{
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