package Filesystem
|
|
|
|
import (
|
|
"PackageManager/Client/Database"
|
|
"PackageManager/Variables"
|
|
|
|
bolt "go.etcd.io/bbolt"
|
|
)
|
|
|
|
func PickFiles(rootPath string) error {
|
|
var (
|
|
fsStatus FilesystemStatus
|
|
picksBucket *bolt.Bucket
|
|
f string
|
|
e error
|
|
)
|
|
|
|
fsStatus, e = GetFilesystemDiff(rootPath)
|
|
if e != nil {
|
|
return e
|
|
}
|
|
|
|
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)
|
|
if e != nil {
|
|
return e
|
|
}
|
|
}
|
|
}
|
|
|
|
if len(fsStatus.ModifiedFiles) > 0 {
|
|
for _, f = range fsStatus.NewFiles {
|
|
e = AddFileToBucket(picksBucket, f)
|
|
if e != nil {
|
|
return e
|
|
}
|
|
}
|
|
}
|
|
|
|
if len(fsStatus.MissingFiles) > 0 {
|
|
for _, f = range fsStatus.NewFiles {
|
|
e = RemoveFileFromBucket(picksBucket, f)
|
|
if e != nil {
|
|
return e
|
|
}
|
|
}
|
|
}
|
|
|
|
return nil
|
|
})
|
|
|
|
return e
|
|
}
|
|
|
|
func ResetAllPickedFiles() error {
|
|
var (
|
|
fsStatus FilesystemStatus
|
|
picksBucket *bolt.Bucket
|
|
f string
|
|
e error
|
|
)
|
|
|
|
fsStatus, e = GetFilesystemDiff(Variables.RootDir)
|
|
if e != nil {
|
|
return e
|
|
}
|
|
|
|
e = Database.FsDB.Batch(func(tx *bolt.Tx) error {
|
|
picksBucket = tx.Bucket(Variables.FsHashPicksBucket)
|
|
|
|
if len(fsStatus.PickedFiles) > 0 {
|
|
for _, f = range fsStatus.PickedFiles {
|
|
e = RemoveFileFromBucket(picksBucket, f)
|
|
if e != nil {
|
|
return e
|
|
}
|
|
}
|
|
}
|
|
|
|
return nil
|
|
})
|
|
|
|
return e
|
|
}
|