Skip to content

Commit 3bddd14

Browse files
committed
unit tests for backup
1 parent 7e45dfc commit 3bddd14

File tree

9 files changed

+1296
-30
lines changed

9 files changed

+1296
-30
lines changed

backup/backup.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func statInputPaths(rawPaths []string) []File {
2727
}
2828
log.Println("Converted to absolute:", path)
2929

30-
stat, err := os.Stat(path)
30+
stat, err := fileOpener.Stat(path)
3131
if err != nil {
3232
panic("Path doesn't exist?")
3333
}
@@ -151,26 +151,26 @@ func DryBackup(rawPaths []string) {
151151
}
152152
defer tx.Rollback()
153153
statuses := make([]FileStatus, 0)
154+
var allPathsToBackup []string
154155
for _, input := range inputs {
155156
if input.info.IsDir() {
156-
filesMap := make(map[string]os.FileInfo)
157157
pathsToBackup := getDirectoriesToScan(input.path, config.Config().Includes)
158-
for _, path := range pathsToBackup {
159-
utils.WalkFiles(path, func(path string, info os.FileInfo) {
160-
filesMap[path] = info
161-
comparison := CompareFileToDb(path, info, tx, false)
162-
if comparison.Modified || comparison.New {
163-
statuses = append(statuses, comparison)
164-
}
165-
})
166-
}
158+
allPathsToBackup = append(allPathsToBackup, pathsToBackup...)
167159
} else {
168160
comparison := CompareFileToDb(input.path, input.info, tx, false)
169161
if comparison.Modified || comparison.New {
170162
statuses = append(statuses, comparison)
171163
}
172164
}
173165
}
166+
if len(allPathsToBackup) > 0 {
167+
walker.Walk(allPathsToBackup, func(path string, info os.FileInfo) {
168+
comparison := CompareFileToDb(path, info, tx, false)
169+
if comparison.Modified || comparison.New {
170+
statuses = append(statuses, comparison)
171+
}
172+
})
173+
}
174174
sort.Slice(statuses, func(i, j int) bool {
175175
return statuses[i].file.info.Size() < statuses[j].file.info.Size()
176176
})

0 commit comments

Comments
 (0)