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.

86 lines
1.5 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
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 PickFiles(rootPath string) error {
  10. var (
  11. fsStatus FilesystemStatus
  12. picksBucket *bolt.Bucket
  13. totalLen int
  14. bar *mpb.Bar
  15. f string
  16. e error
  17. )
  18. fsStatus, e = GetFilesystemDiff(rootPath)
  19. if e != nil {
  20. return e
  21. }
  22. totalLen = len(fsStatus.NewFiles) + len(fsStatus.ModifiedFiles) + len(fsStatus.MissingFiles)
  23. if totalLen == 0 {
  24. return nil
  25. }
  26. bar = ProgressBar.InitBar("Adding...", totalLen)
  27. e = Database.FsDB.Batch(func(tx *bolt.Tx) error {
  28. picksBucket = tx.Bucket(Variables.FsHashPicksBucket)
  29. if len(fsStatus.NewFiles) > 0 {
  30. for _, f = range fsStatus.NewFiles {
  31. e = AddFileToBucket(picksBucket, f)
  32. bar.Increment()
  33. if e != nil {
  34. return e
  35. }
  36. }
  37. }
  38. if len(fsStatus.ModifiedFiles) > 0 {
  39. for _, f = range fsStatus.ModifiedFiles {
  40. e = AddFileToBucket(picksBucket, f)
  41. bar.Increment()
  42. if e != nil {
  43. return e
  44. }
  45. }
  46. }
  47. if len(fsStatus.MissingFiles) > 0 {
  48. for _, f = range fsStatus.NewFiles {
  49. e = RemoveFileFromBucket(picksBucket, f)
  50. bar.Increment()
  51. if e != nil {
  52. return e
  53. }
  54. }
  55. }
  56. return nil
  57. })
  58. ProgressBar.CloseBar(bar)
  59. return e
  60. }
  61. func ResetAllPickedFiles() error {
  62. var (
  63. e error
  64. )
  65. e = Database.FsDB.Batch(func(tx *bolt.Tx) error {
  66. return tx.DeleteBucket(Variables.FsHashPicksBucket)
  67. })
  68. return e
  69. }