diff options
author | Jakob Unterwurzacher | 2016-10-10 08:43:09 +0200 |
---|---|---|
committer | Jakob Unterwurzacher | 2016-10-10 08:53:29 +0200 |
commit | 828f7184838be17d04ff4d78d8b066f4947406f3 (patch) | |
tree | b400497ca98f5902a2dbc22baeaccab4874a9572 /internal/fusefrontend/fs_dir.go | |
parent | 40420cb4cd2997260fd00a2c1566ea62c146f6eb (diff) |
fusefrontend: Also preserve the owner in Mkdir
This already worked for files but was missing for dirs.
Diffstat (limited to 'internal/fusefrontend/fs_dir.go')
-rw-r--r-- | internal/fusefrontend/fs_dir.go | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/internal/fusefrontend/fs_dir.go b/internal/fusefrontend/fs_dir.go index a3b2ccf..b7a0251 100644 --- a/internal/fusefrontend/fs_dir.go +++ b/internal/fusefrontend/fs_dir.go @@ -20,7 +20,8 @@ import ( func (fs *FS) mkdirWithIv(cPath string, mode uint32) error { // Between the creation of the directory and the creation of gocryptfs.diriv - // the directory is inconsistent. Take the lock to prevent other readers. + // the directory is inconsistent. Take the lock to prevent other readers + // from seeing it. fs.dirIVLock.Lock() // The new directory may take the place of an older one that is still in the cache fs.nameTransform.DirIVCache.Clear() @@ -51,6 +52,13 @@ func (fs *FS) Mkdir(newPath string, mode uint32, context *fuse.Context) (code fu } if fs.args.PlaintextNames { err = os.Mkdir(cPath, os.FileMode(mode)) + // Set owner + if fs.args.PreserveOwner { + err = os.Chown(cPath, int(context.Owner.Uid), int(context.Owner.Gid)) + if err != nil { + tlog.Warn.Printf("Mkdir: Chown failed: %v", err) + } + } return fuse.ToStatus(err) } @@ -94,7 +102,17 @@ func (fs *FS) Mkdir(newPath string, mode uint32, context *fuse.Context) (code fu tlog.Warn.Printf("Mkdir: Chmod failed: %v", err) } } - + // Set owner + if fs.args.PreserveOwner { + err = os.Chown(cPath, int(context.Owner.Uid), int(context.Owner.Gid)) + if err != nil { + tlog.Warn.Printf("Mkdir: Chown failed: %v", err) + } + err = os.Chown(filepath.Join(cPath, nametransform.DirIVFilename), int(context.Owner.Uid), int(context.Owner.Gid)) + if err != nil { + tlog.Warn.Printf("Mkdir: Chown failed: %v", err) + } + } return fuse.OK } |