diff options
author | Keuin <[email protected]> | 2021-02-15 18:28:21 +0800 |
---|---|---|
committer | Keuin <[email protected]> | 2021-02-15 18:28:21 +0800 |
commit | d8bc4a4428ca5f05e1ee888dc78fe276b5c51d55 (patch) | |
tree | 3a47b4beddda2321ab366f5026bbb19baf70af0c | |
parent | b171d46ce07a9ed9a426779fcff92dd1f56b3dd1 (diff) |
Add debug log
-rw-r--r-- | src/main/java/com/keuin/kbackupfabric/backup/incremental/manager/IncrementalBackupStorageManager.java | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/main/java/com/keuin/kbackupfabric/backup/incremental/manager/IncrementalBackupStorageManager.java b/src/main/java/com/keuin/kbackupfabric/backup/incremental/manager/IncrementalBackupStorageManager.java index 18e0e58..bea326f 100644 --- a/src/main/java/com/keuin/kbackupfabric/backup/incremental/manager/IncrementalBackupStorageManager.java +++ b/src/main/java/com/keuin/kbackupfabric/backup/incremental/manager/IncrementalBackupStorageManager.java @@ -15,7 +15,6 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.util.*; -import java.util.concurrent.atomic.AtomicInteger; import java.util.logging.Logger; import static org.apache.commons.io.FileUtils.forceDelete; @@ -25,6 +24,7 @@ import static org.apache.commons.io.FileUtils.forceDelete; */ public class IncrementalBackupStorageManager { + private final Logger logger = Logger.getLogger(IncrementalBackupStorageManager.class.getName()); private final Path backupStorageBase; private final Logger LOGGER = Logger.getLogger(IncrementalBackupStorageManager.class.getName()); @@ -82,8 +82,9 @@ public class IncrementalBackupStorageManager { File copyDestination = new File(backupStorageBase.toFile(), entry.getValue().getIdentifier().getIdentification()); File copySourceFile = new File(collectionBasePath.getAbsolutePath(), entry.getKey()); final long fileBytes = FilesystemUtil.getFileSizeBytes(copySourceFile.getAbsolutePath()); - if (!baseContainsObject(entry.getValue())) { + if (!contains(entry.getValue())) { // element does not exist. copy. + logger.info("Copy new file `" + copySourceFile.getName() + "`."); Files.copy(copySourceFile.toPath(), copyDestination.toPath()); copyCount = copyCount.addWith(new IncCopyResult(1, 1, fileBytes, fileBytes)); } else { @@ -174,7 +175,7 @@ public class IncrementalBackupStorageManager { File copySource = new File(backupStorageBase.toFile(), entry.getValue().getIdentifier().getIdentification()); File copyTarget = new File(collectionBasePath.getAbsolutePath(), entry.getKey()); - if (!baseContainsObject(entry.getValue())) { + if (!contains(entry.getValue())) { throw new IOException(String.format("File %s is missing in the backup storage. Cannot restore.", copySource.getName())); } if (copyTarget.exists()) { @@ -216,9 +217,10 @@ public class IncrementalBackupStorageManager { * @param objectElement the element. * @return true or false. */ - private boolean baseContainsObject(ObjectElement objectElement) { + private boolean contains(@NotNull ObjectElement objectElement) { // This can be extended to use more variants of hash functions and combinations of other attributes (such as file size) - return (new File(backupStorageBase.toFile(), objectElement.getIdentifier().getIdentification())).exists(); + Objects.requireNonNull(objectElement); + return contains(objectElement.getIdentifier()); } } |