Always use canonical file path for application folder paths

This commit is contained in:
Reinhard Pointner 2018-03-18 18:24:29 +07:00
parent 9dc93cac2b
commit ba93efa911
2 changed files with 16 additions and 3 deletions

View File

@ -1,8 +1,13 @@
package net.filebot;
import static net.filebot.Logging.*;
import static net.filebot.Settings.*;
import java.io.File;
import java.io.IOException;
import java.nio.file.LinkOption;
import java.nio.file.Paths;
import java.util.logging.Level;
public enum ApplicationFolder {
@ -15,10 +20,18 @@ public enum ApplicationFolder {
Cache(System.getProperty("application.cache", AppData.resolve("cache").getPath()));
private final File path;
private File path;
ApplicationFolder(String path) {
this.path = new File(path);
try {
// use canonical file path
this.path = Paths.get(path).toRealPath(LinkOption.NOFOLLOW_LINKS).toFile();
} catch (IOException e) {
debug.log(Level.WARNING, e, e::toString);
// default to file path as is
this.path = new File(path).getAbsoluteFile();
}
}
public File get() {

View File

@ -59,7 +59,7 @@ public class SecureCompiledScript extends CompiledScript {
// write permissions for cache and temp folders
for (ApplicationFolder it : ApplicationFolder.values()) {
permissions.add(new FilePermission(it.get().getAbsolutePath() + File.separator + "-", "read, write, delete"));
permissions.add(new FilePermission(it.get() + File.separator + "-", "read, write, delete"));
}
return permissions;