* 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
|
// make sure java.io.tmpdir exists
|
||||||
File tmpdir = new File(System.getProperty("java.io.tmpdir"));
|
File tmpdir = new File(System.getProperty("java.io.tmpdir"));
|
||||||
tmpdir.mkdirs();
|
createFolders(tmpdir);
|
||||||
|
|
||||||
// initialize this stuff before anything else
|
// initialize this stuff before anything else
|
||||||
initializeCache();
|
initializeCache();
|
||||||
|
@ -437,9 +437,9 @@ public class Main {
|
||||||
try {
|
try {
|
||||||
for (int i = 0; true; i++) {
|
for (int i = 0; true; i++) {
|
||||||
File cache = new File(cacheRoot, String.format("%d", 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");
|
final File lockFile = new File(cache, ".lock");
|
||||||
boolean isNewCache = !lockFile.exists();
|
boolean isNewCache = !lockFile.exists();
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package net.filebot;
|
package net.filebot;
|
||||||
|
|
||||||
|
import static net.filebot.util.FileUtilities.*;
|
||||||
import static net.filebot.util.StringUtilities.*;
|
import static net.filebot.util.StringUtilities.*;
|
||||||
|
|
||||||
import java.awt.GraphicsEnvironment;
|
import java.awt.GraphicsEnvironment;
|
||||||
|
@ -143,9 +144,12 @@ public final class Settings {
|
||||||
}
|
}
|
||||||
|
|
||||||
// create folder if necessary
|
// create folder if necessary
|
||||||
if (!applicationFolder.exists()) {
|
try {
|
||||||
applicationFolder.mkdirs();
|
createFolders(applicationFolder);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new IllegalStateException("application.dir", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return applicationFolder;
|
return applicationFolder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,9 +164,12 @@ public final class Settings {
|
||||||
}
|
}
|
||||||
|
|
||||||
// create folder if necessary
|
// create folder if necessary
|
||||||
if (!cacheFolder.exists()) {
|
try {
|
||||||
cacheFolder.mkdirs();
|
createFolders(cacheFolder);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new IllegalStateException("application.cache", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return cacheFolder;
|
return cacheFolder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -310,7 +310,7 @@ public class ScriptShellMethods {
|
||||||
file = file.getAbsoluteFile();
|
file = file.getAbsoluteFile();
|
||||||
|
|
||||||
// make sure parent folders exist
|
// make sure parent folders exist
|
||||||
file.getParentFile().mkdirs();
|
FileUtilities.createFolders(file.getParentFile());
|
||||||
|
|
||||||
return FileUtilities.writeFile(self, file);
|
return FileUtilities.writeFile(self, file);
|
||||||
}
|
}
|
||||||
|
@ -324,7 +324,7 @@ public class ScriptShellMethods {
|
||||||
file = file.getAbsoluteFile();
|
file = file.getAbsoluteFile();
|
||||||
|
|
||||||
// make sure parent folders exist
|
// make sure parent folders exist
|
||||||
file.getParentFile().mkdirs();
|
FileUtilities.createFolders(file.getParentFile());
|
||||||
|
|
||||||
org.apache.commons.io.FileUtils.copyURLToFile(self, file);
|
org.apache.commons.io.FileUtils.copyURLToFile(self, file);
|
||||||
return file;
|
return file;
|
||||||
|
|
|
@ -156,11 +156,17 @@ public final class FileUtilities {
|
||||||
return org.apache.commons.io.FileUtils.deleteQuietly(file);
|
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 {
|
public static void createFileIfNotExists(File file) throws IOException {
|
||||||
if (!file.isFile()) {
|
if (!file.isFile()) {
|
||||||
// create parent folder structure if necessary & create file
|
// create parent folder structure if necessary & create file
|
||||||
Files.createDirectories(file.getParentFile().toPath());
|
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
|
* if an I/O error occurred
|
||||||
*/
|
*/
|
||||||
public File createFile(String name) throws IOException {
|
public File createFile(String name) throws IOException {
|
||||||
|
|
||||||
// if the directory does not exist it will be created
|
// if the directory does not exist it will be created
|
||||||
File file = new File(getFolder(), name);
|
File file = new File(getFolder(), name);
|
||||||
file.createNewFile();
|
file.createNewFile();
|
||||||
|
@ -97,7 +96,7 @@ public final class TemporaryFolder {
|
||||||
return File.createTempFile(prefix, suffix, getFolder());
|
return File.createTempFile(prefix, suffix, getFolder());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean deleteFile(String name) {
|
public boolean deleteFile(String name) throws IOException {
|
||||||
return new File(getFolder(), name).delete();
|
return new File(getFolder(), name).delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,15 +105,12 @@ public final class TemporaryFolder {
|
||||||
*
|
*
|
||||||
* @return the {@link File} object for this {@link TemporaryFolder}
|
* @return the {@link File} object for this {@link TemporaryFolder}
|
||||||
*/
|
*/
|
||||||
public File getFolder() {
|
public File getFolder() throws IOException {
|
||||||
if (!root.exists()) {
|
FileUtilities.createFolders(root);
|
||||||
root.mkdirs();
|
|
||||||
}
|
|
||||||
|
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TemporaryFolder subFolder(String name) {
|
public TemporaryFolder subFolder(String name) throws IOException {
|
||||||
return new TemporaryFolder(new File(getFolder(), name));
|
return new TemporaryFolder(new File(getFolder(), name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue