aboutsummaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorJakob Unterwurzacher2016-06-04 16:39:27 +0200
committerJakob Unterwurzacher2016-06-04 16:39:27 +0200
commita602e798b1a65fdfe5e7f0260a34e17ea7ab0615 (patch)
treea0f2b4ddf8ad1b700c5e422f9e545107a2a38eb7 /internal
parent4ee612b36ef9854512d92c08cc6b6e7b756d1b9a (diff)
fusefrontend: report an error if all files in a directory were invalid
Just presenting an empty directory means that the user does not know that things went wrong unless he checks the syslog or tries to delete the directory. It would be nice to report the error even if only some files were invalid. However, go-fuse does not allow returning the valid directory entries AND an error.
Diffstat (limited to 'internal')
-rw-r--r--internal/fusefrontend/fs_dir.go42
1 files changed, 30 insertions, 12 deletions
diff --git a/internal/fusefrontend/fs_dir.go b/internal/fusefrontend/fs_dir.go
index ed12d08..5fea438 100644
--- a/internal/fusefrontend/fs_dir.go
+++ b/internal/fusefrontend/fs_dir.go
@@ -226,8 +226,11 @@ func (fs *FS) OpenDir(dirName string, context *fuse.Context) ([]fuse.DirEntry, f
return nil, fuse.ToStatus(err)
}
}
- // Filter and decrypt filenames
+
+ // Decrypted directory entries
var plain []fuse.DirEntry
+ var errorCount int
+ // Filter and decrypt filenames
for i := range cipherEntries {
cName := cipherEntries[i].Name
if dirName == "" && cName == configfile.ConfDefaultName {
@@ -244,29 +247,44 @@ func (fs *FS) OpenDir(dirName string, context *fuse.Context) ([]fuse.DirEntry, f
continue
}
+ // Handle long file name
+ isLong := nametransform.LongNameNone
if fs.args.LongNames {
- isLong := nametransform.NameType(cName)
- if isLong == nametransform.LongNameContent {
- cNameLong, err := nametransform.ReadLongName(filepath.Join(cDirAbsPath, cName))
- if err != nil {
- toggledlog.Warn.Printf("Could not read long name for file %s, skipping file", cName)
- continue
- }
- cName = cNameLong
- } else if isLong == nametransform.LongNameFilename {
- // ignore "gocryptfs.longname.*.name"
+ isLong = nametransform.NameType(cName)
+ }
+ if isLong == nametransform.LongNameContent {
+ cNameLong, err := nametransform.ReadLongName(filepath.Join(cDirAbsPath, cName))
+ if err != nil {
+ toggledlog.Warn.Printf("Skipping file %q in dir %q: Could not read .name: %v",
+ cName, cDirName, err)
+ errorCount++
continue
}
+ cName = cNameLong
+ } else if isLong == nametransform.LongNameFilename {
+ // ignore "gocryptfs.longname.*.name"
+ continue
}
+
name, err := fs.nameTransform.DecryptName(cName, cachedIV)
if err != nil {
- toggledlog.Warn.Printf("Skipping invalid name '%s' in dir '%s': %s",
+ toggledlog.Warn.Printf("Skipping invalid name %q in dir %q: %s",
cName, cDirName, err)
+ errorCount++
continue
}
cipherEntries[i].Name = name
plain = append(plain, cipherEntries[i])
}
+
+ if errorCount > 0 && len(plain) == 0 {
+ // Don't let the user stare on an empty directory. Report that things went
+ // wrong.
+ toggledlog.Warn.Printf("All %d entries in directory %q were invalid, returning EIO",
+ errorCount, cDirName)
+ status = fuse.EIO
+ }
+
return plain, status
}