From 88826dc51d7919ef8b190c079955230e653323e2 Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Sat, 19 Dec 2015 13:21:15 +0100 Subject: diriv: handle directory rename over directory If an empty directory is overwritten we will always get ENOTEMPTY as the "empty" directory will still contain gocryptfs.diriv. Handle that case by removing the target directory and trying again. Fixes issue #10 --- pathfs_frontend/fs.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'pathfs_frontend/fs.go') diff --git a/pathfs_frontend/fs.go b/pathfs_frontend/fs.go index f853556..e930228 100644 --- a/pathfs_frontend/fs.go +++ b/pathfs_frontend/fs.go @@ -1,5 +1,7 @@ package pathfs_frontend +// FUSE operations on paths + import ( "encoding/base64" "os" @@ -300,6 +302,17 @@ func (fs *FS) Rename(oldPath string, newPath string, context *fuse.Context) (cod fs.CryptFS.DirIVCacheEnc.Clear() err = os.Rename(cOldPath, cNewPath) + + if lerr, ok := err.(*os.LinkError); ok && lerr.Err == syscall.ENOTEMPTY { + // If an empty directory is overwritten we will always get + // ENOTEMPTY as the "empty" directory will still contain gocryptfs.diriv. + // Handle that case by removing the target directory and trying again. + cryptfs.Debug.Printf("Rename: Handling ENOTEMPTY\n") + if fs.Rmdir(newPath, context) == fuse.OK { + err = os.Rename(cOldPath, cNewPath) + } + } + return fuse.ToStatus(err) } -- cgit v1.2.3