diff options
author | Jakob Unterwurzacher | 2016-11-28 23:15:24 +0100 |
---|---|---|
committer | Jakob Unterwurzacher | 2016-11-28 23:15:24 +0100 |
commit | 55df8acac30c382390ca59474f1732b0f1b230b8 (patch) | |
tree | 2be0f90634de12675b7a82355b581288355c0537 /internal/fusefrontend/fs.go | |
parent | e3c5e3f1c8db31e62bbb781a238da4cf76ed1ffc (diff) |
fusefrontend: preserve owner for symlinks
https://github.com/rfjakob/gocryptfs/issues/64
Diffstat (limited to 'internal/fusefrontend/fs.go')
-rw-r--r-- | internal/fusefrontend/fs.go | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/internal/fusefrontend/fs.go b/internal/fusefrontend/fs.go index 8e12997..6165d86 100644 --- a/internal/fusefrontend/fs.go +++ b/internal/fusefrontend/fs.go @@ -351,7 +351,6 @@ func (fs *FS) Symlink(target string, linkName string, context *fuse.Context) (co // Symlinks are encrypted like file contents (GCM) and base64-encoded cBinTarget := fs.contentEnc.EncryptBlock([]byte(target), 0, nil) cTarget := base64.URLEncoding.EncodeToString(cBinTarget) - // Handle long file name cName := filepath.Base(cPath) if nametransform.IsLongContent(cName) { @@ -361,25 +360,32 @@ func (fs *FS) Symlink(target string, linkName string, context *fuse.Context) (co return fuse.ToStatus(err) } defer dirfd.Close() - - // Create ".name" + // Create ".name" file err = fs.nameTransform.WriteLongName(dirfd, cName, linkName) if err != nil { return fuse.ToStatus(err) } - - // Create symlink + // Create "gocryptfs.longfile." symlink // TODO use syscall.Symlinkat once it is available in Go err = syscall.Symlink(cTarget, cPath) if err != nil { nametransform.DeleteLongName(dirfd, cName) } - + } else { + // Create symlink + err = os.Symlink(cTarget, cPath) + } + if err != nil { return fuse.ToStatus(err) } - - err = os.Symlink(cTarget, cPath) - return fuse.ToStatus(err) + // Set owner + if fs.args.PreserveOwner { + err = os.Lchown(cPath, int(context.Owner.Uid), int(context.Owner.Gid)) + if err != nil { + tlog.Warn.Printf("Mknod: Lchown failed: %v", err) + } + } + return fuse.OK } // Rename implements pathfs.Filesystem. |