compareRoots.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package hybridBackup
  2. import (
  3. "os"
  4. "path/filepath"
  5. "time"
  6. "imuslab.com/arozos/mod/filesystem/hidden"
  7. )
  8. /*
  9. Compare roots
  10. This script compare the files between two folder recursively
  11. */
  12. //This function check which file exists in backup but not source drive.
  13. //Only usable for basic and nightly backup mode
  14. func (t *BackupTask) compareRootPaths() ([]*RestorableFile, error) {
  15. results := []*RestorableFile{}
  16. //Check if the source and the backup disk exists
  17. for key, value := range t.DeleteFileMarkers {
  18. //Check if the source file exists
  19. assumedSourcePosition := filepath.Join(t.ParentPath, key)
  20. backupFilePosition := filepath.Join(t.DiskPath, "/backup/", key)
  21. if !fileExists(assumedSourcePosition) && fileExists(backupFilePosition) {
  22. //This is a restorable file
  23. var filesize int64 = 0
  24. fi, err := os.Stat(backupFilePosition)
  25. if err != nil {
  26. filesize = 0
  27. } else {
  28. filesize = fi.Size()
  29. }
  30. fileIsHidden, _ := hidden.IsHidden(backupFilePosition, true)
  31. //Create the Restorable File
  32. thisFile := RestorableFile{
  33. Filename: filepath.Base(key),
  34. IsHidden: fileIsHidden,
  35. Filesize: filesize,
  36. RelpathOnDisk: filepath.ToSlash(key),
  37. RestorePoint: filepath.ToSlash(assumedSourcePosition),
  38. BackupDiskUID: t.DiskUID,
  39. RemainingTime: autoDeleteTime - (time.Now().Unix() - value),
  40. DeleteTime: value,
  41. IsSnapshot: false,
  42. }
  43. results = append(results, &thisFile)
  44. }
  45. }
  46. return results, nil
  47. }