mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 01:41:11 +01:00
Refactor: Add removeAndBackupFile method
This commit is contained in:
parent
d27e4dc249
commit
6f6836f733
@ -37,14 +37,12 @@ import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@Slf4j
|
||||
public class FileUtil {
|
||||
private static final Logger log = LoggerFactory.getLogger(FileUtil.class);
|
||||
|
||||
public static void rollingBackup(File dir, String fileName, int numMaxBackupFiles) {
|
||||
if (dir.exists()) {
|
||||
File backupDir = new File(Paths.get(dir.getAbsolutePath(), "backup").toString());
|
||||
@ -203,11 +201,24 @@ public class FileUtil {
|
||||
FileUtils.copyDirectory(source, destination);
|
||||
}
|
||||
|
||||
static File createNewFile(Path path) throws IOException {
|
||||
public static File createNewFile(Path path) throws IOException {
|
||||
File file = path.toFile();
|
||||
if (!file.createNewFile()) {
|
||||
throw new IOException("There already exists a file with path: " + path);
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
public static void removeAndBackupFile(File dbDir, File storageFile, String fileName, String backupFolderName)
|
||||
throws IOException {
|
||||
File corruptedBackupDir = new File(Paths.get(dbDir.getAbsolutePath(), backupFolderName).toString());
|
||||
if (!corruptedBackupDir.exists() && !corruptedBackupDir.mkdir()) {
|
||||
log.warn("make dir failed");
|
||||
}
|
||||
|
||||
File corruptedFile = new File(Paths.get(dbDir.getAbsolutePath(), backupFolderName, fileName).toString());
|
||||
if (storageFile.exists()) {
|
||||
renameFile(storageFile, corruptedFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user