|
|
@ -2,6 +2,7 @@ package Filesystem |
|
|
|
|
|
|
|
import ( |
|
|
|
"os" |
|
|
|
"path/filepath" |
|
|
|
|
|
|
|
"github.com/vbauerster/mpb" |
|
|
|
bolt "go.etcd.io/bbolt" |
|
|
@ -11,21 +12,22 @@ import ( |
|
|
|
"PackageManager/Variables" |
|
|
|
) |
|
|
|
|
|
|
|
func pickFilesSingle(rootPath string) error { |
|
|
|
func pickFilesSingle(fileKey, filePath string) error { |
|
|
|
var ( |
|
|
|
indexBucket *bolt.Bucket |
|
|
|
picksBucket *bolt.Bucket |
|
|
|
e error |
|
|
|
) |
|
|
|
|
|
|
|
e = Database.FsDB.Batch(func(tx *bolt.Tx) error { |
|
|
|
indexBucket = tx.Bucket(Variables.FsHashIndexBucket) |
|
|
|
picksBucket = tx.Bucket(Variables.FsHashPicksBucket) |
|
|
|
|
|
|
|
e = AddFileToBucket(picksBucket, rootPath) |
|
|
|
e = AddFileToBucket(picksBucket, fileKey, filePath) |
|
|
|
if e != nil { |
|
|
|
return e |
|
|
|
} |
|
|
|
return RemoveFileFromBucket(indexBucket, rootPath) |
|
|
|
return RemoveFileFromBucket(indexBucket, fileKey) |
|
|
|
}) |
|
|
|
return e |
|
|
|
} |
|
|
@ -61,7 +63,7 @@ func pickFilesRecursive(rootPath string) error { |
|
|
|
if len(fsStatus.NewFiles) > 0 { |
|
|
|
for _, f = range fsStatus.NewFiles { |
|
|
|
bar.Increment() |
|
|
|
e = AddFileToBucket(picksBucket, f) |
|
|
|
e = AddFileToBucket(picksBucket, f, f) |
|
|
|
if e != nil { |
|
|
|
return e |
|
|
|
} |
|
|
@ -71,7 +73,7 @@ func pickFilesRecursive(rootPath string) error { |
|
|
|
if len(fsStatus.ModifiedFiles) > 0 { |
|
|
|
for _, f = range fsStatus.ModifiedFiles { |
|
|
|
bar.Increment() |
|
|
|
e = AddFileToBucket(picksBucket, f) |
|
|
|
e = AddFileToBucket(picksBucket, f, f) |
|
|
|
if e != nil { |
|
|
|
return e |
|
|
|
} |
|
|
@ -100,17 +102,20 @@ func pickFilesRecursive(rootPath string) error { |
|
|
|
|
|
|
|
func PickFiles(rootPath string) error { |
|
|
|
var ( |
|
|
|
rootStat os.FileInfo |
|
|
|
e error |
|
|
|
realRootPath string |
|
|
|
rootStat os.FileInfo |
|
|
|
e error |
|
|
|
) |
|
|
|
|
|
|
|
rootStat, e = os.Stat(rootPath) |
|
|
|
realRootPath = filepath.Join(Variables.RootDir, rootPath) |
|
|
|
|
|
|
|
rootStat, e = os.Stat(realRootPath) |
|
|
|
if e != nil { |
|
|
|
return e |
|
|
|
} |
|
|
|
|
|
|
|
if !rootStat.IsDir() { |
|
|
|
return pickFilesSingle(rootPath) |
|
|
|
return pickFilesSingle(rootPath, realRootPath) |
|
|
|
} |
|
|
|
|
|
|
|
return pickFilesRecursive(rootPath) |
|
|
|