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.

50 lines
944 B

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. fsStatus FilesystemStatus
  12. indexBucket *bolt.Bucket
  13. bar *mpb.Bar
  14. f string
  15. e error
  16. )
  17. fsStatus, e = GetFilesystemDiff(Variables.RootDir)
  18. if e != nil {
  19. return e
  20. }
  21. e = Database.FsDB.Batch(func(tx *bolt.Tx) error {
  22. indexBucket = tx.Bucket(Variables.FsHashIndexBucket)
  23. if len(fsStatus.PickedFiles) > 0 {
  24. bar = ProgressBar.InitBar("Commiting...", len(fsStatus.PickedFiles))
  25. for _, f = range fsStatus.PickedFiles {
  26. bar.Increment()
  27. e = AddFileToBucket(indexBucket, f)
  28. if e != nil {
  29. return nil
  30. }
  31. }
  32. e = tx.DeleteBucket(Variables.FsHashPicksBucket)
  33. if e != nil {
  34. return e
  35. }
  36. ProgressBar.CloseBar(bar)
  37. }
  38. return nil
  39. })
  40. return e
  41. }