aboutsummaryrefslogtreecommitdiff
path: root/internal/nametransform
diff options
context:
space:
mode:
authorJakob Unterwurzacher2016-04-10 12:36:43 +0200
committerJakob Unterwurzacher2016-04-10 12:36:43 +0200
commit63d3e517349a6c4774a3f75f2fa039c780eaf5f9 (patch)
tree9a2265fd2b85991b4cc85f3304cff88c0dc26828 /internal/nametransform
parente42e46c97cc46b731b63f1edfe1a4407161057f9 (diff)
longnames: use symbolic constants instead of naked ints
Diffstat (limited to 'internal/nametransform')
-rw-r--r--internal/nametransform/longnames.go23
-rw-r--r--internal/nametransform/longnames_test.go6
2 files changed, 18 insertions, 11 deletions
diff --git a/internal/nametransform/longnames.go b/internal/nametransform/longnames.go
index dad269b..d048f95 100644
--- a/internal/nametransform/longnames.go
+++ b/internal/nametransform/longnames.go
@@ -25,18 +25,25 @@ func HashLongName(name string) string {
return longNamePrefix + hashBase64
}
+// Values returned by IsLongName
+const (
+ LongNameContent = iota
+ LongNameFilename = iota
+ LongNameNone = iota
+)
+
// IsLongName - detect if cName is
-// gocryptfs.longname.* ........ 1
-// gocryptfs.longname.*.name ... 2
-// else ........................ 0
+// gocryptfs.longname.[sha256] ........ LongNameContent (content of a long name file)
+// gocryptfs.longname.[sha256].name .... LongNameFilename (full file name of a long name file)
+// else ................................ LongNameNone (normal file)
func IsLongName(cName string) int {
if !strings.HasPrefix(cName, longNamePrefix) {
- return 0
+ return LongNameNone
}
if strings.HasSuffix(cName, longNameSuffix) {
- return 2
+ return LongNameFilename
}
- return 1
+ return LongNameContent
}
// ReadLongName - read path.name
@@ -51,7 +58,7 @@ func ReadLongName(path string) (string, error) {
// DeleteLongName - if cPath ends in "gocryptfs.longname.[sha256]",
// delete the "gocryptfs.longname.[sha256].name" file
func DeleteLongName(cPath string) error {
- if IsLongName(filepath.Base(cPath)) == 1 {
+ if IsLongName(filepath.Base(cPath)) == LongNameContent {
err := syscall.Unlink(cPath + longNameSuffix)
if err != nil {
toggledlog.Warn.Printf("DeleteLongName: %v", err)
@@ -65,7 +72,7 @@ func DeleteLongName(cPath string) error {
// "gocryptfs.longname.[sha256].name" file
func (n *NameTransform) WriteLongName(cPath string, plainPath string) (err error) {
cHashedName := filepath.Base(cPath)
- if IsLongName(cHashedName) != 1 {
+ if IsLongName(cHashedName) != LongNameContent {
// This is not a hashed file name, nothing to do
return nil
}
diff --git a/internal/nametransform/longnames_test.go b/internal/nametransform/longnames_test.go
index dc4098c..62073ec 100644
--- a/internal/nametransform/longnames_test.go
+++ b/internal/nametransform/longnames_test.go
@@ -6,17 +6,17 @@ import (
func TestIsLongName(t *testing.T) {
n := "gocryptfs.longname.LkwUdALvV_ANnzQN6ZZMYnxxfARD3IeZWCKnxGJjYmU=.name"
- if IsLongName(n) != 2 {
+ if IsLongName(n) != LongNameFilename {
t.Errorf("False negative")
}
n = "gocryptfs.longname.LkwUdALvV_ANnzQN6ZZMYnxxfARD3IeZWCKnxGJjYmU="
- if IsLongName(n) != 1 {
+ if IsLongName(n) != LongNameContent {
t.Errorf("False negative")
}
n = "LkwUdALvV_ANnzQN6ZZMYnxxfARD3IeZWCKnxGJjYmU="
- if IsLongName(n) != 0 {
+ if IsLongName(n) != LongNameNone {
t.Errorf("False positive")
}
}