From 9f56b33e0c8701085189aa77463f1b471b70a705 Mon Sep 17 00:00:00 2001 From: Sebastian Lackner Date: Sat, 25 Nov 2017 01:56:56 +0100 Subject: fusefrontend: Fix longname handling for renames with existing target Fixes https://github.com/rfjakob/gocryptfs/issues/170 Steps to reproduce the problem: * Create a regular forward mount point * Create a file with a shortname and one with a long filename * Try to run 'mv ' This should actually work and replace the existing file, but instead it fails with: mv: cannot move '' to '': File exists The problem is the creation of the .name file. If the target already exists we can safely ignore the EEXIST error and just keep the existing .name file. --- internal/fusefrontend/fs.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'internal/fusefrontend/fs.go') diff --git a/internal/fusefrontend/fs.go b/internal/fusefrontend/fs.go index 3c442a5..b4819fd 100644 --- a/internal/fusefrontend/fs.go +++ b/internal/fusefrontend/fs.go @@ -517,7 +517,13 @@ func (fs *FS) Rename(oldPath string, newPath string, context *fuse.Context) (cod finalNewPath = cNewName // Create destination .name file err = fs.nameTransform.WriteLongName(newDirFd, cNewName, newPath) - if err != nil { + // Failure to write the .name file is expected when the target path already + // exists. Since hashes are pretty unique, there is no need to modify the + // file anyway. We still set newDirFd to nil to ensure that we do not delete + // the file on error. + if err == syscall.EEXIST { + newDirFd = nil + } else if err != nil { return fuse.ToStatus(err) } } -- cgit v1.2.3