Update isEmpty() to isMissingOrEmpty().

master
lodici 2017-03-07 18:51:46 +00:00
parent 3cc5f1cb1e
commit 51b6e359fd
2 changed files with 5 additions and 2 deletions

View File

@ -118,7 +118,7 @@ public class ImportWorker extends SwingWorker<Boolean, Void> {
String directoryName = "stats";
Path sourcePath = importDataPath.resolve(directoryName);
Path targetPath = MagicFileSystem.getDataPath().resolve(directoryName);
if (sourcePath.toFile().exists() && MagicFileSystem.isEmpty(targetPath)) {
if (sourcePath.toFile().exists() && MagicFileSystem.isMissingOrEmpty(targetPath)) {
IOFileFilter dbSuffixFilter = FileFilterUtils.suffixFileFilter(".db");
FileUtils.copyDirectory(sourcePath.toFile(), targetPath.toFile(), dbSuffixFilter);
}

View File

@ -312,7 +312,10 @@ public final class MagicFileSystem {
return getDataPath(DataPath.LOGS).resolve(MagicGameLog.LOG_FILE);
}
public static boolean isEmpty(Path path) throws IOException {
public static boolean isMissingOrEmpty(Path path) throws IOException {
if (!Files.exists(path)) {
return true;
}
if (Files.isDirectory(path)) {
try (DirectoryStream<Path> dirStream = Files.newDirectoryStream(path)) {
return !dirStream.iterator().hasNext();