Commit ce025cb4 authored by freyssin's avatar freyssin
Browse files

Cleans the temporary directory if there is an error during backup.

parent 535add17
/*
* Copyright (C) 2009 - 2020 ScalAgent Distributed Technologies
* Copyright (C) 2009 - 2021 ScalAgent Distributed Technologies
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -498,6 +498,9 @@ public final class NGTransaction extends AbstractTransaction implements NGTransa
}
boolean deleteDirectory(File directoryToBeDeleted) {
if (directoryToBeDeleted == null)
return false;
File[] allContents = directoryToBeDeleted.listFiles();
if (allContents != null) {
for (File file : allContents) {
......@@ -520,6 +523,7 @@ public final class NGTransaction extends AbstractTransaction implements NGTransa
logmon.log(BasicLevel.DEBUG, "NGTransaction, backup");
if ((path == null) || path.isEmpty()) path = ".";
File tempDir = null;
try {
long start = System.currentTimeMillis();
......@@ -529,7 +533,7 @@ public final class NGTransaction extends AbstractTransaction implements NGTransa
// Creates the BackupFile and temporary directory
File backupTempFile = new File(path, backupName + ".temp");
BackupFile backupFile = new BackupFile(backupTempFile);
File tempDir = Files.createTempDirectory(backupName).toFile();
tempDir = Files.createTempDirectory(backupName).toFile();
logmon.log(BasicLevel.INFO, "NGTransaction, backup: " + tempDir.getCanonicalPath());
File repositoryTempFile = File.createTempFile("repository", ".temp", tempDir);
......@@ -556,6 +560,8 @@ public final class NGTransaction extends AbstractTransaction implements NGTransa
} catch (Exception exc) {
logmon.log(BasicLevel.ERROR, "NGTransaction, backup error", exc);
throw exc;
} finally {
deleteDirectory(tempDir);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment