diff options
author | Jakob Unterwurzacher | 2016-08-30 00:23:55 +0200 |
---|---|---|
committer | Jakob Unterwurzacher | 2016-09-25 16:43:17 +0200 |
commit | 777eb8e62f19895e9b2d3d8364a6ae1c40ff3ebc (patch) | |
tree | 4aab732aa3f78c667a36c4fa198f10df7e447ae8 /internal/fusefrontend_reverse/rpath.go | |
parent | 5931eea3877ae34cdb18ac36e5cf5fba3f74b82b (diff) |
reverse: rename types to reverseXYZ
...to prevent confusion with the forward variants.
FS -> reverseFS
file -> reverseFile
Also add an incomplete read implementation.
Diffstat (limited to 'internal/fusefrontend_reverse/rpath.go')
-rw-r--r-- | internal/fusefrontend_reverse/rpath.go | 39 |
1 files changed, 27 insertions, 12 deletions
diff --git a/internal/fusefrontend_reverse/rpath.go b/internal/fusefrontend_reverse/rpath.go index 9377958..7e11ca3 100644 --- a/internal/fusefrontend_reverse/rpath.go +++ b/internal/fusefrontend_reverse/rpath.go @@ -1,15 +1,24 @@ package fusefrontend_reverse import ( + "encoding/base64" + "fmt" "path/filepath" "strings" + "syscall" ) -func (fs *FS) abs(relPath string, err error) (string, error) { +var zeroDirIV []byte + +func init() { + zeroDirIV = make([]byte, 16) +} + +func (rfs *reverseFS) abs(relPath string, err error) (string, error) { if err != nil { return "", err } - return filepath.Join(fs.args.Cipherdir, relPath), nil + return filepath.Join(rfs.args.Cipherdir, relPath), nil } const ( @@ -17,30 +26,36 @@ const ( DECRYPT ) -func (fs *FS) encryptPath(relPath string) (string, error) { - return fs.transformPath(relPath, ENCRYPT) +func (rfs *reverseFS) encryptPath(relPath string) (string, error) { + return rfs.transformPath(relPath, ENCRYPT) } -func (fs *FS) decryptPath(relPath string) (string, error) { - return fs.transformPath(relPath, DECRYPT) +func (rfs *reverseFS) decryptPath(relPath string) (string, error) { + return rfs.transformPath(relPath, DECRYPT) } -func (fs *FS) transformPath(relPath string, direction int) (string, error) { - if fs.args.PlaintextNames { +func (rfs *reverseFS) transformPath(relPath string, direction int) (string, error) { + if rfs.args.PlaintextNames || relPath == "" { return relPath, nil } var err error var transformedParts []string - iv := make([]byte, 16) parts := strings.Split(relPath, "/") for _, part := range parts { var transformedPart string switch direction { case ENCRYPT: - transformedPart = fs.nameTransform.EncryptName(part, iv) + transformedPart = rfs.nameTransform.EncryptName(part, zeroDirIV) case DECRYPT: - transformedPart, err = fs.nameTransform.DecryptName(part, iv) + transformedPart, err = rfs.nameTransform.DecryptName(part, zeroDirIV) if err != nil { + // We get lots of decrypt requests for names like ".Trash" that + // are invalid base64. Convert them to ENOENT so the correct + // error gets returned to the user. + if _, ok := err.(base64.CorruptInputError); ok { + fmt.Printf("converting to ENOENT\n") + return "", syscall.ENOENT + } return "", err } default: @@ -51,6 +66,6 @@ func (fs *FS) transformPath(relPath string, direction int) (string, error) { return filepath.Join(transformedParts...), nil } -func (fs *FS) isFiltered(relPath string) bool { +func (rfs *reverseFS) isFiltered(relPath string) bool { return false } |