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
Kirill Smelkov
go-fuse
Commits
d822ee41
Commit
d822ee41
authored
Oct 10, 2011
by
Han-Wen Nienhuys
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Shorten /mount to /mnt in unionfs tests.
parent
62094b64
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
223 additions
and
223 deletions
+223
-223
unionfs/autounion_test.go
unionfs/autounion_test.go
+19
-19
unionfs/memunionfs_test.go
unionfs/memunionfs_test.go
+92
-92
unionfs/unionfs_test.go
unionfs/unionfs_test.go
+112
-112
No files found.
unionfs/autounion_test.go
View file @
d822ee41
...
...
@@ -30,7 +30,7 @@ func WriteFile(name string, contents string) {
func
setup
(
t
*
testing
.
T
)
(
workdir
string
,
cleanup
func
())
{
wd
,
_
:=
ioutil
.
TempDir
(
""
,
""
)
err
:=
os
.
Mkdir
(
wd
+
"/m
ou
nt"
,
0700
)
err
:=
os
.
Mkdir
(
wd
+
"/mnt"
,
0700
)
fuse
.
CheckSuccess
(
err
)
err
=
os
.
Mkdir
(
wd
+
"/store"
,
0700
)
...
...
@@ -42,7 +42,7 @@ func setup(t *testing.T) (workdir string, cleanup func()) {
WriteFile
(
wd
+
"/ro/file2"
,
"file2"
)
fs
:=
NewAutoUnionFs
(
wd
+
"/store"
,
testAOpts
)
state
,
conn
,
err
:=
fuse
.
MountPathFileSystem
(
wd
+
"/m
ou
nt"
,
fs
,
&
testAOpts
.
FileSystemOptions
)
state
,
conn
,
err
:=
fuse
.
MountPathFileSystem
(
wd
+
"/mnt"
,
fs
,
&
testAOpts
.
FileSystemOptions
)
CheckSuccess
(
err
)
state
.
Debug
=
fuse
.
VerboseTest
()
conn
.
Debug
=
fuse
.
VerboseTest
()
...
...
@@ -58,7 +58,7 @@ func TestVersion(t *testing.T) {
wd
,
clean
:=
setup
(
t
)
defer
clean
()
c
,
err
:=
ioutil
.
ReadFile
(
wd
+
"/m
ou
nt/status/gounionfs_version"
)
c
,
err
:=
ioutil
.
ReadFile
(
wd
+
"/mnt/status/gounionfs_version"
)
CheckSuccess
(
err
)
if
len
(
c
)
==
0
{
t
.
Fatal
(
"No version found."
)
...
...
@@ -76,36 +76,36 @@ func TestAutoFsSymlink(t *testing.T) {
err
=
os
.
Symlink
(
wd
+
"/ro"
,
wd
+
"/store/backing1/READONLY"
)
CheckSuccess
(
err
)
err
=
os
.
Symlink
(
wd
+
"/store/backing1"
,
wd
+
"/m
ou
nt/config/manual1"
)
err
=
os
.
Symlink
(
wd
+
"/store/backing1"
,
wd
+
"/mnt/config/manual1"
)
CheckSuccess
(
err
)
fi
,
err
:=
os
.
Lstat
(
wd
+
"/m
ou
nt/manual1/file1"
)
fi
,
err
:=
os
.
Lstat
(
wd
+
"/mnt/manual1/file1"
)
CheckSuccess
(
err
)
entries
,
err
:=
ioutil
.
ReadDir
(
wd
+
"/m
ou
nt"
)
entries
,
err
:=
ioutil
.
ReadDir
(
wd
+
"/mnt"
)
CheckSuccess
(
err
)
if
len
(
entries
)
!=
3
{
t
.
Error
(
"readdir mismatch"
,
entries
)
}
err
=
os
.
Remove
(
wd
+
"/m
ou
nt/config/manual1"
)
err
=
os
.
Remove
(
wd
+
"/mnt/config/manual1"
)
CheckSuccess
(
err
)
scan
:=
wd
+
"/m
ou
nt/config/"
+
_SCAN_CONFIG
scan
:=
wd
+
"/mnt/config/"
+
_SCAN_CONFIG
err
=
ioutil
.
WriteFile
(
scan
,
[]
byte
(
"something"
),
0644
)
if
err
!=
nil
{
t
.
Error
(
"error writing:"
,
err
)
}
fi
,
_
=
os
.
Lstat
(
wd
+
"/m
ou
nt/manual1"
)
fi
,
_
=
os
.
Lstat
(
wd
+
"/mnt/manual1"
)
if
fi
!=
nil
{
t
.
Error
(
"Should not have file:"
,
fi
)
}
_
,
err
=
ioutil
.
ReadDir
(
wd
+
"/m
ou
nt/config"
)
_
,
err
=
ioutil
.
ReadDir
(
wd
+
"/mnt/config"
)
CheckSuccess
(
err
)
_
,
err
=
os
.
Lstat
(
wd
+
"/m
ou
nt/backing1/file1"
)
_
,
err
=
os
.
Lstat
(
wd
+
"/mnt/backing1/file1"
)
CheckSuccess
(
err
)
}
...
...
@@ -122,13 +122,13 @@ func TestDetectSymlinkedDirectories(t *testing.T) {
err
=
os
.
Symlink
(
wd
+
"/backing1"
,
wd
+
"/store/backing1"
)
CheckSuccess
(
err
)
scan
:=
wd
+
"/m
ou
nt/config/"
+
_SCAN_CONFIG
scan
:=
wd
+
"/mnt/config/"
+
_SCAN_CONFIG
err
=
ioutil
.
WriteFile
(
scan
,
[]
byte
(
"something"
),
0644
)
if
err
!=
nil
{
t
.
Error
(
"error writing:"
,
err
)
}
_
,
err
=
os
.
Lstat
(
wd
+
"/m
ou
nt/backing1"
)
_
,
err
=
os
.
Lstat
(
wd
+
"/mnt/backing1"
)
CheckSuccess
(
err
)
}
...
...
@@ -141,12 +141,12 @@ func TestExplicitScan(t *testing.T) {
os
.
Symlink
(
wd
+
"/ro"
,
wd
+
"/store/backing1/READONLY"
)
CheckSuccess
(
err
)
fi
,
_
:=
os
.
Lstat
(
wd
+
"/m
ou
nt/backing1"
)
fi
,
_
:=
os
.
Lstat
(
wd
+
"/mnt/backing1"
)
if
fi
!=
nil
{
t
.
Error
(
"Should not have file:"
,
fi
)
}
scan
:=
wd
+
"/m
ou
nt/config/"
+
_SCAN_CONFIG
scan
:=
wd
+
"/mnt/config/"
+
_SCAN_CONFIG
_
,
err
=
os
.
Lstat
(
scan
)
if
err
!=
nil
{
t
.
Error
(
".scan_config missing:"
,
err
)
...
...
@@ -157,7 +157,7 @@ func TestExplicitScan(t *testing.T) {
t
.
Error
(
"error writing:"
,
err
)
}
_
,
err
=
os
.
Lstat
(
wd
+
"/m
ou
nt/backing1"
)
_
,
err
=
os
.
Lstat
(
wd
+
"/mnt/backing1"
)
if
err
!=
nil
{
t
.
Error
(
"Should have workspace backing1:"
,
err
)
}
...
...
@@ -177,16 +177,16 @@ func TestCreationChecks(t *testing.T) {
os
.
Symlink
(
wd
+
"/ro"
,
wd
+
"/store/ws2/READONLY"
)
CheckSuccess
(
err
)
err
=
os
.
Symlink
(
wd
+
"/store/foo"
,
wd
+
"/m
ou
nt/config/bar"
)
err
=
os
.
Symlink
(
wd
+
"/store/foo"
,
wd
+
"/mnt/config/bar"
)
CheckSuccess
(
err
)
err
=
os
.
Symlink
(
wd
+
"/store/foo"
,
wd
+
"/m
ou
nt/config/foo"
)
err
=
os
.
Symlink
(
wd
+
"/store/foo"
,
wd
+
"/mnt/config/foo"
)
code
:=
fuse
.
OsErrorToErrno
(
err
)
if
code
!=
fuse
.
EBUSY
{
t
.
Error
(
"Should return EBUSY"
,
err
)
}
err
=
os
.
Symlink
(
wd
+
"/store/ws2"
,
wd
+
"/m
ou
nt/config/config"
)
err
=
os
.
Symlink
(
wd
+
"/store/ws2"
,
wd
+
"/mnt/config/config"
)
code
=
fuse
.
OsErrorToErrno
(
err
)
if
code
!=
fuse
.
EINVAL
{
t
.
Error
(
"Should return EINVAL"
,
err
)
...
...
unionfs/memunionfs_test.go
View file @
d822ee41
...
...
@@ -23,7 +23,7 @@ func setupMemUfs(t *testing.T) (workdir string, ufs *MemUnionFs, cleanup func())
syscall
.
Umask
(
0
)
wd
,
_
:=
ioutil
.
TempDir
(
""
,
""
)
err
:=
os
.
Mkdir
(
wd
+
"/m
ou
nt"
,
0700
)
err
:=
os
.
Mkdir
(
wd
+
"/mnt"
,
0700
)
fuse
.
CheckSuccess
(
err
)
err
=
os
.
Mkdir
(
wd
+
"/backing"
,
0700
)
...
...
@@ -43,7 +43,7 @@ func setupMemUfs(t *testing.T) (workdir string, ufs *MemUnionFs, cleanup func())
NegativeTimeout
:
.5
*
entryTtl
,
}
state
,
conn
,
err
:=
fuse
.
MountNodeFileSystem
(
wd
+
"/m
ou
nt"
,
memFs
,
opts
)
state
,
conn
,
err
:=
fuse
.
MountNodeFileSystem
(
wd
+
"/mnt"
,
memFs
,
opts
)
CheckSuccess
(
err
)
conn
.
Debug
=
fuse
.
VerboseTest
()
state
.
Debug
=
fuse
.
VerboseTest
()
...
...
@@ -59,10 +59,10 @@ func TestMemUnionFsSymlink(t *testing.T) {
wd
,
ufs
,
clean
:=
setupMemUfs
(
t
)
defer
clean
()
err
:=
os
.
Symlink
(
"/foobar"
,
wd
+
"/m
ou
nt/link"
)
err
:=
os
.
Symlink
(
"/foobar"
,
wd
+
"/mnt/link"
)
CheckSuccess
(
err
)
val
,
err
:=
os
.
Readlink
(
wd
+
"/m
ou
nt/link"
)
val
,
err
:=
os
.
Readlink
(
wd
+
"/mnt/link"
)
CheckSuccess
(
err
)
if
val
!=
"/foobar"
{
...
...
@@ -82,7 +82,7 @@ func TestMemUnionFsSymlinkPromote(t *testing.T) {
err
:=
os
.
Mkdir
(
wd
+
"/ro/subdir"
,
0755
)
CheckSuccess
(
err
)
err
=
os
.
Symlink
(
"/foobar"
,
wd
+
"/m
ou
nt/subdir/link"
)
err
=
os
.
Symlink
(
"/foobar"
,
wd
+
"/mnt/subdir/link"
)
CheckSuccess
(
err
)
r
:=
ufs
.
Reap
()
...
...
@@ -99,10 +99,10 @@ func TestMemUnionFsChtimes(t *testing.T) {
err
:=
os
.
Chtimes
(
wd
+
"/ro/file"
,
42e9
,
43e9
)
CheckSuccess
(
err
)
err
=
os
.
Chtimes
(
wd
+
"/m
ou
nt/file"
,
82e9
,
83e9
)
err
=
os
.
Chtimes
(
wd
+
"/mnt/file"
,
82e9
,
83e9
)
CheckSuccess
(
err
)
fi
,
err
:=
os
.
Lstat
(
wd
+
"/m
ou
nt/file"
)
fi
,
err
:=
os
.
Lstat
(
wd
+
"/mnt/file"
)
if
fi
.
Atime_ns
!=
82e9
||
fi
.
Mtime_ns
!=
83e9
{
t
.
Error
(
"Incorrect timestamp"
,
fi
)
}
...
...
@@ -118,7 +118,7 @@ func TestMemUnionFsChmod(t *testing.T) {
defer
clean
()
ro_fn
:=
wd
+
"/ro/file"
m_fn
:=
wd
+
"/m
ou
nt/file"
m_fn
:=
wd
+
"/mnt/file"
writeToFile
(
ro_fn
,
"a"
)
err
:=
os
.
Chmod
(
m_fn
,
07070
)
CheckSuccess
(
err
)
...
...
@@ -140,7 +140,7 @@ func TestMemUnionFsChown(t *testing.T) {
defer
clean
()
ro_fn
:=
wd
+
"/ro/file"
m_fn
:=
wd
+
"/m
ou
nt/file"
m_fn
:=
wd
+
"/mnt/file"
writeToFile
(
ro_fn
,
"a"
)
err
:=
os
.
Chown
(
m_fn
,
0
,
0
)
...
...
@@ -155,13 +155,13 @@ func TestMemUnionFsDelete(t *testing.T) {
defer
clean
()
writeToFile
(
wd
+
"/ro/file"
,
"a"
)
_
,
err
:=
os
.
Lstat
(
wd
+
"/m
ou
nt/file"
)
_
,
err
:=
os
.
Lstat
(
wd
+
"/mnt/file"
)
CheckSuccess
(
err
)
err
=
os
.
Remove
(
wd
+
"/m
ou
nt/file"
)
err
=
os
.
Remove
(
wd
+
"/mnt/file"
)
CheckSuccess
(
err
)
_
,
err
=
os
.
Lstat
(
wd
+
"/m
ou
nt/file"
)
_
,
err
=
os
.
Lstat
(
wd
+
"/mnt/file"
)
if
err
==
nil
{
t
.
Fatal
(
"should have disappeared."
)
}
...
...
@@ -176,32 +176,32 @@ func TestMemUnionFsBasic(t *testing.T) {
wd
,
_
,
clean
:=
setupMemUfs
(
t
)
defer
clean
()
writeToFile
(
wd
+
"/m
ou
nt/rw"
,
"a"
)
writeToFile
(
wd
+
"/mnt/rw"
,
"a"
)
writeToFile
(
wd
+
"/ro/ro1"
,
"a"
)
writeToFile
(
wd
+
"/ro/ro2"
,
"b"
)
names
:=
dirNames
(
wd
+
"/m
ou
nt"
)
names
:=
dirNames
(
wd
+
"/mnt"
)
expected
:=
map
[
string
]
bool
{
"rw"
:
true
,
"ro1"
:
true
,
"ro2"
:
true
,
}
checkMapEq
(
t
,
names
,
expected
)
writeToFile
(
wd
+
"/m
ou
nt/new"
,
"new contents"
)
writeToFile
(
wd
+
"/mnt/new"
,
"new contents"
)
contents
:=
readFromFile
(
wd
+
"/m
ou
nt/new"
)
contents
:=
readFromFile
(
wd
+
"/mnt/new"
)
if
contents
!=
"new contents"
{
t
.
Errorf
(
"read mismatch: '%v'"
,
contents
)
}
writeToFile
(
wd
+
"/m
ou
nt/ro1"
,
"promote me"
)
writeToFile
(
wd
+
"/mnt/ro1"
,
"promote me"
)
remove
(
wd
+
"/m
ou
nt/new"
)
names
=
dirNames
(
wd
+
"/m
ou
nt"
)
remove
(
wd
+
"/mnt/new"
)
names
=
dirNames
(
wd
+
"/mnt"
)
checkMapEq
(
t
,
names
,
map
[
string
]
bool
{
"rw"
:
true
,
"ro1"
:
true
,
"ro2"
:
true
,
})
remove
(
wd
+
"/m
ou
nt/ro1"
)
names
=
dirNames
(
wd
+
"/m
ou
nt"
)
remove
(
wd
+
"/mnt/ro1"
)
names
=
dirNames
(
wd
+
"/mnt"
)
checkMapEq
(
t
,
names
,
map
[
string
]
bool
{
"rw"
:
true
,
"ro2"
:
true
,
})
...
...
@@ -214,7 +214,7 @@ func TestMemUnionFsPromote(t *testing.T) {
err
:=
os
.
Mkdir
(
wd
+
"/ro/subdir"
,
0755
)
CheckSuccess
(
err
)
writeToFile
(
wd
+
"/ro/subdir/file"
,
"content"
)
writeToFile
(
wd
+
"/m
ou
nt/subdir/file"
,
"other-content"
)
writeToFile
(
wd
+
"/mnt/subdir/file"
,
"other-content"
)
r
:=
ufs
.
Reap
()
if
r
[
"subdir/file"
]
==
nil
||
r
[
"subdir/file"
]
.
Backing
==
""
{
...
...
@@ -228,8 +228,8 @@ func TestMemUnionFsSubdirCreate(t *testing.T) {
err
:=
os
.
MkdirAll
(
wd
+
"/ro/subdir/sub2"
,
0755
)
CheckSuccess
(
err
)
writeToFile
(
wd
+
"/m
ou
nt/subdir/sub2/file"
,
"other-content"
)
_
,
err
=
os
.
Lstat
(
wd
+
"/m
ou
nt/subdir/sub2/file"
)
writeToFile
(
wd
+
"/mnt/subdir/sub2/file"
,
"other-content"
)
_
,
err
=
os
.
Lstat
(
wd
+
"/mnt/subdir/sub2/file"
)
CheckSuccess
(
err
)
r
:=
ufs
.
Reap
()
...
...
@@ -242,8 +242,8 @@ func TestMemUnionFsCreate(t *testing.T) {
wd
,
ufs
,
clean
:=
setupMemUfs
(
t
)
defer
clean
()
writeToFile
(
wd
+
"/m
ou
nt/file.txt"
,
"hello"
)
_
,
err
:=
os
.
Lstat
(
wd
+
"/m
ou
nt/file.txt"
)
writeToFile
(
wd
+
"/mnt/file.txt"
,
"hello"
)
_
,
err
:=
os
.
Lstat
(
wd
+
"/mnt/file.txt"
)
CheckSuccess
(
err
)
r
:=
ufs
.
Reap
()
...
...
@@ -257,17 +257,17 @@ func TestMemUnionFsOpenUndeletes(t *testing.T) {
defer
clean
()
writeToFile
(
wd
+
"/ro/file"
,
"X"
)
err
:=
os
.
Remove
(
wd
+
"/m
ou
nt/file"
)
err
:=
os
.
Remove
(
wd
+
"/mnt/file"
)
CheckSuccess
(
err
)
writeToFile
(
wd
+
"/m
ou
nt/file"
,
"X"
)
_
,
err
=
os
.
Lstat
(
wd
+
"/m
ou
nt/file"
)
writeToFile
(
wd
+
"/mnt/file"
,
"X"
)
_
,
err
=
os
.
Lstat
(
wd
+
"/mnt/file"
)
}
func
TestMemUnionFsMkdir
(
t
*
testing
.
T
)
{
wd
,
ufs
,
clean
:=
setupMemUfs
(
t
)
defer
clean
()
dirname
:=
wd
+
"/m
ou
nt/subdir"
dirname
:=
wd
+
"/mnt/subdir"
err
:=
os
.
Mkdir
(
dirname
,
0755
)
CheckSuccess
(
err
)
...
...
@@ -288,7 +288,7 @@ func TestMemUnionFsMkdirPromote(t *testing.T) {
err
:=
os
.
MkdirAll
(
dirname
,
0755
)
CheckSuccess
(
err
)
err
=
os
.
Mkdir
(
wd
+
"/m
ou
nt/subdir/subdir2/dir3"
,
0755
)
err
=
os
.
Mkdir
(
wd
+
"/mnt/subdir/subdir2/dir3"
,
0755
)
CheckSuccess
(
err
)
r
:=
ufs
.
Reap
()
...
...
@@ -304,7 +304,7 @@ func TestMemUnionFsRmdirMkdir(t *testing.T) {
err
:=
os
.
Mkdir
(
wd
+
"/ro/subdir"
,
0755
)
CheckSuccess
(
err
)
dirname
:=
wd
+
"/m
ou
nt/subdir"
dirname
:=
wd
+
"/mnt/subdir"
err
=
os
.
Remove
(
dirname
)
CheckSuccess
(
err
)
...
...
@@ -321,18 +321,18 @@ func TestMemUnionFsLink(t *testing.T) {
err
:=
ioutil
.
WriteFile
(
fn
,
[]
byte
(
content
),
0666
)
CheckSuccess
(
err
)
err
=
os
.
Link
(
wd
+
"/m
ount/file"
,
wd
+
"/mou
nt/linked"
)
err
=
os
.
Link
(
wd
+
"/m
nt/file"
,
wd
+
"/m
nt/linked"
)
CheckSuccess
(
err
)
fi2
,
err
:=
os
.
Lstat
(
wd
+
"/m
ou
nt/linked"
)
fi2
,
err
:=
os
.
Lstat
(
wd
+
"/mnt/linked"
)
CheckSuccess
(
err
)
fi1
,
err
:=
os
.
Lstat
(
wd
+
"/m
ou
nt/file"
)
fi1
,
err
:=
os
.
Lstat
(
wd
+
"/mnt/file"
)
CheckSuccess
(
err
)
if
fi1
.
Ino
!=
fi2
.
Ino
{
t
.
Errorf
(
"inode numbers should be equal for linked files %v, %v"
,
fi1
.
Ino
,
fi2
.
Ino
)
}
c
,
err
:=
ioutil
.
ReadFile
(
wd
+
"/m
ou
nt/linked"
)
c
,
err
:=
ioutil
.
ReadFile
(
wd
+
"/mnt/linked"
)
if
string
(
c
)
!=
content
{
t
.
Errorf
(
"content mismatch got %q want %q"
,
string
(
c
),
content
)
}
...
...
@@ -347,7 +347,7 @@ func TestMemUnionFsCreateLink(t *testing.T) {
err
:=
ioutil
.
WriteFile
(
fn
,
[]
byte
(
content
),
0666
)
CheckSuccess
(
err
)
err
=
os
.
Link
(
wd
+
"/m
ount/file"
,
wd
+
"/mou
nt/linked"
)
err
=
os
.
Link
(
wd
+
"/m
nt/file"
,
wd
+
"/m
nt/linked"
)
CheckSuccess
(
err
)
}
...
...
@@ -356,8 +356,8 @@ func TestMemUnionFsTruncate(t *testing.T) {
defer
clean
()
writeToFile
(
wd
+
"/ro/file"
,
"hello"
)
os
.
Truncate
(
wd
+
"/m
ou
nt/file"
,
2
)
content
:=
readFromFile
(
wd
+
"/m
ou
nt/file"
)
os
.
Truncate
(
wd
+
"/mnt/file"
,
2
)
content
:=
readFromFile
(
wd
+
"/mnt/file"
)
if
content
!=
"he"
{
t
.
Errorf
(
"unexpected content %v"
,
content
)
}
...
...
@@ -368,7 +368,7 @@ func TestMemUnionFsCopyChmod(t *testing.T) {
defer
clean
()
contents
:=
"hello"
fn
:=
wd
+
"/m
ou
nt/y"
fn
:=
wd
+
"/mnt/y"
err
:=
ioutil
.
WriteFile
(
fn
,
[]
byte
(
contents
),
0644
)
CheckSuccess
(
err
)
...
...
@@ -393,7 +393,7 @@ func TestMemUnionFsTruncateTimestamp(t *testing.T) {
defer
clean
()
contents
:=
"hello"
fn
:=
wd
+
"/m
ou
nt/y"
fn
:=
wd
+
"/mnt/y"
err
:=
ioutil
.
WriteFile
(
fn
,
[]
byte
(
contents
),
0644
)
CheckSuccess
(
err
)
time
.
Sleep
(
0.2e9
)
...
...
@@ -422,7 +422,7 @@ func TestMemUnionFsRemoveAll(t *testing.T) {
err
=
ioutil
.
WriteFile
(
fn
,
[]
byte
(
contents
),
0644
)
CheckSuccess
(
err
)
err
=
os
.
RemoveAll
(
wd
+
"/m
ou
nt/dir"
)
err
=
os
.
RemoveAll
(
wd
+
"/mnt/dir"
)
if
err
!=
nil
{
t
.
Error
(
"Should delete all"
)
}
...
...
@@ -447,7 +447,7 @@ func TestMemUnionFsRmRf(t *testing.T) {
CheckSuccess
(
err
)
bin
,
err
:=
exec
.
LookPath
(
"rm"
)
CheckSuccess
(
err
)
cmd
:=
exec
.
Command
(
bin
,
"-rf"
,
wd
+
"/m
ou
nt/dir"
)
cmd
:=
exec
.
Command
(
bin
,
"-rf"
,
wd
+
"/mnt/dir"
)
err
=
cmd
.
Run
()
if
err
!=
nil
{
t
.
Fatal
(
"rm -rf returned error:"
,
err
)
...
...
@@ -467,11 +467,11 @@ func TestMemUnionFsDeletedGetAttr(t *testing.T) {
err
:=
ioutil
.
WriteFile
(
wd
+
"/ro/file"
,
[]
byte
(
"blabla"
),
0644
)
CheckSuccess
(
err
)
f
,
err
:=
os
.
Open
(
wd
+
"/m
ou
nt/file"
)
f
,
err
:=
os
.
Open
(
wd
+
"/mnt/file"
)
CheckSuccess
(
err
)
defer
f
.
Close
()
err
=
os
.
Remove
(
wd
+
"/m
ou
nt/file"
)
err
=
os
.
Remove
(
wd
+
"/mnt/file"
)
CheckSuccess
(
err
)
if
fi
,
err
:=
f
.
Stat
();
err
!=
nil
||
!
fi
.
IsRegular
()
{
...
...
@@ -485,10 +485,10 @@ func TestMemUnionFsDoubleOpen(t *testing.T) {
err
:=
ioutil
.
WriteFile
(
wd
+
"/ro/file"
,
[]
byte
(
"blablabla"
),
0644
)
CheckSuccess
(
err
)
roFile
,
err
:=
os
.
Open
(
wd
+
"/m
ou
nt/file"
)
roFile
,
err
:=
os
.
Open
(
wd
+
"/mnt/file"
)
CheckSuccess
(
err
)
defer
roFile
.
Close
()
rwFile
,
err
:=
os
.
OpenFile
(
wd
+
"/m
ou
nt/file"
,
os
.
O_WRONLY
|
os
.
O_TRUNC
,
0666
)
rwFile
,
err
:=
os
.
OpenFile
(
wd
+
"/mnt/file"
,
os
.
O_WRONLY
|
os
.
O_TRUNC
,
0666
)
CheckSuccess
(
err
)
defer
rwFile
.
Close
()
...
...
@@ -521,12 +521,12 @@ func TestMemUnionFsUpdate(t *testing.T) {
err
:=
ioutil
.
WriteFile
(
wd
+
"/ro/file1"
,
[]
byte
(
"blablabla"
),
0644
)
CheckSuccess
(
err
)
_
,
err
=
os
.
Lstat
(
wd
+
"/m
ou
nt/file1"
)
_
,
err
=
os
.
Lstat
(
wd
+
"/mnt/file1"
)
CheckSuccess
(
err
)
if
fi
,
_
:=
os
.
Lstat
(
wd
+
"/m
ou
nt/file2"
);
fi
!=
nil
{
if
fi
,
_
:=
os
.
Lstat
(
wd
+
"/mnt/file2"
);
fi
!=
nil
{
t
.
Fatal
(
"file2 should not exist"
,
fi
)
}
if
fi
,
_
:=
os
.
Lstat
(
wd
+
"/m
ou
nt/symlink"
);
fi
!=
nil
{
if
fi
,
_
:=
os
.
Lstat
(
wd
+
"/mnt/symlink"
);
fi
!=
nil
{
t
.
Fatal
(
"symlink should not exist"
,
fi
)
}
...
...
@@ -538,12 +538,12 @@ func TestMemUnionFsUpdate(t *testing.T) {
CheckSuccess
(
err
)
// Still have cached attributes.
fi
,
err
:=
os
.
Lstat
(
wd
+
"/m
ou
nt/file1"
)
fi
,
err
:=
os
.
Lstat
(
wd
+
"/mnt/file1"
)
CheckSuccess
(
err
)
if
fi
,
_
:=
os
.
Lstat
(
wd
+
"/m
ou
nt/file2"
);
fi
!=
nil
{
if
fi
,
_
:=
os
.
Lstat
(
wd
+
"/mnt/file2"
);
fi
!=
nil
{
t
.
Fatal
(
"file2 should not exist"
)
}
if
fi
,
_
:=
os
.
Lstat
(
wd
+
"/m
ou
nt/symlink"
);
fi
!=
nil
{
if
fi
,
_
:=
os
.
Lstat
(
wd
+
"/mnt/symlink"
);
fi
!=
nil
{
t
.
Fatal
(
"symlink should not exist"
,
fi
)
}
...
...
@@ -567,17 +567,17 @@ func TestMemUnionFsUpdate(t *testing.T) {
ufs
.
Update
(
updates
)
// Cached attributes flushed.
if
fi
,
_
:=
os
.
Lstat
(
wd
+
"/m
ou
nt/file1"
);
fi
!=
nil
{
if
fi
,
_
:=
os
.
Lstat
(
wd
+
"/mnt/file1"
);
fi
!=
nil
{
t
.
Fatal
(
"file1 should have disappeared"
,
fi
)
}
fi
,
err
=
os
.
Lstat
(
wd
+
"/m
ou
nt/file2"
)
fi
,
err
=
os
.
Lstat
(
wd
+
"/mnt/file2"
)
CheckSuccess
(
err
)
if
roF2
.
Mtime_ns
!=
fi
.
Mtime_ns
{
t
.
Fatalf
(
"file2 attribute mismatch: got %v want %v"
,
fi
,
roF2
)
}
val
,
err
:=
os
.
Readlink
(
wd
+
"/m
ou
nt/symlink"
)
val
,
err
:=
os
.
Readlink
(
wd
+
"/mnt/symlink"
)
CheckSuccess
(
err
)
if
val
!=
"target"
{
t
.
Error
(
"symlink value got %q want %v"
,
val
,
"target"
)
...
...
@@ -592,10 +592,10 @@ func TestMemUnionFsFdLeak(t *testing.T) {
err
=
ioutil
.
WriteFile
(
wd
+
"/ro/file"
,
[]
byte
(
"blablabla"
),
0644
)
CheckSuccess
(
err
)
contents
,
err
:=
ioutil
.
ReadFile
(
wd
+
"/m
ou
nt/file"
)
contents
,
err
:=
ioutil
.
ReadFile
(
wd
+
"/mnt/file"
)
CheckSuccess
(
err
)
err
=
ioutil
.
WriteFile
(
wd
+
"/m
ou
nt/file"
,
contents
,
0644
)
err
=
ioutil
.
WriteFile
(
wd
+
"/mnt/file"
,
contents
,
0644
)
CheckSuccess
(
err
)
clean
()
...
...
@@ -613,7 +613,7 @@ func TestMemUnionFsStatFs(t *testing.T) {
defer
clean
()
s1
:=
syscall
.
Statfs_t
{}
err
:=
syscall
.
Statfs
(
wd
+
"/m
ou
nt"
,
&
s1
)
err
:=
syscall
.
Statfs
(
wd
+
"/mnt"
,
&
s1
)
if
err
!=
0
{
t
.
Fatal
(
"statfs mnt"
,
err
)
}
...
...
@@ -626,7 +626,7 @@ func TestMemUnionFsFlushSize(t *testing.T) {
wd
,
_
,
clean
:=
setupMemUfs
(
t
)
defer
clean
()
fn
:=
wd
+
"/m
ou
nt/file"
fn
:=
wd
+
"/mnt/file"
f
,
err
:=
os
.
OpenFile
(
fn
,
os
.
O_WRONLY
|
os
.
O_CREATE
,
0644
)
CheckSuccess
(
err
)
fi
,
err
:=
f
.
Stat
()
...
...
@@ -647,9 +647,9 @@ func TestMemUnionFsFlushRename(t *testing.T) {
wd
,
_
,
clean
:=
setupMemUfs
(
t
)
defer
clean
()
err
:=
ioutil
.
WriteFile
(
wd
+
"/m
ou
nt/file"
,
[]
byte
(
"x"
),
0644
)
err
:=
ioutil
.
WriteFile
(
wd
+
"/mnt/file"
,
[]
byte
(
"x"
),
0644
)
fn
:=
wd
+
"/m
ou
nt/tmp"
fn
:=
wd
+
"/mnt/tmp"
f
,
err
:=
os
.
OpenFile
(
fn
,
os
.
O_WRONLY
|
os
.
O_CREATE
,
0644
)
CheckSuccess
(
err
)
fi
,
err
:=
f
.
Stat
()
...
...
@@ -659,7 +659,7 @@ func TestMemUnionFsFlushRename(t *testing.T) {
CheckSuccess
(
err
)
f
.
Close
()
dst
:=
wd
+
"/m
ou
nt/file"
dst
:=
wd
+
"/mnt/file"
err
=
os
.
Rename
(
fn
,
dst
)
CheckSuccess
(
err
)
...
...
@@ -675,14 +675,14 @@ func TestMemUnionFsTruncGetAttr(t *testing.T) {
defer
clean
()
c
:=
[]
byte
(
"hello"
)
f
,
err
:=
os
.
OpenFile
(
wd
+
"/m
ou
nt/file"
,
os
.
O_CREATE
|
os
.
O_RDWR
|
os
.
O_TRUNC
,
0644
)
f
,
err
:=
os
.
OpenFile
(
wd
+
"/mnt/file"
,
os
.
O_CREATE
|
os
.
O_RDWR
|
os
.
O_TRUNC
,
0644
)
CheckSuccess
(
err
)
_
,
err
=
f
.
Write
(
c
)
CheckSuccess
(
err
)
err
=
f
.
Close
()
CheckSuccess
(
err
)
fi
,
err
:=
os
.
Lstat
(
wd
+
"/m
ou
nt/file"
)
fi
,
err
:=
os
.
Lstat
(
wd
+
"/mnt/file"
)
if
fi
.
Size
!=
int64
(
len
(
c
))
{
t
.
Fatalf
(
"Length mismatch got %d want %d"
,
fi
.
Size
,
len
(
c
))
}
...
...
@@ -695,20 +695,20 @@ func TestMemUnionFsRenameDirBasic(t *testing.T) {
err
:=
os
.
MkdirAll
(
wd
+
"/ro/dir/subdir"
,
0755
)
CheckSuccess
(
err
)
err
=
os
.
Rename
(
wd
+
"/m
ount/dir"
,
wd
+
"/mou
nt/renamed"
)
err
=
os
.
Rename
(
wd
+
"/m
nt/dir"
,
wd
+
"/m
nt/renamed"
)
CheckSuccess
(
err
)
if
fi
,
_
:=
os
.
Lstat
(
wd
+
"/m
ou
nt/dir"
);
fi
!=
nil
{
t
.
Fatalf
(
"%s/m
ou
nt/dir should have disappeared: %v"
,
wd
,
fi
)
if
fi
,
_
:=
os
.
Lstat
(
wd
+
"/mnt/dir"
);
fi
!=
nil
{
t
.
Fatalf
(
"%s/mnt/dir should have disappeared: %v"
,
wd
,
fi
)
}
if
fi
,
_
:=
os
.
Lstat
(
wd
+
"/m
ou
nt/renamed"
);
fi
==
nil
||
!
fi
.
IsDirectory
()
{
t
.
Fatalf
(
"%s/m
ou
nt/renamed should be directory: %v"
,
wd
,
fi
)
if
fi
,
_
:=
os
.
Lstat
(
wd
+
"/mnt/renamed"
);
fi
==
nil
||
!
fi
.
IsDirectory
()
{
t
.
Fatalf
(
"%s/mnt/renamed should be directory: %v"
,
wd
,
fi
)
}
entries
,
err
:=
ioutil
.
ReadDir
(
wd
+
"/m
ou
nt/renamed"
)
entries
,
err
:=
ioutil
.
ReadDir
(
wd
+
"/mnt/renamed"
)
if
err
!=
nil
||
len
(
entries
)
!=
1
||
entries
[
0
]
.
Name
!=
"subdir"
{
t
.
Errorf
(
"readdir(%s/m
ou
nt/renamed) should have one entry: %v, err %v"
,
wd
,
entries
,
err
)
t
.
Errorf
(
"readdir(%s/mnt/renamed) should have one entry: %v, err %v"
,
wd
,
entries
,
err
)
}
r
:=
ufs
.
Reap
()
...
...
@@ -716,7 +716,7 @@ func TestMemUnionFsRenameDirBasic(t *testing.T) {
t
.
Errorf
(
"Reap should del dir, and add renamed/subdir: %v"
,
r
)
}
if
err
=
os
.
Mkdir
(
wd
+
"/m
ou
nt/dir"
,
0755
);
err
!=
nil
{
if
err
=
os
.
Mkdir
(
wd
+
"/mnt/dir"
,
0755
);
err
!=
nil
{
t
.
Errorf
(
"mkdir should succeed %v"
,
err
)
}
...
...
@@ -732,7 +732,7 @@ func TestMemUnionFsRenameDirAllSourcesGone(t *testing.T) {
err
=
ioutil
.
WriteFile
(
wd
+
"/ro/dir/file.txt"
,
[]
byte
{
42
},
0644
)
CheckSuccess
(
err
)
err
=
os
.
Rename
(
wd
+
"/m
ount/dir"
,
wd
+
"/mou
nt/renamed"
)
err
=
os
.
Rename
(
wd
+
"/m
nt/dir"
,
wd
+
"/m
nt/renamed"
)
CheckSuccess
(
err
)
r
:=
ufs
.
Reap
()
...
...
@@ -754,38 +754,38 @@ func TestMemUnionFsRenameDirWithDeletions(t *testing.T) {
err
=
ioutil
.
WriteFile
(
wd
+
"/ro/dir/subdir/file.txt"
,
[]
byte
{
42
},
0644
)
CheckSuccess
(
err
)
if
fi
,
_
:=
os
.
Lstat
(
wd
+
"/m
ou
nt/dir/subdir/file.txt"
);
fi
==
nil
||
!
fi
.
IsRegular
()
{
t
.
Fatalf
(
"%s/m
ou
nt/dir/subdir/file.txt should be file: %v"
,
wd
,
fi
)
if
fi
,
_
:=
os
.
Lstat
(
wd
+
"/mnt/dir/subdir/file.txt"
);
fi
==
nil
||
!
fi
.
IsRegular
()
{
t
.
Fatalf
(
"%s/mnt/dir/subdir/file.txt should be file: %v"
,
wd
,
fi
)
}
err
=
os
.
Remove
(
wd
+
"/m
ou
nt/dir/file.txt"
)
err
=
os
.
Remove
(
wd
+
"/mnt/dir/file.txt"
)
CheckSuccess
(
err
)
err
=
os
.
Rename
(
wd
+
"/m
ount/dir"
,
wd
+
"/mou
nt/renamed"
)
err
=
os
.
Rename
(
wd
+
"/m
nt/dir"
,
wd
+
"/m
nt/renamed"
)
CheckSuccess
(
err
)
if
fi
,
_
:=
os
.
Lstat
(
wd
+
"/m
ou
nt/dir/subdir/file.txt"
);
fi
!=
nil
{
t
.
Fatalf
(
"%s/m
ou
nt/dir/subdir/file.txt should have disappeared: %v"
,
wd
,
fi
)
if
fi
,
_
:=
os
.
Lstat
(
wd
+
"/mnt/dir/subdir/file.txt"
);
fi
!=
nil
{
t
.
Fatalf
(
"%s/mnt/dir/subdir/file.txt should have disappeared: %v"
,
wd
,
fi
)
}
if
fi
,
_
:=
os
.
Lstat
(
wd
+
"/m
ou
nt/dir"
);
fi
!=
nil
{
t
.
Fatalf
(
"%s/m
ou
nt/dir should have disappeared: %v"
,
wd
,
fi
)
if
fi
,
_
:=
os
.
Lstat
(
wd
+
"/mnt/dir"
);
fi
!=
nil
{
t
.
Fatalf
(
"%s/mnt/dir should have disappeared: %v"
,
wd
,
fi
)
}
if
fi
,
_
:=
os
.
Lstat
(
wd
+
"/m
ou
nt/renamed"
);
fi
==
nil
||
!
fi
.
IsDirectory
()
{
t
.
Fatalf
(
"%s/m
ou
nt/renamed should be directory: %v"
,
wd
,
fi
)
if
fi
,
_
:=
os
.
Lstat
(
wd
+
"/mnt/renamed"
);
fi
==
nil
||
!
fi
.
IsDirectory
()
{
t
.
Fatalf
(
"%s/mnt/renamed should be directory: %v"
,
wd
,
fi
)
}
if
fi
,
_
:=
os
.
Lstat
(
wd
+
"/m
ou
nt/renamed/file.txt"
);
fi
!=
nil
{
t
.
Fatalf
(
"%s/m
ou
nt/renamed/file.txt should have disappeared %#v"
,
wd
,
fi
)
if
fi
,
_
:=
os
.
Lstat
(
wd
+
"/mnt/renamed/file.txt"
);
fi
!=
nil
{
t
.
Fatalf
(
"%s/mnt/renamed/file.txt should have disappeared %#v"
,
wd
,
fi
)
}
if
err
=
os
.
Mkdir
(
wd
+
"/m
ou
nt/dir"
,
0755
);
err
!=
nil
{
if
err
=
os
.
Mkdir
(
wd
+
"/mnt/dir"
,
0755
);
err
!=
nil
{
t
.
Errorf
(
"mkdir should succeed %v"
,
err
)
}
if
fi
,
_
:=
os
.
Lstat
(
wd
+
"/m
ou
nt/dir/subdir"
);
fi
!=
nil
{
t
.
Fatalf
(
"%s/m
ou
nt/dir/subdir should have disappeared %#v"
,
wd
,
fi
)
if
fi
,
_
:=
os
.
Lstat
(
wd
+
"/mnt/dir/subdir"
);
fi
!=
nil
{
t
.
Fatalf
(
"%s/mnt/dir/subdir should have disappeared %#v"
,
wd
,
fi
)
}
}
...
...
@@ -793,9 +793,9 @@ func TestMemUnionGc(t *testing.T) {
wd
,
ufs
,
clean
:=
setupMemUfs
(
t
)
defer
clean
()
writeToFile
(
wd
+
"/m
ou
nt/file1"
,
"other-content"
)
writeToFile
(
wd
+
"/m
ou
nt/file2"
,
"other-content"
)
err
:=
os
.
Remove
(
wd
+
"/m
ou
nt/file1"
)
writeToFile
(
wd
+
"/mnt/file1"
,
"other-content"
)
writeToFile
(
wd
+
"/mnt/file2"
,
"other-content"
)
err
:=
os
.
Remove
(
wd
+
"/mnt/file1"
)
CheckSuccess
(
err
)
ufs
.
Clear
()
...
...
unionfs/unionfs_test.go
View file @
d822ee41
...
...
@@ -41,7 +41,7 @@ func setupUfs(t *testing.T) (workdir string, cleanup func()) {
syscall
.
Umask
(
0
)
wd
,
_
:=
ioutil
.
TempDir
(
""
,
""
)
err
:=
os
.
Mkdir
(
wd
+
"/m
ou
nt"
,
0700
)
err
:=
os
.
Mkdir
(
wd
+
"/mnt"
,
0700
)
fuse
.
CheckSuccess
(
err
)
err
=
os
.
Mkdir
(
wd
+
"/rw"
,
0700
)
...
...
@@ -66,7 +66,7 @@ func setupUfs(t *testing.T) (workdir string, cleanup func()) {
pathfs
:=
fuse
.
NewPathNodeFs
(
ufs
,
&
fuse
.
PathNodeFsOptions
{
ClientInodes
:
true
})
state
,
conn
,
err
:=
fuse
.
MountNodeFileSystem
(
wd
+
"/m
ou
nt"
,
pathfs
,
opts
)
state
,
conn
,
err
:=
fuse
.
MountNodeFileSystem
(
wd
+
"/mnt"
,
pathfs
,
opts
)
CheckSuccess
(
err
)
conn
.
Debug
=
fuse
.
VerboseTest
()
state
.
Debug
=
fuse
.
VerboseTest
()
...
...
@@ -143,10 +143,10 @@ func TestUnionFsAutocreateDeletionDir(t *testing.T) {
err
:=
os
.
Remove
(
wd
+
"/rw/DELETIONS"
)
CheckSuccess
(
err
)
err
=
os
.
Mkdir
(
wd
+
"/m
ou
nt/dir"
,
0755
)
err
=
os
.
Mkdir
(
wd
+
"/mnt/dir"
,
0755
)
CheckSuccess
(
err
)
_
,
err
=
ioutil
.
ReadDir
(
wd
+
"/m
ou
nt/dir"
)
_
,
err
=
ioutil
.
ReadDir
(
wd
+
"/mnt/dir"
)
CheckSuccess
(
err
)
}
...
...
@@ -154,10 +154,10 @@ func TestUnionFsSymlink(t *testing.T) {
wd
,
clean
:=
setupUfs
(
t
)
defer
clean
()
err
:=
os
.
Symlink
(
"/foobar"
,
wd
+
"/m
ou
nt/link"
)
err
:=
os
.
Symlink
(
"/foobar"
,
wd
+
"/mnt/link"
)
CheckSuccess
(
err
)
val
,
err
:=
os
.
Readlink
(
wd
+
"/m
ou
nt/link"
)
val
,
err
:=
os
.
Readlink
(
wd
+
"/mnt/link"
)
CheckSuccess
(
err
)
if
val
!=
"/foobar"
{
...
...
@@ -172,7 +172,7 @@ func TestUnionFsSymlinkPromote(t *testing.T) {
err
:=
os
.
Mkdir
(
wd
+
"/ro/subdir"
,
0755
)
CheckSuccess
(
err
)
err
=
os
.
Symlink
(
"/foobar"
,
wd
+
"/m
ou
nt/subdir/link"
)
err
=
os
.
Symlink
(
"/foobar"
,
wd
+
"/mnt/subdir/link"
)
CheckSuccess
(
err
)
}
...
...
@@ -184,10 +184,10 @@ func TestUnionFsChtimes(t *testing.T) {
err
:=
os
.
Chtimes
(
wd
+
"/ro/file"
,
42e9
,
43e9
)
CheckSuccess
(
err
)
err
=
os
.
Chtimes
(
wd
+
"/m
ou
nt/file"
,
82e9
,
83e9
)
err
=
os
.
Chtimes
(
wd
+
"/mnt/file"
,
82e9
,
83e9
)
CheckSuccess
(
err
)
fi
,
err
:=
os
.
Lstat
(
wd
+
"/m
ou
nt/file"
)
fi
,
err
:=
os
.
Lstat
(
wd
+
"/mnt/file"
)
if
fi
.
Atime_ns
!=
82e9
||
fi
.
Mtime_ns
!=
83e9
{
t
.
Error
(
"Incorrect timestamp"
,
fi
)
}
...
...
@@ -198,7 +198,7 @@ func TestUnionFsChmod(t *testing.T) {
defer
clean
()
ro_fn
:=
wd
+
"/ro/file"
m_fn
:=
wd
+
"/m
ou
nt/file"
m_fn
:=
wd
+
"/mnt/file"
writeToFile
(
ro_fn
,
"a"
)
err
:=
os
.
Chmod
(
m_fn
,
07070
)
CheckSuccess
(
err
)
...
...
@@ -219,7 +219,7 @@ func TestUnionFsChown(t *testing.T) {
defer
clean
()
ro_fn
:=
wd
+
"/ro/file"
m_fn
:=
wd
+
"/m
ou
nt/file"
m_fn
:=
wd
+
"/mnt/file"
writeToFile
(
ro_fn
,
"a"
)
err
:=
os
.
Chown
(
m_fn
,
0
,
0
)
...
...
@@ -234,13 +234,13 @@ func TestUnionFsDelete(t *testing.T) {
defer
clean
()
writeToFile
(
wd
+
"/ro/file"
,
"a"
)
_
,
err
:=
os
.
Lstat
(
wd
+
"/m
ou
nt/file"
)
_
,
err
:=
os
.
Lstat
(
wd
+
"/mnt/file"
)
CheckSuccess
(
err
)
err
=
os
.
Remove
(
wd
+
"/m
ou
nt/file"
)
err
=
os
.
Remove
(
wd
+
"/mnt/file"
)
CheckSuccess
(
err
)
_
,
err
=
os
.
Lstat
(
wd
+
"/m
ou
nt/file"
)
_
,
err
=
os
.
Lstat
(
wd
+
"/mnt/file"
)
if
err
==
nil
{
t
.
Fatal
(
"should have disappeared."
)
}
...
...
@@ -267,28 +267,28 @@ func TestUnionFsBasic(t *testing.T) {
writeToFile
(
wd
+
"/ro/ro1"
,
"a"
)
writeToFile
(
wd
+
"/ro/ro2"
,
"b"
)
names
:=
dirNames
(
wd
+
"/m
ou
nt"
)
names
:=
dirNames
(
wd
+
"/mnt"
)
expected
:=
map
[
string
]
bool
{
"rw"
:
true
,
"ro1"
:
true
,
"ro2"
:
true
,
}
checkMapEq
(
t
,
names
,
expected
)
writeToFile
(
wd
+
"/m
ou
nt/new"
,
"new contents"
)
writeToFile
(
wd
+
"/mnt/new"
,
"new contents"
)
if
!
fileExists
(
wd
+
"/rw/new"
)
{
t
.
Errorf
(
"missing file in rw layer"
,
names
)
}
contents
:=
readFromFile
(
wd
+
"/m
ou
nt/new"
)
contents
:=
readFromFile
(
wd
+
"/mnt/new"
)
if
contents
!=
"new contents"
{
t
.
Errorf
(
"read mismatch: '%v'"
,
contents
)
}
writeToFile
(
wd
+
"/m
ou
nt/ro1"
,
"promote me"
)
writeToFile
(
wd
+
"/mnt/ro1"
,
"promote me"
)
if
!
fileExists
(
wd
+
"/rw/ro1"
)
{
t
.
Errorf
(
"missing file in rw layer"
,
names
)
}
remove
(
wd
+
"/m
ou
nt/new"
)
names
=
dirNames
(
wd
+
"/m
ou
nt"
)
remove
(
wd
+
"/mnt/new"
)
names
=
dirNames
(
wd
+
"/mnt"
)
checkMapEq
(
t
,
names
,
map
[
string
]
bool
{
"rw"
:
true
,
"ro1"
:
true
,
"ro2"
:
true
,
})
...
...
@@ -303,8 +303,8 @@ func TestUnionFsBasic(t *testing.T) {
t
.
Errorf
(
"Expected 0 entry in %v"
,
names
)
}
remove
(
wd
+
"/m
ou
nt/ro1"
)
names
=
dirNames
(
wd
+
"/m
ou
nt"
)
remove
(
wd
+
"/mnt/ro1"
)
names
=
dirNames
(
wd
+
"/mnt"
)
checkMapEq
(
t
,
names
,
map
[
string
]
bool
{
"rw"
:
true
,
"ro2"
:
true
,
})
...
...
@@ -327,7 +327,7 @@ func TestUnionFsPromote(t *testing.T) {
err
:=
os
.
Mkdir
(
wd
+
"/ro/subdir"
,
0755
)
CheckSuccess
(
err
)
writeToFile
(
wd
+
"/ro/subdir/file"
,
"content"
)
writeToFile
(
wd
+
"/m
ou
nt/subdir/file"
,
"other-content"
)
writeToFile
(
wd
+
"/mnt/subdir/file"
,
"other-content"
)
}
func
TestUnionFsCreate
(
t
*
testing
.
T
)
{
...
...
@@ -336,8 +336,8 @@ func TestUnionFsCreate(t *testing.T) {
err
:=
os
.
MkdirAll
(
wd
+
"/ro/subdir/sub2"
,
0755
)
CheckSuccess
(
err
)
writeToFile
(
wd
+
"/m
ou
nt/subdir/sub2/file"
,
"other-content"
)
_
,
err
=
os
.
Lstat
(
wd
+
"/m
ou
nt/subdir/sub2/file"
)
writeToFile
(
wd
+
"/mnt/subdir/sub2/file"
,
"other-content"
)
_
,
err
=
os
.
Lstat
(
wd
+
"/mnt/subdir/sub2/file"
)
CheckSuccess
(
err
)
}
...
...
@@ -346,10 +346,10 @@ func TestUnionFsOpenUndeletes(t *testing.T) {
defer
clean
()
writeToFile
(
wd
+
"/ro/file"
,
"X"
)
err
:=
os
.
Remove
(
wd
+
"/m
ou
nt/file"
)
err
:=
os
.
Remove
(
wd
+
"/mnt/file"
)
CheckSuccess
(
err
)
writeToFile
(
wd
+
"/m
ou
nt/file"
,
"X"
)
_
,
err
=
os
.
Lstat
(
wd
+
"/m
ou
nt/file"
)
writeToFile
(
wd
+
"/mnt/file"
,
"X"
)
_
,
err
=
os
.
Lstat
(
wd
+
"/mnt/file"
)
CheckSuccess
(
err
)
}
...
...
@@ -357,7 +357,7 @@ func TestUnionFsMkdir(t *testing.T) {
wd
,
clean
:=
setupUfs
(
t
)
defer
clean
()
dirname
:=
wd
+
"/m
ou
nt/subdir"
dirname
:=
wd
+
"/mnt/subdir"
err
:=
os
.
Mkdir
(
dirname
,
0755
)
CheckSuccess
(
err
)
...
...
@@ -373,7 +373,7 @@ func TestUnionFsMkdirPromote(t *testing.T) {
err
:=
os
.
MkdirAll
(
dirname
,
0755
)
CheckSuccess
(
err
)
err
=
os
.
Mkdir
(
wd
+
"/m
ou
nt/subdir/subdir2/dir3"
,
0755
)
err
=
os
.
Mkdir
(
wd
+
"/mnt/subdir/subdir2/dir3"
,
0755
)
CheckSuccess
(
err
)
fi
,
_
:=
os
.
Lstat
(
wd
+
"/rw/subdir/subdir2/dir3"
)
CheckSuccess
(
err
)
...
...
@@ -389,7 +389,7 @@ func TestUnionFsRmdirMkdir(t *testing.T) {
err
:=
os
.
Mkdir
(
wd
+
"/ro/subdir"
,
0755
)
CheckSuccess
(
err
)
dirname
:=
wd
+
"/m
ou
nt/subdir"
dirname
:=
wd
+
"/mnt/subdir"
err
=
os
.
Remove
(
dirname
)
CheckSuccess
(
err
)
...
...
@@ -431,24 +431,24 @@ func TestUnionFsRename(t *testing.T) {
writeToFile
(
wd
+
"/rw/file2"
,
"c4"
)
}
err
:=
os
.
Rename
(
wd
+
"/m
ount/file1"
,
wd
+
"/mou
nt/file2"
)
err
:=
os
.
Rename
(
wd
+
"/m
nt/file1"
,
wd
+
"/m
nt/file2"
)
CheckSuccess
(
err
)
_
,
err
=
os
.
Lstat
(
wd
+
"/m
ou
nt/file1"
)
_
,
err
=
os
.
Lstat
(
wd
+
"/mnt/file1"
)
if
err
==
nil
{
t
.
Errorf
(
"Should have lost file1"
)
}
_
,
err
=
os
.
Lstat
(
wd
+
"/m
ou
nt/file2"
)
_
,
err
=
os
.
Lstat
(
wd
+
"/mnt/file2"
)
CheckSuccess
(
err
)
err
=
os
.
Rename
(
wd
+
"/m
ount/file2"
,
wd
+
"/mou
nt/file1"
)
err
=
os
.
Rename
(
wd
+
"/m
nt/file2"
,
wd
+
"/m
nt/file1"
)
CheckSuccess
(
err
)
_
,
err
=
os
.
Lstat
(
wd
+
"/m
ou
nt/file2"
)
_
,
err
=
os
.
Lstat
(
wd
+
"/mnt/file2"
)
if
err
==
nil
{
t
.
Errorf
(
"Should have lost file2"
)
}
_
,
err
=
os
.
Lstat
(
wd
+
"/m
ou
nt/file1"
)
_
,
err
=
os
.
Lstat
(
wd
+
"/mnt/file1"
)
CheckSuccess
(
err
)
clean
()
...
...
@@ -462,23 +462,23 @@ func TestUnionFsRenameDirBasic(t *testing.T) {
err
:=
os
.
MkdirAll
(
wd
+
"/ro/dir/subdir"
,
0755
)
CheckSuccess
(
err
)
err
=
os
.
Rename
(
wd
+
"/m
ount/dir"
,
wd
+
"/mou
nt/renamed"
)
err
=
os
.
Rename
(
wd
+
"/m
nt/dir"
,
wd
+
"/m
nt/renamed"
)
CheckSuccess
(
err
)
if
fi
,
_
:=
os
.
Lstat
(
wd
+
"/m
ou
nt/dir"
);
fi
!=
nil
{
t
.
Fatalf
(
"%s/m
ou
nt/dir should have disappeared: %v"
,
wd
,
fi
)
if
fi
,
_
:=
os
.
Lstat
(
wd
+
"/mnt/dir"
);
fi
!=
nil
{
t
.
Fatalf
(
"%s/mnt/dir should have disappeared: %v"
,
wd
,
fi
)
}
if
fi
,
_
:=
os
.
Lstat
(
wd
+
"/m
ou
nt/renamed"
);
fi
==
nil
||
!
fi
.
IsDirectory
()
{
t
.
Fatalf
(
"%s/m
ou
nt/renamed should be directory: %v"
,
wd
,
fi
)
if
fi
,
_
:=
os
.
Lstat
(
wd
+
"/mnt/renamed"
);
fi
==
nil
||
!
fi
.
IsDirectory
()
{
t
.
Fatalf
(
"%s/mnt/renamed should be directory: %v"
,
wd
,
fi
)
}
entries
,
err
:=
ioutil
.
ReadDir
(
wd
+
"/m
ou
nt/renamed"
)
entries
,
err
:=
ioutil
.
ReadDir
(
wd
+
"/mnt/renamed"
)
if
err
!=
nil
||
len
(
entries
)
!=
1
||
entries
[
0
]
.
Name
!=
"subdir"
{
t
.
Errorf
(
"readdir(%s/m
ou
nt/renamed) should have one entry: %v, err %v"
,
wd
,
entries
,
err
)
t
.
Errorf
(
"readdir(%s/mnt/renamed) should have one entry: %v, err %v"
,
wd
,
entries
,
err
)
}
if
err
=
os
.
Mkdir
(
wd
+
"/m
ou
nt/dir"
,
0755
);
err
!=
nil
{
if
err
=
os
.
Mkdir
(
wd
+
"/mnt/dir"
,
0755
);
err
!=
nil
{
t
.
Errorf
(
"mkdir should succeed %v"
,
err
)
}
}
...
...
@@ -494,7 +494,7 @@ func TestUnionFsRenameDirAllSourcesGone(t *testing.T) {
CheckSuccess
(
err
)
freezeRo
(
wd
+
"/ro"
)
err
=
os
.
Rename
(
wd
+
"/m
ount/dir"
,
wd
+
"/mou
nt/renamed"
)
err
=
os
.
Rename
(
wd
+
"/m
nt/dir"
,
wd
+
"/m
nt/renamed"
)
CheckSuccess
(
err
)
names
:=
dirNames
(
wd
+
"/rw/"
+
testOpts
.
DeletionDirName
)
...
...
@@ -517,38 +517,38 @@ func TestUnionFsRenameDirWithDeletions(t *testing.T) {
CheckSuccess
(
err
)
freezeRo
(
wd
+
"/ro"
)
if
fi
,
_
:=
os
.
Lstat
(
wd
+
"/m
ou
nt/dir/subdir/file.txt"
);
fi
==
nil
||
!
fi
.
IsRegular
()
{
t
.
Fatalf
(
"%s/m
ou
nt/dir/subdir/file.txt should be file: %v"
,
wd
,
fi
)
if
fi
,
_
:=
os
.
Lstat
(
wd
+
"/mnt/dir/subdir/file.txt"
);
fi
==
nil
||
!
fi
.
IsRegular
()
{
t
.
Fatalf
(
"%s/mnt/dir/subdir/file.txt should be file: %v"
,
wd
,
fi
)
}
err
=
os
.
Remove
(
wd
+
"/m
ou
nt/dir/file.txt"
)
err
=
os
.
Remove
(
wd
+
"/mnt/dir/file.txt"
)
CheckSuccess
(
err
)
err
=
os
.
Rename
(
wd
+
"/m
ount/dir"
,
wd
+
"/mou
nt/renamed"
)
err
=
os
.
Rename
(
wd
+
"/m
nt/dir"
,
wd
+
"/m
nt/renamed"
)
CheckSuccess
(
err
)
if
fi
,
_
:=
os
.
Lstat
(
wd
+
"/m
ou
nt/dir/subdir/file.txt"
);
fi
!=
nil
{
t
.
Fatalf
(
"%s/m
ou
nt/dir/subdir/file.txt should have disappeared: %v"
,
wd
,
fi
)
if
fi
,
_
:=
os
.
Lstat
(
wd
+
"/mnt/dir/subdir/file.txt"
);
fi
!=
nil
{
t
.
Fatalf
(
"%s/mnt/dir/subdir/file.txt should have disappeared: %v"
,
wd
,
fi
)
}
if
fi
,
_
:=
os
.
Lstat
(
wd
+
"/m
ou
nt/dir"
);
fi
!=
nil
{
t
.
Fatalf
(
"%s/m
ou
nt/dir should have disappeared: %v"
,
wd
,
fi
)
if
fi
,
_
:=
os
.
Lstat
(
wd
+
"/mnt/dir"
);
fi
!=
nil
{
t
.
Fatalf
(
"%s/mnt/dir should have disappeared: %v"
,
wd
,
fi
)
}
if
fi
,
_
:=
os
.
Lstat
(
wd
+
"/m
ou
nt/renamed"
);
fi
==
nil
||
!
fi
.
IsDirectory
()
{
t
.
Fatalf
(
"%s/m
ou
nt/renamed should be directory: %v"
,
wd
,
fi
)
if
fi
,
_
:=
os
.
Lstat
(
wd
+
"/mnt/renamed"
);
fi
==
nil
||
!
fi
.
IsDirectory
()
{
t
.
Fatalf
(
"%s/mnt/renamed should be directory: %v"
,
wd
,
fi
)
}
if
fi
,
_
:=
os
.
Lstat
(
wd
+
"/m
ou
nt/renamed/file.txt"
);
fi
!=
nil
{
t
.
Fatalf
(
"%s/m
ou
nt/renamed/file.txt should have disappeared %#v"
,
wd
,
fi
)
if
fi
,
_
:=
os
.
Lstat
(
wd
+
"/mnt/renamed/file.txt"
);
fi
!=
nil
{
t
.
Fatalf
(
"%s/mnt/renamed/file.txt should have disappeared %#v"
,
wd
,
fi
)
}
if
err
=
os
.
Mkdir
(
wd
+
"/m
ou
nt/dir"
,
0755
);
err
!=
nil
{
if
err
=
os
.
Mkdir
(
wd
+
"/mnt/dir"
,
0755
);
err
!=
nil
{
t
.
Errorf
(
"mkdir should succeed %v"
,
err
)
}
if
fi
,
_
:=
os
.
Lstat
(
wd
+
"/m
ou
nt/dir/subdir"
);
fi
!=
nil
{
t
.
Fatalf
(
"%s/m
ou
nt/dir/subdir should have disappeared %#v"
,
wd
,
fi
)
if
fi
,
_
:=
os
.
Lstat
(
wd
+
"/mnt/dir/subdir"
);
fi
!=
nil
{
t
.
Fatalf
(
"%s/mnt/dir/subdir should have disappeared %#v"
,
wd
,
fi
)
}
}
...
...
@@ -559,19 +559,19 @@ func TestUnionFsRenameSymlink(t *testing.T) {
err
:=
os
.
Symlink
(
"linktarget"
,
wd
+
"/ro/link"
)
CheckSuccess
(
err
)
err
=
os
.
Rename
(
wd
+
"/m
ount/link"
,
wd
+
"/mou
nt/renamed"
)
err
=
os
.
Rename
(
wd
+
"/m
nt/link"
,
wd
+
"/m
nt/renamed"
)
CheckSuccess
(
err
)
if
fi
,
_
:=
os
.
Lstat
(
wd
+
"/m
ou
nt/link"
);
fi
!=
nil
{
t
.
Fatalf
(
"%s/m
ou
nt/link should have disappeared: %v"
,
wd
,
fi
)
if
fi
,
_
:=
os
.
Lstat
(
wd
+
"/mnt/link"
);
fi
!=
nil
{
t
.
Fatalf
(
"%s/mnt/link should have disappeared: %v"
,
wd
,
fi
)
}
if
fi
,
_
:=
os
.
Lstat
(
wd
+
"/m
ou
nt/renamed"
);
fi
==
nil
||
!
fi
.
IsSymlink
()
{
t
.
Fatalf
(
"%s/m
ou
nt/renamed should be link: %v"
,
wd
,
fi
)
if
fi
,
_
:=
os
.
Lstat
(
wd
+
"/mnt/renamed"
);
fi
==
nil
||
!
fi
.
IsSymlink
()
{
t
.
Fatalf
(
"%s/mnt/renamed should be link: %v"
,
wd
,
fi
)
}
if
link
,
err
:=
os
.
Readlink
(
wd
+
"/m
ou
nt/renamed"
);
err
!=
nil
||
link
!=
"linktarget"
{
t
.
Fatalf
(
"readlink(%s/m
ou
nt/renamed) should point to 'linktarget': %v, err %v"
,
wd
,
link
,
err
)
if
link
,
err
:=
os
.
Readlink
(
wd
+
"/mnt/renamed"
);
err
!=
nil
||
link
!=
"linktarget"
{
t
.
Fatalf
(
"readlink(%s/mnt/renamed) should point to 'linktarget': %v, err %v"
,
wd
,
link
,
err
)
}
}
...
...
@@ -584,7 +584,7 @@ func TestUnionFsWritableDir(t *testing.T) {
CheckSuccess
(
err
)
freezeRo
(
wd
+
"/ro"
)
fi
,
err
:=
os
.
Lstat
(
wd
+
"/m
ou
nt/subdir"
)
fi
,
err
:=
os
.
Lstat
(
wd
+
"/mnt/subdir"
)
CheckSuccess
(
err
)
if
fi
.
Permission
()
&
0222
==
0
{
t
.
Errorf
(
"unexpected permission %o"
,
fi
.
Permission
())
...
...
@@ -601,7 +601,7 @@ func TestUnionFsWriteAccess(t *testing.T) {
CheckSuccess
(
err
)
freezeRo
(
wd
+
"/ro"
)
errno
:=
syscall
.
Access
(
wd
+
"/m
ou
nt/file"
,
fuse
.
W_OK
)
errno
:=
syscall
.
Access
(
wd
+
"/mnt/file"
,
fuse
.
W_OK
)
if
errno
!=
0
{
err
=
os
.
Errno
(
errno
)
CheckSuccess
(
err
)
...
...
@@ -618,18 +618,18 @@ func TestUnionFsLink(t *testing.T) {
CheckSuccess
(
err
)
freezeRo
(
wd
+
"/ro"
)
err
=
os
.
Link
(
wd
+
"/m
ount/file"
,
wd
+
"/mou
nt/linked"
)
err
=
os
.
Link
(
wd
+
"/m
nt/file"
,
wd
+
"/m
nt/linked"
)
CheckSuccess
(
err
)
fi2
,
err
:=
os
.
Lstat
(
wd
+
"/m
ou
nt/linked"
)
fi2
,
err
:=
os
.
Lstat
(
wd
+
"/mnt/linked"
)
CheckSuccess
(
err
)
fi1
,
err
:=
os
.
Lstat
(
wd
+
"/m
ou
nt/file"
)
fi1
,
err
:=
os
.
Lstat
(
wd
+
"/mnt/file"
)
CheckSuccess
(
err
)
if
fi1
.
Ino
!=
fi2
.
Ino
{
t
.
Errorf
(
"inode numbers should be equal for linked files %v, %v"
,
fi1
.
Ino
,
fi2
.
Ino
)
}
c
,
err
:=
ioutil
.
ReadFile
(
wd
+
"/m
ou
nt/linked"
)
c
,
err
:=
ioutil
.
ReadFile
(
wd
+
"/mnt/linked"
)
if
string
(
c
)
!=
content
{
t
.
Errorf
(
"content mismatch got %q want %q"
,
string
(
c
),
content
)
}
...
...
@@ -642,8 +642,8 @@ func TestUnionFsTruncate(t *testing.T) {
writeToFile
(
wd
+
"/ro/file"
,
"hello"
)
freezeRo
(
wd
+
"/ro"
)
os
.
Truncate
(
wd
+
"/m
ou
nt/file"
,
2
)
content
:=
readFromFile
(
wd
+
"/m
ou
nt/file"
)
os
.
Truncate
(
wd
+
"/mnt/file"
,
2
)
content
:=
readFromFile
(
wd
+
"/mnt/file"
)
if
content
!=
"he"
{
t
.
Errorf
(
"unexpected content %v"
,
content
)
}
...
...
@@ -658,7 +658,7 @@ func TestUnionFsCopyChmod(t *testing.T) {
defer
clean
()
contents
:=
"hello"
fn
:=
wd
+
"/m
ou
nt/y"
fn
:=
wd
+
"/mnt/y"
err
:=
ioutil
.
WriteFile
(
fn
,
[]
byte
(
contents
),
0644
)
CheckSuccess
(
err
)
...
...
@@ -690,7 +690,7 @@ func TestUnionFsTruncateTimestamp(t *testing.T) {
defer
clean
()
contents
:=
"hello"
fn
:=
wd
+
"/m
ou
nt/y"
fn
:=
wd
+
"/mnt/y"
err
:=
ioutil
.
WriteFile
(
fn
,
[]
byte
(
contents
),
0644
)
CheckSuccess
(
err
)
time
.
Sleep
(
0.2e9
)
...
...
@@ -720,7 +720,7 @@ func TestUnionFsRemoveAll(t *testing.T) {
CheckSuccess
(
err
)
freezeRo
(
wd
+
"/ro"
)
err
=
os
.
RemoveAll
(
wd
+
"/m
ou
nt/dir"
)
err
=
os
.
RemoveAll
(
wd
+
"/mnt/dir"
)
if
err
!=
nil
{
t
.
Error
(
"Should delete all"
)
}
...
...
@@ -753,7 +753,7 @@ func TestUnionFsRmRf(t *testing.T) {
bin
,
err
:=
exec
.
LookPath
(
"rm"
)
CheckSuccess
(
err
)
cmd
:=
exec
.
Command
(
bin
,
"-rf"
,
wd
+
"/m
ou
nt/dir"
)
cmd
:=
exec
.
Command
(
bin
,
"-rf"
,
wd
+
"/mnt/dir"
)
err
=
cmd
.
Run
()
if
err
!=
nil
{
t
.
Fatal
(
"rm -rf returned error:"
,
err
)
...
...
@@ -790,11 +790,11 @@ func TestUnionFsDropDeletionCache(t *testing.T) {
CheckSuccess
(
err
)
freezeRo
(
wd
+
"/ro"
)
_
,
err
=
os
.
Lstat
(
wd
+
"/m
ou
nt/file"
)
_
,
err
=
os
.
Lstat
(
wd
+
"/mnt/file"
)
CheckSuccess
(
err
)
err
=
os
.
Remove
(
wd
+
"/m
ou
nt/file"
)
err
=
os
.
Remove
(
wd
+
"/mnt/file"
)
CheckSuccess
(
err
)
fi
,
_
:=
os
.
Lstat
(
wd
+
"/m
ou
nt/file"
)
fi
,
_
:=
os
.
Lstat
(
wd
+
"/mnt/file"
)
if
fi
!=
nil
{
t
.
Fatal
(
"Lstat() should have failed"
,
fi
)
}
...
...
@@ -805,16 +805,16 @@ func TestUnionFsDropDeletionCache(t *testing.T) {
t
.
Fatal
(
"unexpected names"
,
names
)
}
os
.
Remove
(
wd
+
"/rw/DELETIONS/"
+
names
[
0
])
fi
,
_
=
os
.
Lstat
(
wd
+
"/m
ou
nt/file"
)
fi
,
_
=
os
.
Lstat
(
wd
+
"/mnt/file"
)
if
fi
!=
nil
{
t
.
Fatal
(
"Lstat() should have failed"
,
fi
)
}
// Expire kernel entry.
time
.
Sleep
(
0.6e9
*
entryTtl
)
err
=
ioutil
.
WriteFile
(
wd
+
"/m
ou
nt/.drop_cache"
,
[]
byte
(
""
),
0644
)
err
=
ioutil
.
WriteFile
(
wd
+
"/mnt/.drop_cache"
,
[]
byte
(
""
),
0644
)
CheckSuccess
(
err
)
_
,
err
=
os
.
Lstat
(
wd
+
"/m
ou
nt/file"
)
_
,
err
=
os
.
Lstat
(
wd
+
"/mnt/file"
)
if
err
!=
nil
{
t
.
Fatal
(
"Lstat() should have succeeded"
,
err
)
}
...
...
@@ -827,25 +827,25 @@ func TestUnionFsDropCache(t *testing.T) {
err
:=
ioutil
.
WriteFile
(
wd
+
"/ro/file"
,
[]
byte
(
"bla"
),
0644
)
CheckSuccess
(
err
)
_
,
err
=
os
.
Lstat
(
wd
+
"/m
ou
nt/.drop_cache"
)
_
,
err
=
os
.
Lstat
(
wd
+
"/mnt/.drop_cache"
)
CheckSuccess
(
err
)
names
,
err
:=
Readdirnames
(
wd
+
"/m
ou
nt"
)
names
,
err
:=
Readdirnames
(
wd
+
"/mnt"
)
CheckSuccess
(
err
)
if
len
(
names
)
!=
1
||
names
[
0
]
!=
"file"
{
t
.
Fatal
(
"unexpected names"
,
names
)
}
err
=
ioutil
.
WriteFile
(
wd
+
"/ro/file2"
,
[]
byte
(
"blabla"
),
0644
)
names2
,
err
:=
Readdirnames
(
wd
+
"/m
ou
nt"
)
names2
,
err
:=
Readdirnames
(
wd
+
"/mnt"
)
CheckSuccess
(
err
)
if
len
(
names2
)
!=
len
(
names
)
{
t
.
Fatal
(
"mismatch"
,
names2
)
}
err
=
ioutil
.
WriteFile
(
wd
+
"/m
ou
nt/.drop_cache"
,
[]
byte
(
"does not matter"
),
0644
)
err
=
ioutil
.
WriteFile
(
wd
+
"/mnt/.drop_cache"
,
[]
byte
(
"does not matter"
),
0644
)
CheckSuccess
(
err
)
names2
,
err
=
Readdirnames
(
wd
+
"/m
ou
nt"
)
names2
,
err
=
Readdirnames
(
wd
+
"/mnt"
)
if
len
(
names2
)
!=
2
{
t
.
Fatal
(
"mismatch 2"
,
names2
)
}
...
...
@@ -856,7 +856,7 @@ func TestUnionFsDisappearing(t *testing.T) {
// writable Fs.
wd
,
_
:=
ioutil
.
TempDir
(
""
,
""
)
defer
os
.
RemoveAll
(
wd
)
err
:=
os
.
Mkdir
(
wd
+
"/m
ou
nt"
,
0700
)
err
:=
os
.
Mkdir
(
wd
+
"/mnt"
,
0700
)
fuse
.
CheckSuccess
(
err
)
err
=
os
.
Mkdir
(
wd
+
"/rw"
,
0700
)
...
...
@@ -877,7 +877,7 @@ func TestUnionFsDisappearing(t *testing.T) {
NegativeTimeout
:
entryTtl
,
}
state
,
_
,
err
:=
fuse
.
MountPathFileSystem
(
wd
+
"/m
ou
nt"
,
ufs
,
opts
)
state
,
_
,
err
:=
fuse
.
MountPathFileSystem
(
wd
+
"/mnt"
,
ufs
,
opts
)
CheckSuccess
(
err
)
defer
state
.
Unmount
()
state
.
Debug
=
fuse
.
VerboseTest
()
...
...
@@ -889,20 +889,20 @@ func TestUnionFsDisappearing(t *testing.T) {
CheckSuccess
(
err
)
freezeRo
(
wd
+
"/ro"
)
err
=
os
.
Remove
(
wd
+
"/m
ou
nt/file"
)
err
=
os
.
Remove
(
wd
+
"/mnt/file"
)
CheckSuccess
(
err
)
oldRoot
:=
wrFs
.
Root
wrFs
.
Root
=
"/dev/null"
time
.
Sleep
(
1.5
*
entryTtl
*
1e9
)
_
,
err
=
ioutil
.
ReadDir
(
wd
+
"/m
ou
nt"
)
_
,
err
=
ioutil
.
ReadDir
(
wd
+
"/mnt"
)
if
err
==
nil
{
t
.
Fatal
(
"Readdir should have failed"
)
}
log
.
Println
(
"expected readdir failure:"
,
err
)
err
=
ioutil
.
WriteFile
(
wd
+
"/m
ou
nt/file2"
,
[]
byte
(
"blabla"
),
0644
)
err
=
ioutil
.
WriteFile
(
wd
+
"/mnt/file2"
,
[]
byte
(
"blabla"
),
0644
)
if
err
==
nil
{
t
.
Fatal
(
"write should have failed"
)
}
...
...
@@ -912,11 +912,11 @@ func TestUnionFsDisappearing(t *testing.T) {
wrFs
.
Root
=
oldRoot
time
.
Sleep
(
1.5
*
entryTtl
*
1e9
)
_
,
err
=
ioutil
.
ReadDir
(
wd
+
"/m
ou
nt"
)
_
,
err
=
ioutil
.
ReadDir
(
wd
+
"/mnt"
)
if
err
!=
nil
{
t
.
Fatal
(
"Readdir should succeed"
,
err
)
}
err
=
ioutil
.
WriteFile
(
wd
+
"/m
ou
nt/file2"
,
[]
byte
(
"blabla"
),
0644
)
err
=
ioutil
.
WriteFile
(
wd
+
"/mnt/file2"
,
[]
byte
(
"blabla"
),
0644
)
if
err
!=
nil
{
t
.
Fatal
(
"write should succeed"
,
err
)
}
...
...
@@ -930,11 +930,11 @@ func TestUnionFsDeletedGetAttr(t *testing.T) {
CheckSuccess
(
err
)
freezeRo
(
wd
+
"/ro"
)
f
,
err
:=
os
.
Open
(
wd
+
"/m
ou
nt/file"
)
f
,
err
:=
os
.
Open
(
wd
+
"/mnt/file"
)
CheckSuccess
(
err
)
defer
f
.
Close
()
err
=
os
.
Remove
(
wd
+
"/m
ou
nt/file"
)
err
=
os
.
Remove
(
wd
+
"/mnt/file"
)
CheckSuccess
(
err
)
if
fi
,
err
:=
f
.
Stat
();
err
!=
nil
||
!
fi
.
IsRegular
()
{
...
...
@@ -949,10 +949,10 @@ func TestUnionFsDoubleOpen(t *testing.T) {
CheckSuccess
(
err
)
freezeRo
(
wd
+
"/ro"
)
roFile
,
err
:=
os
.
Open
(
wd
+
"/m
ou
nt/file"
)
roFile
,
err
:=
os
.
Open
(
wd
+
"/mnt/file"
)
CheckSuccess
(
err
)
defer
roFile
.
Close
()
rwFile
,
err
:=
os
.
OpenFile
(
wd
+
"/m
ou
nt/file"
,
os
.
O_WRONLY
|
os
.
O_TRUNC
,
0666
)
rwFile
,
err
:=
os
.
OpenFile
(
wd
+
"/mnt/file"
,
os
.
O_WRONLY
|
os
.
O_TRUNC
,
0666
)
CheckSuccess
(
err
)
defer
rwFile
.
Close
()
...
...
@@ -987,10 +987,10 @@ func TestUnionFsFdLeak(t *testing.T) {
CheckSuccess
(
err
)
freezeRo
(
wd
+
"/ro"
)
contents
,
err
:=
ioutil
.
ReadFile
(
wd
+
"/m
ou
nt/file"
)
contents
,
err
:=
ioutil
.
ReadFile
(
wd
+
"/mnt/file"
)
CheckSuccess
(
err
)
err
=
ioutil
.
WriteFile
(
wd
+
"/m
ou
nt/file"
,
contents
,
0644
)
err
=
ioutil
.
WriteFile
(
wd
+
"/mnt/file"
,
contents
,
0644
)
CheckSuccess
(
err
)
clean
()
...
...
@@ -1008,7 +1008,7 @@ func TestUnionFsStatFs(t *testing.T) {
defer
clean
()
s1
:=
syscall
.
Statfs_t
{}
err
:=
syscall
.
Statfs
(
wd
+
"/m
ou
nt"
,
&
s1
)
err
:=
syscall
.
Statfs
(
wd
+
"/mnt"
,
&
s1
)
if
err
!=
0
{
t
.
Fatal
(
"statfs mnt"
,
err
)
}
...
...
@@ -1021,7 +1021,7 @@ func TestUnionFsFlushSize(t *testing.T) {
wd
,
clean
:=
setupUfs
(
t
)
defer
clean
()
fn
:=
wd
+
"/m
ou
nt/file"
fn
:=
wd
+
"/mnt/file"
f
,
err
:=
os
.
OpenFile
(
fn
,
os
.
O_WRONLY
|
os
.
O_CREATE
,
0644
)
CheckSuccess
(
err
)
fi
,
err
:=
f
.
Stat
()
...
...
@@ -1042,9 +1042,9 @@ func TestUnionFsFlushRename(t *testing.T) {
wd
,
clean
:=
setupUfs
(
t
)
defer
clean
()
err
:=
ioutil
.
WriteFile
(
wd
+
"/m
ou
nt/file"
,
[]
byte
(
"x"
),
0644
)
err
:=
ioutil
.
WriteFile
(
wd
+
"/mnt/file"
,
[]
byte
(
"x"
),
0644
)
fn
:=
wd
+
"/m
ou
nt/tmp"
fn
:=
wd
+
"/mnt/tmp"
f
,
err
:=
os
.
OpenFile
(
fn
,
os
.
O_WRONLY
|
os
.
O_CREATE
,
0644
)
CheckSuccess
(
err
)
fi
,
err
:=
f
.
Stat
()
...
...
@@ -1054,7 +1054,7 @@ func TestUnionFsFlushRename(t *testing.T) {
CheckSuccess
(
err
)
f
.
Close
()
dst
:=
wd
+
"/m
ou
nt/file"
dst
:=
wd
+
"/mnt/file"
err
=
os
.
Rename
(
fn
,
dst
)
CheckSuccess
(
err
)
...
...
@@ -1070,14 +1070,14 @@ func TestUnionFsTruncGetAttr(t *testing.T) {
defer
clean
()
c
:=
[]
byte
(
"hello"
)
f
,
err
:=
os
.
OpenFile
(
wd
+
"/m
ou
nt/file"
,
os
.
O_CREATE
|
os
.
O_RDWR
|
os
.
O_TRUNC
,
0644
)
f
,
err
:=
os
.
OpenFile
(
wd
+
"/mnt/file"
,
os
.
O_CREATE
|
os
.
O_RDWR
|
os
.
O_TRUNC
,
0644
)
CheckSuccess
(
err
)
_
,
err
=
f
.
Write
(
c
)
CheckSuccess
(
err
)
err
=
f
.
Close
()
CheckSuccess
(
err
)
fi
,
err
:=
os
.
Lstat
(
wd
+
"/m
ou
nt/file"
)
fi
,
err
:=
os
.
Lstat
(
wd
+
"/mnt/file"
)
if
fi
.
Size
!=
int64
(
len
(
c
))
{
t
.
Fatalf
(
"Length mismatch got %d want %d"
,
fi
.
Size
,
len
(
c
))
}
...
...
@@ -1093,7 +1093,7 @@ func TestUnionFsPromoteDirTimeStamp(t *testing.T) {
CheckSuccess
(
err
)
freezeRo
(
wd
+
"/ro"
)
err
=
os
.
Chmod
(
wd
+
"/m
ou
nt/subdir/file"
,
0060
)
err
=
os
.
Chmod
(
wd
+
"/mnt/subdir/file"
,
0060
)
CheckSuccess
(
err
)
fRo
,
err
:=
os
.
Lstat
(
wd
+
"/ro/subdir"
)
...
...
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