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
This commit is contained in:
Jakob Unterwurzacher 2015-12-19 13:21:15 +01:00
parent 00a712b4d1
commit 88826dc51d
4 changed files with 19 additions and 0 deletions

View File

@ -1,5 +1,7 @@
package pathfs_frontend
// FUSE operations on file handles
import (
"bytes"
"fmt"

View File

@ -1,5 +1,7 @@
package pathfs_frontend
// Helper functions for sparse files (files with holes)
import (
"github.com/hanwen/go-fuse/fuse"
"github.com/rfjakob/gocryptfs/cryptfs"

View File

@ -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)
}

View File

@ -1,5 +1,7 @@
package pathfs_frontend
// Mkdir and Rmdir
import (
"fmt"
"os"