mirror of
https://github.com/mitb-archive/filebot
synced 2024-12-24 00:38:52 -05:00
* use NIO.2 to create folders everywhere so we can get better error messages / exception messages
This commit is contained in:
parent
9ec4b6a97b
commit
7c90ed20fa
@ -134,7 +134,7 @@ public class Main {
|
||||
|
||||
// make sure java.io.tmpdir exists
|
||||
File tmpdir = new File(System.getProperty("java.io.tmpdir"));
|
||||
tmpdir.mkdirs();
|
||||
createFolders(tmpdir);
|
||||
|
||||
// initialize this stuff before anything else
|
||||
initializeCache();
|
||||
@ -437,9 +437,9 @@ public class Main {
|
||||
try {
|
||||
for (int i = 0; true; i++) {
|
||||
File cache = new File(cacheRoot, String.format("%d", i));
|
||||
if (!cache.isDirectory() && !cache.mkdirs()) {
|
||||
throw new IOException("Failed to create cache dir: " + cache);
|
||||
}
|
||||
|
||||
// make sure cache is accessible
|
||||
createFolders(cache);
|
||||
|
||||
final File lockFile = new File(cache, ".lock");
|
||||
boolean isNewCache = !lockFile.exists();
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.filebot;
|
||||
|
||||
import static net.filebot.util.FileUtilities.*;
|
||||
import static net.filebot.util.StringUtilities.*;
|
||||
|
||||
import java.awt.GraphicsEnvironment;
|
||||
@ -143,9 +144,12 @@ public final class Settings {
|
||||
}
|
||||
|
||||
// create folder if necessary
|
||||
if (!applicationFolder.exists()) {
|
||||
applicationFolder.mkdirs();
|
||||
try {
|
||||
createFolders(applicationFolder);
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException("application.dir", e);
|
||||
}
|
||||
|
||||
return applicationFolder;
|
||||
}
|
||||
|
||||
@ -160,9 +164,12 @@ public final class Settings {
|
||||
}
|
||||
|
||||
// create folder if necessary
|
||||
if (!cacheFolder.exists()) {
|
||||
cacheFolder.mkdirs();
|
||||
try {
|
||||
createFolders(cacheFolder);
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException("application.cache", e);
|
||||
}
|
||||
|
||||
return cacheFolder;
|
||||
}
|
||||
|
||||
|
@ -310,7 +310,7 @@ public class ScriptShellMethods {
|
||||
file = file.getAbsoluteFile();
|
||||
|
||||
// make sure parent folders exist
|
||||
file.getParentFile().mkdirs();
|
||||
FileUtilities.createFolders(file.getParentFile());
|
||||
|
||||
return FileUtilities.writeFile(self, file);
|
||||
}
|
||||
@ -324,7 +324,7 @@ public class ScriptShellMethods {
|
||||
file = file.getAbsoluteFile();
|
||||
|
||||
// make sure parent folders exist
|
||||
file.getParentFile().mkdirs();
|
||||
FileUtilities.createFolders(file.getParentFile());
|
||||
|
||||
org.apache.commons.io.FileUtils.copyURLToFile(self, file);
|
||||
return file;
|
||||
|
@ -156,11 +156,17 @@ public final class FileUtilities {
|
||||
return org.apache.commons.io.FileUtils.deleteQuietly(file);
|
||||
}
|
||||
|
||||
public static void createFolders(File folder) throws IOException {
|
||||
if (!folder.isDirectory()) {
|
||||
Files.createDirectories(folder.toPath());
|
||||
}
|
||||
}
|
||||
|
||||
public static void createFileIfNotExists(File file) throws IOException {
|
||||
if (!file.isFile()) {
|
||||
// create parent folder structure if necessary & create file
|
||||
Files.createDirectories(file.getParentFile().toPath());
|
||||
Files.createFile(file.toPath()).toFile();
|
||||
Files.createFile(file.toPath());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -73,7 +73,6 @@ public final class TemporaryFolder {
|
||||
* if an I/O error occurred
|
||||
*/
|
||||
public File createFile(String name) throws IOException {
|
||||
|
||||
// if the directory does not exist it will be created
|
||||
File file = new File(getFolder(), name);
|
||||
file.createNewFile();
|
||||
@ -97,7 +96,7 @@ public final class TemporaryFolder {
|
||||
return File.createTempFile(prefix, suffix, getFolder());
|
||||
}
|
||||
|
||||
public boolean deleteFile(String name) {
|
||||
public boolean deleteFile(String name) throws IOException {
|
||||
return new File(getFolder(), name).delete();
|
||||
}
|
||||
|
||||
@ -106,15 +105,12 @@ public final class TemporaryFolder {
|
||||
*
|
||||
* @return the {@link File} object for this {@link TemporaryFolder}
|
||||
*/
|
||||
public File getFolder() {
|
||||
if (!root.exists()) {
|
||||
root.mkdirs();
|
||||
}
|
||||
|
||||
public File getFolder() throws IOException {
|
||||
FileUtilities.createFolders(root);
|
||||
return root;
|
||||
}
|
||||
|
||||
public TemporaryFolder subFolder(String name) {
|
||||
public TemporaryFolder subFolder(String name) throws IOException {
|
||||
return new TemporaryFolder(new File(getFolder(), name));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user