compareRoots.go 1.6 KB

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