From 79454823b30e428539b9ba25baa924419cb64a6c Mon Sep 17 00:00:00 2001 From: Connor Tumbleson Date: Tue, 15 Aug 2017 15:52:46 -0400 Subject: [PATCH] Refactor directory checks to prevent assumptions - only checks directory path of apktool framework location - fixes #1586 --- .../brut/androlib/res/AndrolibResources.java | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/AndrolibResources.java b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/AndrolibResources.java index daa6711f..da416668 100644 --- a/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/AndrolibResources.java +++ b/brut.apktool/apktool-lib/src/main/java/brut/androlib/res/AndrolibResources.java @@ -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);