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
7475c1f3
Commit
7475c1f3
authored
Sep 26, 2011
by
Han-Wen Nienhuys
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create directories and files in r/w storage that are writable.
Make all tests freeze r/o storage before commencing.
parent
a764b4d5
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
79 additions
and
43 deletions
+79
-43
unionfs/unionfs.go
unionfs/unionfs.go
+13
-3
unionfs/unionfs_test.go
unionfs/unionfs_test.go
+66
-40
No files found.
unionfs/unionfs.go
View file @
7475c1f3
...
...
@@ -278,6 +278,15 @@ func (me *UnionFs) Promote(name string, srcResult branchResult, context *fuse.Co
if
srcResult
.
attr
.
IsRegular
()
{
code
=
fuse
.
CopyFile
(
sourceFs
,
writable
,
name
,
name
,
context
)
if
code
.
Ok
()
{
code
=
writable
.
Chmod
(
name
,
srcResult
.
attr
.
Mode
&
07777
|
0200
,
context
)
}
if
code
.
Ok
()
{
code
=
writable
.
Utimens
(
name
,
uint64
(
srcResult
.
attr
.
Atime_ns
),
uint64
(
srcResult
.
attr
.
Mtime_ns
),
context
)
}
files
:=
me
.
nodeFs
.
AllFiles
(
name
,
0
)
for
_
,
fileWrapper
:=
range
files
{
if
!
code
.
Ok
()
{
...
...
@@ -312,12 +321,13 @@ func (me *UnionFs) Promote(name string, srcResult branchResult, context *fuse.Co
code
=
writable
.
Symlink
(
link
,
name
,
context
)
}
}
else
if
srcResult
.
attr
.
IsDirectory
()
{
code
=
writable
.
Mkdir
(
name
,
0755
,
context
)
code
=
writable
.
Mkdir
(
name
,
srcResult
.
attr
.
Mode
&
07777
|
0200
,
context
)
}
else
{
log
.
Println
(
"Unknown file type:"
,
srcResult
.
attr
)
return
fuse
.
ENOSYS
}
if
!
code
.
Ok
()
{
me
.
branchCache
.
GetFresh
(
name
)
return
code
...
...
@@ -625,9 +635,9 @@ func (me *UnionFs) promoteDirsTo(filename string) fuse.Status {
j
:=
len
(
todo
)
-
i
-
1
d
:=
todo
[
j
]
r
:=
results
[
j
]
code
:=
me
.
fileSystems
[
0
]
.
Mkdir
(
d
,
r
.
attr
.
Mode
&
07777
,
nil
)
code
:=
me
.
fileSystems
[
0
]
.
Mkdir
(
d
,
r
.
attr
.
Mode
&
07777
|
0200
,
nil
)
if
code
!=
fuse
.
OK
{
log
.
Println
(
"Error creating dir leading to path"
,
d
,
code
)
log
.
Println
(
"Error creating dir leading to path"
,
d
,
code
,
me
.
fileSystems
[
0
]
)
return
fuse
.
EPERM
}
...
...
unionfs/unionfs_test.go
View file @
7475c1f3
...
...
@@ -27,6 +27,15 @@ var testOpts = UnionFsOptions{
BranchCacheTTLSecs
:
entryTtl
,
}
func
freezeRo
(
dir
string
)
{
err
:=
filepath
.
Walk
(
dir
,
func
(
path
string
,
fi
*
os
.
FileInfo
,
err
os
.
Error
)
os
.
Error
{
return
os
.
Chmod
(
path
,
(
fi
.
Mode
&
0777
)
&^
0222
)
})
CheckSuccess
(
err
)
}
func
setupUfs
(
t
*
testing
.
T
)
(
workdir
string
,
cleanup
func
())
{
// Make sure system setting does not affect test.
syscall
.
Umask
(
0
)
...
...
@@ -127,7 +136,7 @@ func remove(path string) {
fuse
.
CheckSuccess
(
err
)
}
func
TestAutocreateDeletionDir
(
t
*
testing
.
T
)
{
func
Test
UnionFs
AutocreateDeletionDir
(
t
*
testing
.
T
)
{
wd
,
clean
:=
setupUfs
(
t
)
defer
clean
()
...
...
@@ -141,7 +150,7 @@ func TestAutocreateDeletionDir(t *testing.T) {
CheckSuccess
(
err
)
}
func
TestSymlink
(
t
*
testing
.
T
)
{
func
Test
UnionFs
Symlink
(
t
*
testing
.
T
)
{
wd
,
clean
:=
setupUfs
(
t
)
defer
clean
()
...
...
@@ -156,7 +165,7 @@ func TestSymlink(t *testing.T) {
}
}
func
TestSymlinkPromote
(
t
*
testing
.
T
)
{
func
Test
UnionFs
SymlinkPromote
(
t
*
testing
.
T
)
{
wd
,
clean
:=
setupUfs
(
t
)
defer
clean
()
...
...
@@ -167,7 +176,7 @@ func TestSymlinkPromote(t *testing.T) {
CheckSuccess
(
err
)
}
func
TestChtimes
(
t
*
testing
.
T
)
{
func
Test
UnionFs
Chtimes
(
t
*
testing
.
T
)
{
wd
,
clean
:=
setupUfs
(
t
)
defer
clean
()
...
...
@@ -184,7 +193,7 @@ func TestChtimes(t *testing.T) {
}
}
func
TestChmod
(
t
*
testing
.
T
)
{
func
Test
UnionFs
Chmod
(
t
*
testing
.
T
)
{
wd
,
clean
:=
setupUfs
(
t
)
defer
clean
()
...
...
@@ -205,7 +214,7 @@ func TestChmod(t *testing.T) {
}
}
func
TestChown
(
t
*
testing
.
T
)
{
func
Test
UnionFs
Chown
(
t
*
testing
.
T
)
{
wd
,
clean
:=
setupUfs
(
t
)
defer
clean
()
...
...
@@ -220,7 +229,7 @@ func TestChown(t *testing.T) {
}
}
func
TestDelete
(
t
*
testing
.
T
)
{
func
Test
UnionFs
Delete
(
t
*
testing
.
T
)
{
wd
,
clean
:=
setupUfs
(
t
)
defer
clean
()
...
...
@@ -250,7 +259,7 @@ func TestDelete(t *testing.T) {
}
}
func
TestBasic
(
t
*
testing
.
T
)
{
func
Test
UnionFs
Basic
(
t
*
testing
.
T
)
{
wd
,
clean
:=
setupUfs
(
t
)
defer
clean
()
...
...
@@ -311,7 +320,7 @@ func TestBasic(t *testing.T) {
}
}
func
TestPromote
(
t
*
testing
.
T
)
{
func
Test
UnionFs
Promote
(
t
*
testing
.
T
)
{
wd
,
clean
:=
setupUfs
(
t
)
defer
clean
()
...
...
@@ -321,7 +330,7 @@ func TestPromote(t *testing.T) {
writeToFile
(
wd
+
"/mount/subdir/file"
,
"other-content"
)
}
func
TestCreate
(
t
*
testing
.
T
)
{
func
Test
UnionFs
Create
(
t
*
testing
.
T
)
{
wd
,
clean
:=
setupUfs
(
t
)
defer
clean
()
...
...
@@ -332,7 +341,7 @@ func TestCreate(t *testing.T) {
CheckSuccess
(
err
)
}
func
TestOpenUndeletes
(
t
*
testing
.
T
)
{
func
Test
UnionFs
OpenUndeletes
(
t
*
testing
.
T
)
{
wd
,
clean
:=
setupUfs
(
t
)
defer
clean
()
...
...
@@ -344,7 +353,7 @@ func TestOpenUndeletes(t *testing.T) {
CheckSuccess
(
err
)
}
func
TestMkdir
(
t
*
testing
.
T
)
{
func
Test
UnionFs
Mkdir
(
t
*
testing
.
T
)
{
wd
,
clean
:=
setupUfs
(
t
)
defer
clean
()
...
...
@@ -356,7 +365,7 @@ func TestMkdir(t *testing.T) {
CheckSuccess
(
err
)
}
func
TestMkdirPromote
(
t
*
testing
.
T
)
{
func
Test
UnionFs
MkdirPromote
(
t
*
testing
.
T
)
{
wd
,
clean
:=
setupUfs
(
t
)
defer
clean
()
...
...
@@ -373,7 +382,7 @@ func TestMkdirPromote(t *testing.T) {
}
}
func
TestRmdirMkdir
(
t
*
testing
.
T
)
{
func
Test
UnionFs
RmdirMkdir
(
t
*
testing
.
T
)
{
wd
,
clean
:=
setupUfs
(
t
)
defer
clean
()
...
...
@@ -388,7 +397,7 @@ func TestRmdirMkdir(t *testing.T) {
CheckSuccess
(
err
)
}
func
TestRename
(
t
*
testing
.
T
)
{
func
Test
UnionFs
Rename
(
t
*
testing
.
T
)
{
type
Config
struct
{
f1_ro
bool
f1_rw
bool
...
...
@@ -446,7 +455,7 @@ func TestRename(t *testing.T) {
}
}
func
TestRenameDirBasic
(
t
*
testing
.
T
)
{
func
Test
UnionFs
RenameDirBasic
(
t
*
testing
.
T
)
{
wd
,
clean
:=
setupUfs
(
t
)
defer
clean
()
...
...
@@ -474,7 +483,7 @@ func TestRenameDirBasic(t *testing.T) {
}
}
func
TestRenameDirAllSourcesGone
(
t
*
testing
.
T
)
{
func
Test
UnionFs
RenameDirAllSourcesGone
(
t
*
testing
.
T
)
{
wd
,
clean
:=
setupUfs
(
t
)
defer
clean
()
...
...
@@ -484,6 +493,7 @@ func TestRenameDirAllSourcesGone(t *testing.T) {
err
=
ioutil
.
WriteFile
(
wd
+
"/ro/dir/file.txt"
,
[]
byte
{
42
},
0644
)
CheckSuccess
(
err
)
freezeRo
(
wd
+
"/ro"
)
err
=
os
.
Rename
(
wd
+
"/mount/dir"
,
wd
+
"/mount/renamed"
)
CheckSuccess
(
err
)
...
...
@@ -493,7 +503,7 @@ func TestRenameDirAllSourcesGone(t *testing.T) {
}
}
func
TestRenameDirWithDeletions
(
t
*
testing
.
T
)
{
func
Test
UnionFs
RenameDirWithDeletions
(
t
*
testing
.
T
)
{
wd
,
clean
:=
setupUfs
(
t
)
defer
clean
()
...
...
@@ -505,6 +515,7 @@ func TestRenameDirWithDeletions(t *testing.T) {
err
=
ioutil
.
WriteFile
(
wd
+
"/ro/dir/subdir/file.txt"
,
[]
byte
{
42
},
0644
)
CheckSuccess
(
err
)
freezeRo
(
wd
+
"/ro"
)
if
fi
,
_
:=
os
.
Lstat
(
wd
+
"/mount/dir/subdir/file.txt"
);
fi
==
nil
||
!
fi
.
IsRegular
()
{
t
.
Fatalf
(
"%s/mount/dir/subdir/file.txt should be file: %v"
,
wd
,
fi
)
...
...
@@ -541,7 +552,7 @@ func TestRenameDirWithDeletions(t *testing.T) {
}
}
func
TestRenameSymlink
(
t
*
testing
.
T
)
{
func
Test
UnionFs
RenameSymlink
(
t
*
testing
.
T
)
{
wd
,
clean
:=
setupUfs
(
t
)
defer
clean
()
...
...
@@ -564,13 +575,14 @@ func TestRenameSymlink(t *testing.T) {
}
}
func
TestWritableDir
(
t
*
testing
.
T
)
{
func
Test
UnionFs
WritableDir
(
t
*
testing
.
T
)
{
wd
,
clean
:=
setupUfs
(
t
)
defer
clean
()
dirname
:=
wd
+
"/ro/subdir"
err
:=
os
.
Mkdir
(
dirname
,
0555
)
CheckSuccess
(
err
)
freezeRo
(
wd
+
"/ro"
)
fi
,
err
:=
os
.
Lstat
(
wd
+
"/mount/subdir"
)
CheckSuccess
(
err
)
...
...
@@ -579,7 +591,7 @@ func TestWritableDir(t *testing.T) {
}
}
func
TestWriteAccess
(
t
*
testing
.
T
)
{
func
Test
UnionFs
WriteAccess
(
t
*
testing
.
T
)
{
wd
,
clean
:=
setupUfs
(
t
)
defer
clean
()
...
...
@@ -587,6 +599,7 @@ func TestWriteAccess(t *testing.T) {
// No write perms.
err
:=
ioutil
.
WriteFile
(
fn
,
[]
byte
(
"foo"
),
0444
)
CheckSuccess
(
err
)
freezeRo
(
wd
+
"/ro"
)
errno
:=
syscall
.
Access
(
wd
+
"/mount/file"
,
fuse
.
W_OK
)
if
errno
!=
0
{
...
...
@@ -595,7 +608,7 @@ func TestWriteAccess(t *testing.T) {
}
}
func
TestLink
(
t
*
testing
.
T
)
{
func
Test
UnionFs
Link
(
t
*
testing
.
T
)
{
wd
,
clean
:=
setupUfs
(
t
)
defer
clean
()
...
...
@@ -603,6 +616,7 @@ func TestLink(t *testing.T) {
fn
:=
wd
+
"/ro/file"
err
:=
ioutil
.
WriteFile
(
fn
,
[]
byte
(
content
),
0666
)
CheckSuccess
(
err
)
freezeRo
(
wd
+
"/ro"
)
err
=
os
.
Link
(
wd
+
"/mount/file"
,
wd
+
"/mount/linked"
)
CheckSuccess
(
err
)
...
...
@@ -621,11 +635,13 @@ func TestLink(t *testing.T) {
}
}
func
TestTruncate
(
t
*
testing
.
T
)
{
func
Test
UnionFs
Truncate
(
t
*
testing
.
T
)
{
wd
,
clean
:=
setupUfs
(
t
)
defer
clean
()
writeToFile
(
wd
+
"/ro/file"
,
"hello"
)
freezeRo
(
wd
+
"/ro"
)
os
.
Truncate
(
wd
+
"/mount/file"
,
2
)
content
:=
readFromFile
(
wd
+
"/mount/file"
)
if
content
!=
"he"
{
...
...
@@ -637,7 +653,7 @@ func TestTruncate(t *testing.T) {
}
}
func
TestCopyChmod
(
t
*
testing
.
T
)
{
func
Test
UnionFs
CopyChmod
(
t
*
testing
.
T
)
{
wd
,
clean
:=
setupUfs
(
t
)
defer
clean
()
...
...
@@ -669,7 +685,7 @@ func abs(dt int64) int64 {
return
-
dt
}
func
TestTruncateTimestamp
(
t
*
testing
.
T
)
{
func
Test
UnionFs
TruncateTimestamp
(
t
*
testing
.
T
)
{
wd
,
clean
:=
setupUfs
(
t
)
defer
clean
()
...
...
@@ -691,7 +707,7 @@ func TestTruncateTimestamp(t *testing.T) {
}
}
func
TestRemoveAll
(
t
*
testing
.
T
)
{
func
Test
UnionFs
RemoveAll
(
t
*
testing
.
T
)
{
wd
,
clean
:=
setupUfs
(
t
)
defer
clean
()
...
...
@@ -702,6 +718,7 @@ func TestRemoveAll(t *testing.T) {
fn
:=
wd
+
"/ro/dir/subdir/y"
err
=
ioutil
.
WriteFile
(
fn
,
[]
byte
(
contents
),
0644
)
CheckSuccess
(
err
)
freezeRo
(
wd
+
"/ro"
)
err
=
os
.
RemoveAll
(
wd
+
"/mount/dir"
)
if
err
!=
nil
{
...
...
@@ -721,7 +738,7 @@ func TestRemoveAll(t *testing.T) {
}
}
func
TestRmRf
(
t
*
testing
.
T
)
{
func
Test
UnionFs
RmRf
(
t
*
testing
.
T
)
{
wd
,
clean
:=
setupUfs
(
t
)
defer
clean
()
...
...
@@ -732,6 +749,8 @@ func TestRmRf(t *testing.T) {
fn
:=
wd
+
"/ro/dir/subdir/y"
err
=
ioutil
.
WriteFile
(
fn
,
[]
byte
(
contents
),
0644
)
CheckSuccess
(
err
)
freezeRo
(
wd
+
"/ro"
)
bin
,
err
:=
exec
.
LookPath
(
"rm"
)
CheckSuccess
(
err
)
cmd
:=
exec
.
Command
(
bin
,
"-rf"
,
wd
+
"/mount/dir"
)
...
...
@@ -763,12 +782,14 @@ func Readdirnames(dir string) ([]string, os.Error) {
return
f
.
Readdirnames
(
-
1
)
}
func
TestDropDeletionCache
(
t
*
testing
.
T
)
{
func
Test
UnionFs
DropDeletionCache
(
t
*
testing
.
T
)
{
wd
,
clean
:=
setupUfs
(
t
)
defer
clean
()
err
:=
ioutil
.
WriteFile
(
wd
+
"/ro/file"
,
[]
byte
(
"bla"
),
0644
)
CheckSuccess
(
err
)
freezeRo
(
wd
+
"/ro"
)
_
,
err
=
os
.
Lstat
(
wd
+
"/mount/file"
)
CheckSuccess
(
err
)
err
=
os
.
Remove
(
wd
+
"/mount/file"
)
...
...
@@ -799,7 +820,7 @@ func TestDropDeletionCache(t *testing.T) {
}
}
func
TestDropCache
(
t
*
testing
.
T
)
{
func
Test
UnionFs
DropCache
(
t
*
testing
.
T
)
{
wd
,
clean
:=
setupUfs
(
t
)
defer
clean
()
...
...
@@ -830,7 +851,7 @@ func TestDropCache(t *testing.T) {
}
}
func
TestDisappearing
(
t
*
testing
.
T
)
{
func
Test
UnionFs
Disappearing
(
t
*
testing
.
T
)
{
// This init is like setupUfs, but we want access to the
// writable Fs.
wd
,
_
:=
ioutil
.
TempDir
(
""
,
""
)
...
...
@@ -862,10 +883,11 @@ func TestDisappearing(t *testing.T) {
state
.
Debug
=
fuse
.
VerboseTest
()
go
state
.
Loop
()
log
.
Println
(
"TestDisappearing2"
)
log
.
Println
(
"Test
UnionFs
Disappearing2"
)
err
=
ioutil
.
WriteFile
(
wd
+
"/ro/file"
,
[]
byte
(
"blabla"
),
0644
)
CheckSuccess
(
err
)
freezeRo
(
wd
+
"/ro"
)
err
=
os
.
Remove
(
wd
+
"/mount/file"
)
CheckSuccess
(
err
)
...
...
@@ -900,12 +922,13 @@ func TestDisappearing(t *testing.T) {
}
}
func
TestDeletedGetAttr
(
t
*
testing
.
T
)
{
func
Test
UnionFs
DeletedGetAttr
(
t
*
testing
.
T
)
{
wd
,
clean
:=
setupUfs
(
t
)
defer
clean
()
err
:=
ioutil
.
WriteFile
(
wd
+
"/ro/file"
,
[]
byte
(
"blabla"
),
0644
)
CheckSuccess
(
err
)
freezeRo
(
wd
+
"/ro"
)
f
,
err
:=
os
.
Open
(
wd
+
"/mount/file"
)
CheckSuccess
(
err
)
...
...
@@ -919,11 +942,12 @@ func TestDeletedGetAttr(t *testing.T) {
}
}
func
TestDoubleOpen
(
t
*
testing
.
T
)
{
func
Test
UnionFs
DoubleOpen
(
t
*
testing
.
T
)
{
wd
,
clean
:=
setupUfs
(
t
)
defer
clean
()
err
:=
ioutil
.
WriteFile
(
wd
+
"/ro/file"
,
[]
byte
(
"blablabla"
),
0644
)
CheckSuccess
(
err
)
freezeRo
(
wd
+
"/ro"
)
roFile
,
err
:=
os
.
Open
(
wd
+
"/mount/file"
)
CheckSuccess
(
err
)
...
...
@@ -954,13 +978,14 @@ func TestDoubleOpen(t *testing.T) {
}
}
func
TestFdLeak
(
t
*
testing
.
T
)
{
func
Test
UnionFs
FdLeak
(
t
*
testing
.
T
)
{
beforeEntries
,
err
:=
ioutil
.
ReadDir
(
"/proc/self/fd"
)
CheckSuccess
(
err
)
wd
,
clean
:=
setupUfs
(
t
)
err
=
ioutil
.
WriteFile
(
wd
+
"/ro/file"
,
[]
byte
(
"blablabla"
),
0644
)
CheckSuccess
(
err
)
freezeRo
(
wd
+
"/ro"
)
contents
,
err
:=
ioutil
.
ReadFile
(
wd
+
"/mount/file"
)
CheckSuccess
(
err
)
...
...
@@ -978,7 +1003,7 @@ func TestFdLeak(t *testing.T) {
}
}
func
TestStatFs
(
t
*
testing
.
T
)
{
func
Test
UnionFs
StatFs
(
t
*
testing
.
T
)
{
wd
,
clean
:=
setupUfs
(
t
)
defer
clean
()
...
...
@@ -992,7 +1017,7 @@ func TestStatFs(t *testing.T) {
}
}
func
TestFlushSize
(
t
*
testing
.
T
)
{
func
Test
UnionFs
FlushSize
(
t
*
testing
.
T
)
{
wd
,
clean
:=
setupUfs
(
t
)
defer
clean
()
...
...
@@ -1013,7 +1038,7 @@ func TestFlushSize(t *testing.T) {
}
}
func
TestFlushRename
(
t
*
testing
.
T
)
{
func
Test
UnionFs
FlushRename
(
t
*
testing
.
T
)
{
wd
,
clean
:=
setupUfs
(
t
)
defer
clean
()
...
...
@@ -1040,7 +1065,7 @@ func TestFlushRename(t *testing.T) {
}
}
func
TestTruncGetAttr
(
t
*
testing
.
T
)
{
func
Test
UnionFs
TruncGetAttr
(
t
*
testing
.
T
)
{
wd
,
clean
:=
setupUfs
(
t
)
defer
clean
()
...
...
@@ -1058,7 +1083,7 @@ func TestTruncGetAttr(t *testing.T) {
}
}
func
TestPromoteDirTimeStamp
(
t
*
testing
.
T
)
{
func
Test
UnionFs
PromoteDirTimeStamp
(
t
*
testing
.
T
)
{
wd
,
clean
:=
setupUfs
(
t
)
defer
clean
()
...
...
@@ -1066,6 +1091,7 @@ func TestPromoteDirTimeStamp(t *testing.T) {
CheckSuccess
(
err
)
err
=
ioutil
.
WriteFile
(
wd
+
"/ro/subdir/file"
,
[]
byte
(
"hello"
),
0644
)
CheckSuccess
(
err
)
freezeRo
(
wd
+
"/ro"
)
err
=
os
.
Chmod
(
wd
+
"/mount/subdir/file"
,
0060
)
CheckSuccess
(
err
)
...
...
@@ -1081,7 +1107,7 @@ func TestPromoteDirTimeStamp(t *testing.T) {
t
.
Errorf
(
"Changed timestamps on promoted subdir: ro %d rw %d"
,
fRo
.
Mtime_ns
,
fRw
.
Mtime_ns
)
}
if
fRo
.
Mode
!=
fRw
.
Mode
{
if
fRo
.
Mode
|
0200
!=
fRw
.
Mode
{
t
.
Errorf
(
"Changed mode ro: %o, rw: %o"
,
fRo
.
Mode
,
fRw
.
Mode
)
}
}
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