Commit 19af0e94 authored by Manuel Klimek's avatar Manuel Klimek Committed by Han-Wen Nienhuys

Allows LoopbackFileSystem to use symlinks to directories

as root. This is important especially when LoopbackFileSystem
is used in combination with AutoUnionFs and the root one of
the overlays is a symlink - in that case we don't want to
link out of the overlay directory structure.
parent dba1cecd
......@@ -32,9 +32,16 @@ func (me *LoopbackFileSystem) GetPath(relPath string) string {
return filepath.Join(me.Root, relPath)
}
func (me *LoopbackFileSystem) GetAttr(name string, context *Context) (*os.FileInfo, Status) {
func (me *LoopbackFileSystem) GetAttr(name string, context *Context) (fi *os.FileInfo, code Status) {
fullPath := me.GetPath(name)
fi, err := os.Lstat(fullPath)
var err os.Error = nil
if name == "" {
// When GetAttr is called for the toplevel directory, we always want
// to look through symlinks.
fi, err = os.Stat(fullPath)
} else {
fi, err = os.Lstat(fullPath)
}
if err != nil {
return nil, OsErrorToErrno(err)
}
......
......@@ -666,3 +666,27 @@ func TestStatFs(t *testing.T) {
t.Error("Mismatch", s1, s2)
}
}
func TestOriginalIsSymlink(t *testing.T) {
tmpDir := MakeTempDir()
defer os.RemoveAll(tmpDir)
orig := tmpDir + "/orig"
err := os.Mkdir(orig, 0755)
CheckSuccess(err)
link := tmpDir + "/link"
mnt := tmpDir + "/mnt"
err = os.Mkdir(mnt, 0755)
CheckSuccess(err)
err = os.Symlink("orig", link)
CheckSuccess(err)
fs := NewLoopbackFileSystem(link)
state, _, err := MountFileSystem(mnt, fs, nil)
CheckSuccess(err)
defer state.Unmount()
go state.Loop(false)
_, err = os.Lstat(mnt)
CheckSuccess(err)
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment