diff --git a/Client/Filesystem/CommitFiles.go b/Client/Filesystem/CommitFiles.go index 411a94b..642a72d 100644 --- a/Client/Filesystem/CommitFiles.go +++ b/Client/Filesystem/CommitFiles.go @@ -32,7 +32,7 @@ func CommitFiles() error { bar = ProgressBar.InitBar("Commiting...", len(pickedFiles)) for _, f = range pickedFiles { bar.Increment() - e = AddFileToBucket(indexBucket, f, f) + e = AddFileToBucket(indexBucket, f) if e != nil { return nil } diff --git a/Client/Filesystem/ManageFileBucket.go b/Client/Filesystem/ManageFileBucket.go index 3bde8f6..a98bcca 100644 --- a/Client/Filesystem/ManageFileBucket.go +++ b/Client/Filesystem/ManageFileBucket.go @@ -6,7 +6,7 @@ import ( bolt "go.etcd.io/bbolt" ) -func AddFileToBucket(bucket *bolt.Bucket, key, filePath string) error { +func AddFileToBucket(bucket *bolt.Bucket, filePath string) error { var ( fileObject FileObject fileObjectBytes []byte @@ -25,9 +25,9 @@ func AddFileToBucket(bucket *bolt.Bucket, key, filePath string) error { return e } - return bucket.Put([]byte(key), fileObjectBytes) + return bucket.Put([]byte(StripRootDir(filePath)), fileObjectBytes) } func RemoveFileFromBucket(bucket *bolt.Bucket, filePath string) error { - return bucket.Delete([]byte(filePath)) + return bucket.Delete([]byte(StripRootDir(filePath))) } diff --git a/Client/Filesystem/PickFiles.go b/Client/Filesystem/PickFiles.go index 288b230..934dde0 100644 --- a/Client/Filesystem/PickFiles.go +++ b/Client/Filesystem/PickFiles.go @@ -3,7 +3,6 @@ package Filesystem import ( "os" "path/filepath" - "strings" "github.com/vbauerster/mpb" bolt "go.etcd.io/bbolt" @@ -13,7 +12,7 @@ import ( "PackageManager/Variables" ) -func pickFilesSingle(fileKey, filePath string) error { +func pickFilesSingle(filePath string) error { var ( indexBucket *bolt.Bucket picksBucket *bolt.Bucket @@ -24,11 +23,11 @@ func pickFilesSingle(fileKey, filePath string) error { indexBucket = tx.Bucket(Variables.FsHashIndexBucket) picksBucket = tx.Bucket(Variables.FsHashPicksBucket) - e = AddFileToBucket(picksBucket, fileKey, filePath) + e = AddFileToBucket(picksBucket, filePath) if e != nil { return e } - return RemoveFileFromBucket(indexBucket, fileKey) + return RemoveFileFromBucket(indexBucket, filePath) }) return e } @@ -40,7 +39,6 @@ func pickFilesRecursive(rootPath string) error { picksBucket *bolt.Bucket bar *mpb.Bar totalLen int - trimF string f string e error ) @@ -65,8 +63,7 @@ func pickFilesRecursive(rootPath string) error { if len(fsStatus.NewFiles) > 0 { for _, f = range fsStatus.NewFiles { bar.Increment() - trimF = strings.TrimPrefix(f, Variables.RootDir) - e = AddFileToBucket(picksBucket, trimF, f) + e = AddFileToBucket(picksBucket, f) if e != nil { return e } @@ -76,8 +73,7 @@ func pickFilesRecursive(rootPath string) error { if len(fsStatus.ModifiedFiles) > 0 { for _, f = range fsStatus.ModifiedFiles { bar.Increment() - trimF = strings.TrimPrefix(f, Variables.RootDir) - e = AddFileToBucket(picksBucket, trimF, f) + e = AddFileToBucket(picksBucket, f) if e != nil { return e } @@ -119,7 +115,7 @@ func PickFiles(rootPath string) error { } if !rootStat.IsDir() { - return pickFilesSingle(rootPath, realRootPath) + return pickFilesSingle(realRootPath) } return pickFilesRecursive(realRootPath) diff --git a/Client/Filesystem/StipRootDir.go b/Client/Filesystem/StipRootDir.go new file mode 100644 index 0000000..0bf94ef --- /dev/null +++ b/Client/Filesystem/StipRootDir.go @@ -0,0 +1,18 @@ +package Filesystem + +import ( + "path/filepath" + "strings" + + "PackageManager/Variables" +) + +func StripRootDir(path string) string { + return filepath.Join( + "/", + strings.TrimPrefix( + path, + Variables.RootDir, + ), + ) +}