mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-03-12 15:20:21 +01:00
Enhance error handling
This commit is contained in:
@@ -56,14 +56,12 @@ public final class CopyOnWrite {
|
||||
Path backupFile = backupOriginalFile(targetFile);
|
||||
try {
|
||||
Files.move(temporaryFile, targetFile);
|
||||
if (backupFile != null) {
|
||||
Files.delete(backupFile);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
LOG.error("Error renaming temporary file {} to target file {}", temporaryFile, targetFile);
|
||||
restoreBackup(targetFile, backupFile);
|
||||
throw new StoreException("could rename temporary file to target file", e);
|
||||
}
|
||||
deleteBackupFile(backupFile);
|
||||
}
|
||||
|
||||
private static Path backupOriginalFile(Path targetFile) {
|
||||
@@ -82,6 +80,17 @@ public final class CopyOnWrite {
|
||||
}
|
||||
}
|
||||
|
||||
private static void deleteBackupFile(Path backupFile) {
|
||||
if (backupFile != null) {
|
||||
try {
|
||||
Files.delete(backupFile);
|
||||
} catch (IOException e) {
|
||||
LOG.warn("Could not delete backup file {}", backupFile);
|
||||
throw new StoreException("could not delete backup file", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void restoreBackup(Path targetFile, Path backupFile) {
|
||||
if (backupFile != null) {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user