Browse Source

Trim RootDir off bucket keys to line everything up

feature/create-install-pkgs
Tovi Jaeschke-Rogers 3 years ago
parent
commit
d133851f4f
4 changed files with 28 additions and 14 deletions
  1. +1
    -1
      Client/Filesystem/CommitFiles.go
  2. +3
    -3
      Client/Filesystem/ManageFileBucket.go
  3. +6
    -10
      Client/Filesystem/PickFiles.go
  4. +18
    -0
      Client/Filesystem/StipRootDir.go

+ 1
- 1
Client/Filesystem/CommitFiles.go View File

@ -32,7 +32,7 @@ func CommitFiles() error {
bar = ProgressBar.InitBar("Commiting...", len(pickedFiles)) bar = ProgressBar.InitBar("Commiting...", len(pickedFiles))
for _, f = range pickedFiles { for _, f = range pickedFiles {
bar.Increment() bar.Increment()
e = AddFileToBucket(indexBucket, f, f)
e = AddFileToBucket(indexBucket, f)
if e != nil { if e != nil {
return nil return nil
} }


+ 3
- 3
Client/Filesystem/ManageFileBucket.go View File

@ -6,7 +6,7 @@ import (
bolt "go.etcd.io/bbolt" bolt "go.etcd.io/bbolt"
) )
func AddFileToBucket(bucket *bolt.Bucket, key, filePath string) error {
func AddFileToBucket(bucket *bolt.Bucket, filePath string) error {
var ( var (
fileObject FileObject fileObject FileObject
fileObjectBytes []byte fileObjectBytes []byte
@ -25,9 +25,9 @@ func AddFileToBucket(bucket *bolt.Bucket, key, filePath string) error {
return e return e
} }
return bucket.Put([]byte(key), fileObjectBytes)
return bucket.Put([]byte(StripRootDir(filePath)), fileObjectBytes)
} }
func RemoveFileFromBucket(bucket *bolt.Bucket, filePath string) error { func RemoveFileFromBucket(bucket *bolt.Bucket, filePath string) error {
return bucket.Delete([]byte(filePath))
return bucket.Delete([]byte(StripRootDir(filePath)))
} }

+ 6
- 10
Client/Filesystem/PickFiles.go View File

@ -3,7 +3,6 @@ package Filesystem
import ( import (
"os" "os"
"path/filepath" "path/filepath"
"strings"
"github.com/vbauerster/mpb" "github.com/vbauerster/mpb"
bolt "go.etcd.io/bbolt" bolt "go.etcd.io/bbolt"
@ -13,7 +12,7 @@ import (
"PackageManager/Variables" "PackageManager/Variables"
) )
func pickFilesSingle(fileKey, filePath string) error {
func pickFilesSingle(filePath string) error {
var ( var (
indexBucket *bolt.Bucket indexBucket *bolt.Bucket
picksBucket *bolt.Bucket picksBucket *bolt.Bucket
@ -24,11 +23,11 @@ func pickFilesSingle(fileKey, filePath string) error {
indexBucket = tx.Bucket(Variables.FsHashIndexBucket) indexBucket = tx.Bucket(Variables.FsHashIndexBucket)
picksBucket = tx.Bucket(Variables.FsHashPicksBucket) picksBucket = tx.Bucket(Variables.FsHashPicksBucket)
e = AddFileToBucket(picksBucket, fileKey, filePath)
e = AddFileToBucket(picksBucket, filePath)
if e != nil { if e != nil {
return e return e
} }
return RemoveFileFromBucket(indexBucket, fileKey)
return RemoveFileFromBucket(indexBucket, filePath)
}) })
return e return e
} }
@ -40,7 +39,6 @@ func pickFilesRecursive(rootPath string) error {
picksBucket *bolt.Bucket picksBucket *bolt.Bucket
bar *mpb.Bar bar *mpb.Bar
totalLen int totalLen int
trimF string
f string f string
e error e error
) )
@ -65,8 +63,7 @@ func pickFilesRecursive(rootPath string) error {
if len(fsStatus.NewFiles) > 0 { if len(fsStatus.NewFiles) > 0 {
for _, f = range fsStatus.NewFiles { for _, f = range fsStatus.NewFiles {
bar.Increment() bar.Increment()
trimF = strings.TrimPrefix(f, Variables.RootDir)
e = AddFileToBucket(picksBucket, trimF, f)
e = AddFileToBucket(picksBucket, f)
if e != nil { if e != nil {
return e return e
} }
@ -76,8 +73,7 @@ func pickFilesRecursive(rootPath string) error {
if len(fsStatus.ModifiedFiles) > 0 { if len(fsStatus.ModifiedFiles) > 0 {
for _, f = range fsStatus.ModifiedFiles { for _, f = range fsStatus.ModifiedFiles {
bar.Increment() bar.Increment()
trimF = strings.TrimPrefix(f, Variables.RootDir)
e = AddFileToBucket(picksBucket, trimF, f)
e = AddFileToBucket(picksBucket, f)
if e != nil { if e != nil {
return e return e
} }
@ -119,7 +115,7 @@ func PickFiles(rootPath string) error {
} }
if !rootStat.IsDir() { if !rootStat.IsDir() {
return pickFilesSingle(rootPath, realRootPath)
return pickFilesSingle(realRootPath)
} }
return pickFilesRecursive(realRootPath) return pickFilesRecursive(realRootPath)


+ 18
- 0
Client/Filesystem/StipRootDir.go View File

@ -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,
),
)
}

Loading…
Cancel
Save