package Filesystem import ( "PackageManager/Client/Database" "PackageManager/Client/ProgressBar" "PackageManager/Variables" "github.com/vbauerster/mpb" bolt "go.etcd.io/bbolt" ) func PickFiles(rootPath string) error { var ( fsStatus FilesystemStatus picksBucket *bolt.Bucket totalLen int bar *mpb.Bar f string e error ) fsStatus, e = GetFilesystemDiff(rootPath) if e != nil { return e } totalLen = len(fsStatus.NewFiles) + len(fsStatus.ModifiedFiles) + len(fsStatus.MissingFiles) if totalLen == 0 { return nil } bar = ProgressBar.InitBar("Adding...", totalLen) e = Database.FsDB.Batch(func(tx *bolt.Tx) error { picksBucket = tx.Bucket(Variables.FsHashPicksBucket) if len(fsStatus.NewFiles) > 0 { for _, f = range fsStatus.NewFiles { e = AddFileToBucket(picksBucket, f) bar.Increment() if e != nil { return e } } } if len(fsStatus.ModifiedFiles) > 0 { for _, f = range fsStatus.ModifiedFiles { e = AddFileToBucket(picksBucket, f) bar.Increment() if e != nil { return e } } } if len(fsStatus.MissingFiles) > 0 { for _, f = range fsStatus.NewFiles { e = RemoveFileFromBucket(picksBucket, f) bar.Increment() if e != nil { return e } } } return nil }) ProgressBar.CloseBar(bar) return e } func ResetAllPickedFiles() error { var ( e error ) e = Database.FsDB.Batch(func(tx *bolt.Tx) error { return tx.DeleteBucket(Variables.FsHashPicksBucket) }) return e }