Skip to content

Commit

Permalink
fusefrontend: Use openBackingPath in Unlink and simplify code
Browse files Browse the repository at this point in the history
  • Loading branch information
slackner authored and rfjakob committed Nov 28, 2017
1 parent 2591900 commit 5d44a31
Showing 1 changed file with 8 additions and 18 deletions.
26 changes: 8 additions & 18 deletions internal/fusefrontend/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,33 +382,23 @@ func (fs *FS) Unlink(path string, context *fuse.Context) (code fuse.Status) {
if fs.isFiltered(path) {
return fuse.EPERM
}
cPath, err := fs.getBackingPath(path)
dirfd, cName, err := fs.openBackingPath(path)
if err != nil {
return fuse.ToStatus(err)
}

cName := filepath.Base(cPath)
defer dirfd.Close()
// Delete content
err = syscallcompat.Unlinkat(int(dirfd.Fd()), cName)
if err != nil {
return fuse.ToStatus(err)
}
// Delete ".name" file
if !fs.args.PlaintextNames && nametransform.IsLongContent(cName) {
var dirfd *os.File
dirfd, err = os.Open(filepath.Dir(cPath))
if err != nil {
return fuse.ToStatus(err)
}
defer dirfd.Close()
// Delete content
err = syscallcompat.Unlinkat(int(dirfd.Fd()), cName)
if err != nil {
return fuse.ToStatus(err)
}
// Delete ".name"
err = nametransform.DeleteLongName(dirfd, cName)
if err != nil {
tlog.Warn.Printf("Unlink: could not delete .name file: %v", err)
}
return fuse.ToStatus(err)
}

err = syscall.Unlink(cPath)
return fuse.ToStatus(err)
}

Expand Down

0 comments on commit 5d44a31

Please sign in to comment.