From 810303ce25bd444d5ca1e840519abb5ae0dcaa3b Mon Sep 17 00:00:00 2001 From: Gilbert Chen Date: Mon, 30 Mar 2020 17:44:53 -0400 Subject: [PATCH] Fail the backup if the repository can't be accessed or there are no files This is mainly to avoid creating an empty snapshot when a drive/share is not mounted which causes the subsequent backup to scan all files again. --- src/duplicacy_backupmanager.go | 5 +++++ src/duplicacy_snapshot.go | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/src/duplicacy_backupmanager.go b/src/duplicacy_backupmanager.go index 795135c..2e5a908 100644 --- a/src/duplicacy_backupmanager.go +++ b/src/duplicacy_backupmanager.go @@ -211,6 +211,11 @@ func (manager *BackupManager) Backup(top string, quickMode bool, threads int, ta return true } + if len(localSnapshot.Files) == 0 { + LOG_ERROR("SNAPSHOT_EMPTY", "No files under the repository to be backed up") + return false + } + // This cache contains all chunks referenced by last snasphot. Any other chunks will lead to a call to // UploadChunk. chunkCache := make(map[string]bool) diff --git a/src/duplicacy_snapshot.go b/src/duplicacy_snapshot.go index 016c85f..45180f9 100644 --- a/src/duplicacy_snapshot.go +++ b/src/duplicacy_snapshot.go @@ -91,6 +91,10 @@ func CreateSnapshotFromDirectory(id string, top string, nobackupFile string, fil snapshot.Files = append(snapshot.Files, directory) subdirectories, skipped, err := ListEntries(top, directory.Path, &snapshot.Files, patterns, nobackupFile, snapshot.discardAttributes) if err != nil { + if directory.Path == "" { + LOG_ERROR("LIST_FAILURE", "Failed to list the repository root: %v", err) + return nil, nil, nil, err + } LOG_WARN("LIST_FAILURE", "Failed to list subdirectory: %v", err) skippedDirectories = append(skippedDirectories, directory.Path) continue