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.

52 lines
1.0 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. package Filesystem
  2. import (
  3. "PackageManager/Client/Database"
  4. "PackageManager/Client/ProgressBar"
  5. "PackageManager/Variables"
  6. "github.com/vbauerster/mpb"
  7. bolt "go.etcd.io/bbolt"
  8. )
  9. func CommitFiles() error {
  10. var (
  11. indexBucket *bolt.Bucket
  12. picksBucket *bolt.Bucket
  13. bar *mpb.Bar
  14. pickedFiles []string
  15. f string
  16. e error
  17. )
  18. e = Database.FsDB.Batch(func(tx *bolt.Tx) error {
  19. indexBucket = tx.Bucket(Variables.FsHashIndexBucket)
  20. picksBucket = tx.Bucket(Variables.FsHashPicksBucket)
  21. picksBucket.ForEach(func(k, v []byte) error {
  22. pickedFiles = append(pickedFiles, string(k))
  23. return nil
  24. })
  25. if len(pickedFiles) > 0 {
  26. bar = ProgressBar.InitBar("Commiting...", len(pickedFiles))
  27. for _, f = range pickedFiles {
  28. bar.Increment()
  29. e = AddFileToBucket(indexBucket, f)
  30. if e != nil {
  31. return nil
  32. }
  33. }
  34. e = tx.DeleteBucket(Variables.FsHashPicksBucket)
  35. if e != nil {
  36. return e
  37. }
  38. ProgressBar.CloseBar(bar)
  39. }
  40. return nil
  41. })
  42. return e
  43. }