fusefrontend: fix PlaintextNames versions of Mkdir, Rmdir
The "!fs.args.DirIV" special case was removed by b17f0465c7
but that, by accident, also removed the handling for
PlaintextNames.
Re-add it as an explicit PlaintextNames special case.
Also adds support for removing directories that miss their
gocryptfs.diriv file for some reason.
This commit is contained in:
parent
547ddf4264
commit
3288d98703
@ -4,6 +4,7 @@ package fusefrontend
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"syscall"
|
"syscall"
|
||||||
@ -46,6 +47,11 @@ func (fs *FS) Mkdir(newPath string, mode uint32, context *fuse.Context) (code fu
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fuse.ToStatus(err)
|
return fuse.ToStatus(err)
|
||||||
}
|
}
|
||||||
|
if fs.args.PlaintextNames {
|
||||||
|
err = os.Mkdir(cPath, os.FileMode(mode))
|
||||||
|
return fuse.ToStatus(err)
|
||||||
|
}
|
||||||
|
|
||||||
// We need write and execute permissions to create gocryptfs.diriv
|
// We need write and execute permissions to create gocryptfs.diriv
|
||||||
origMode := mode
|
origMode := mode
|
||||||
mode = mode | 0300
|
mode = mode | 0300
|
||||||
@ -95,7 +101,10 @@ func (fs *FS) Rmdir(path string, context *fuse.Context) (code fuse.Status) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fuse.ToStatus(err)
|
return fuse.ToStatus(err)
|
||||||
}
|
}
|
||||||
|
if fs.args.PlaintextNames {
|
||||||
|
err = syscall.Rmdir(cPath)
|
||||||
|
return fuse.ToStatus(err)
|
||||||
|
}
|
||||||
parentDir := filepath.Dir(cPath)
|
parentDir := filepath.Dir(cPath)
|
||||||
parentDirFd, err := os.Open(parentDir)
|
parentDirFd, err := os.Open(parentDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -146,16 +155,12 @@ func (fs *FS) Rmdir(path string, context *fuse.Context) (code fuse.Status) {
|
|||||||
defer dirfd.Close()
|
defer dirfd.Close()
|
||||||
|
|
||||||
children, err := dirfd.Readdirnames(10)
|
children, err := dirfd.Readdirnames(10)
|
||||||
if err != nil {
|
if err == nil {
|
||||||
tlog.Warn.Printf("Rmdir: Readdirnames: %v", err)
|
|
||||||
return fuse.ToStatus(err)
|
|
||||||
}
|
|
||||||
// If the directory is not empty besides gocryptfs.diriv, do not even
|
// If the directory is not empty besides gocryptfs.diriv, do not even
|
||||||
// attempt the dance around gocryptfs.diriv.
|
// attempt the dance around gocryptfs.diriv.
|
||||||
if len(children) > 1 {
|
if len(children) > 1 {
|
||||||
return fuse.ToStatus(syscall.ENOTEMPTY)
|
return fuse.ToStatus(syscall.ENOTEMPTY)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Move "gocryptfs.diriv" to the parent dir as "gocryptfs.diriv.rmdir.XYZ"
|
// Move "gocryptfs.diriv" to the parent dir as "gocryptfs.diriv.rmdir.XYZ"
|
||||||
tmpName := fmt.Sprintf("gocryptfs.diriv.rmdir.%d", cryptocore.RandUint64())
|
tmpName := fmt.Sprintf("gocryptfs.diriv.rmdir.%d", cryptocore.RandUint64())
|
||||||
tlog.Debug.Printf("Rmdir: Renaming %s to %s", nametransform.DirIVFilename, tmpName)
|
tlog.Debug.Printf("Rmdir: Renaming %s to %s", nametransform.DirIVFilename, tmpName)
|
||||||
@ -189,6 +194,17 @@ func (fs *FS) Rmdir(path string, context *fuse.Context) (code fuse.Status) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
tlog.Warn.Printf("Rmdir: Could not clean up %s: %v", tmpName, err)
|
tlog.Warn.Printf("Rmdir: Could not clean up %s: %v", tmpName, err)
|
||||||
}
|
}
|
||||||
|
} else if err == io.EOF {
|
||||||
|
// The directory is empty
|
||||||
|
tlog.Warn.Printf("Rmdir: %q: gocryptfs.diriv is missing", cPath)
|
||||||
|
err = syscall.Rmdir(cPath)
|
||||||
|
if err != nil {
|
||||||
|
return fuse.ToStatus(err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
tlog.Warn.Printf("Rmdir: Readdirnames: %v", err)
|
||||||
|
return fuse.ToStatus(err)
|
||||||
|
}
|
||||||
// Delete .name file
|
// Delete .name file
|
||||||
if nametransform.IsLongContent(cName) {
|
if nametransform.IsLongContent(cName) {
|
||||||
nametransform.DeleteLongName(parentDirFd, cName)
|
nametransform.DeleteLongName(parentDirFd, cName)
|
||||||
|
Loading…
Reference in New Issue
Block a user