Refactor directory checks to prevent assumptions

- only checks directory path of apktool framework location
 - fixes #1586
This commit is contained in:
Connor Tumbleson 2017-08-15 15:52:46 -04:00
parent f9c091f54b
commit 79454823b3
1 changed files with 16 additions and 8 deletions

View File

@ -730,14 +730,6 @@ final public class AndrolibResources {
path = apkOptions.frameworkFolderLocation;
} else {
File parentPath = new File(System.getProperty("user.home"));
if (! parentPath.canWrite()) {
LOGGER.severe(String.format("WARNING: Could not write to $HOME (%s), using %s instead...",
parentPath.getAbsolutePath(), System.getProperty("java.io.tmpdir")));
LOGGER.severe("Please be aware this is a volatile directory and frameworks could go missing, " +
"please utilize --frame-path if the default storage directory is unavailable");
parentPath = new File(System.getProperty("java.io.tmpdir"));
}
if (OSDetection.isMacOSX()) {
path = parentPath.getAbsolutePath() + String.format("%1$sLibrary%1$sapktool%1$sframework", File.separatorChar);
@ -746,10 +738,26 @@ final public class AndrolibResources {
} else {
path = parentPath.getAbsolutePath() + String.format("%1$s.local%1$sshare%1$sapktool%1$sframework", File.separatorChar);
}
File fullPath = new File(path);
if (! fullPath.canWrite()) {
LOGGER.severe(String.format("WARNING: Could not write to (%1$s), using %2$s instead...",
fullPath.getAbsolutePath(), System.getProperty("java.io.tmpdir")));
LOGGER.severe("Please be aware this is a volatile directory and frameworks could go missing, " +
"please utilize --frame-path if the default storage directory is unavailable");
path = new File(System.getProperty("java.io.tmpdir")).getAbsolutePath();
}
}
File dir = new File(path);
if (!dir.isDirectory()) {
LOGGER.severe("--frame-path is set to a file, not a directory.");
System.exit(1);
}
if (dir.getParentFile() != null && dir.getParentFile().isFile()) {
LOGGER.severe("Please remove file at " + dir.getParentFile());
System.exit(1);