PackageManager just because
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1010 B

package Filesystem
import (
"PackageManager/Client/Database"
"PackageManager/Client/ProgressBar"
"PackageManager/Variables"
"github.com/vbauerster/mpb"
bolt "go.etcd.io/bbolt"
)
func CommitFiles() error {
var (
indexBucket *bolt.Bucket
picksBucket *bolt.Bucket
bar *mpb.Bar
pickedFiles []string
f string
err error
)
err = Database.FsDB.Batch(func(tx *bolt.Tx) error {
indexBucket = tx.Bucket(Variables.FsHashIndexBucket)
picksBucket = tx.Bucket(Variables.FsHashPicksBucket)
picksBucket.ForEach(func(k, v []byte) error {
pickedFiles = append(pickedFiles, string(k))
return nil
})
if len(pickedFiles) > 0 {
bar = ProgressBar.InitBar("Commiting...", len(pickedFiles))
for _, f = range pickedFiles {
bar.Increment()
err = AddFileToBucket(indexBucket, f)
if err != nil {
return nil
}
}
err = tx.DeleteBucket(Variables.FsHashPicksBucket)
if err != nil {
return err
}
}
return nil
})
return err
}