From 5d44a31b412e3db07313d3f7e839e2838cff67c0 Mon Sep 17 00:00:00 2001 From: Sebastian Lackner Date: Tue, 28 Nov 2017 01:28:29 +0100 Subject: fusefrontend: Use openBackingPath in Unlink and simplify code --- internal/fusefrontend/fs.go | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) (limited to 'internal') diff --git a/internal/fusefrontend/fs.go b/internal/fusefrontend/fs.go index 46787e2..08edd2b 100644 --- a/internal/fusefrontend/fs.go +++ b/internal/fusefrontend/fs.go @@ -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) } -- cgit v1.2.3