Skip to content

Commit

Permalink
fusefrontend: Introduce a openBackingPath helper and use it to simpli…
Browse files Browse the repository at this point in the history
…fy Mknod and Symlink
  • Loading branch information
slackner committed Nov 28, 2017
1 parent 16a289a commit a74644e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
14 changes: 2 additions & 12 deletions internal/fusefrontend/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,17 +278,12 @@ func (fs *FS) Mknod(path string, mode uint32, dev uint32, context *fuse.Context)
if fs.isFiltered(path) {
return fuse.EPERM
}
cPath, err := fs.getBackingPath(path)
if err != nil {
return fuse.ToStatus(err)
}
dirfd, err := os.Open(filepath.Dir(cPath))
dirfd, cName, err := fs.openBackingPath(path)
if err != nil {
return fuse.ToStatus(err)
}
defer dirfd.Close()
// Create ".name" file to store long file name (except in PlaintextNames mode)
cName := filepath.Base(cPath)
if !fs.args.PlaintextNames && nametransform.IsLongContent(cName) {
err = fs.nameTransform.WriteLongName(dirfd, cName, path)
if err != nil {
Expand Down Expand Up @@ -423,11 +418,7 @@ func (fs *FS) Symlink(target string, linkName string, context *fuse.Context) (co
if fs.isFiltered(linkName) {
return fuse.EPERM
}
cPath, err := fs.getBackingPath(linkName)
if err != nil {
return fuse.ToStatus(err)
}
dirfd, err := os.Open(filepath.Dir(cPath))
dirfd, cName, err := fs.openBackingPath(linkName)
if err != nil {
return fuse.ToStatus(err)
}
Expand All @@ -439,7 +430,6 @@ func (fs *FS) Symlink(target string, linkName string, context *fuse.Context) (co
cTarget = fs.nameTransform.B64.EncodeToString(cBinTarget)
}
// Create ".name" file to store long file name (except in PlaintextNames mode)
cName := filepath.Base(cPath)
if !fs.args.PlaintextNames && nametransform.IsLongContent(cName) {
err = fs.nameTransform.WriteLongName(dirfd, cName, linkName)
if err != nil {
Expand Down
15 changes: 15 additions & 0 deletions internal/fusefrontend/names.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package fusefrontend
// This file forwards file encryption operations to cryptfs

import (
"os"
"path/filepath"

"github.com/rfjakob/gocryptfs/internal/configfile"
Expand Down Expand Up @@ -39,6 +40,20 @@ func (fs *FS) getBackingPath(relPath string) (string, error) {
return cAbsPath, nil
}

// openBackingPath - get the absolute encrypted path of the backing file
// and open the corresponding directory
func (fs *FS) openBackingPath(relPath string) (*os.File, string, error) {
cPath, err := fs.getBackingPath(relPath)
if err != nil {
return nil, "", err
}
dirfd, err := os.Open(filepath.Dir(cPath))
if err != nil {
return nil, "", err
}
return dirfd, filepath.Base(cPath), nil
}

// encryptPath - encrypt relative plaintext path
func (fs *FS) encryptPath(plainPath string) (string, error) {
if fs.args.PlaintextNames {
Expand Down

0 comments on commit a74644e

Please sign in to comment.