From 26a52809da1b6795b95e02aa39947c3158a048df Mon Sep 17 00:00:00 2001 From: mszkb Date: Sat, 20 Jan 2018 15:13:46 +0100 Subject: [PATCH 1/3] make method to check if directory exists --- .../rarchives/ripme/ripper/AlbumRipper.java | 5 ++- .../java/com/rarchives/ripme/utils/Utils.java | 36 +++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/rarchives/ripme/ripper/AlbumRipper.java b/src/main/java/com/rarchives/ripme/ripper/AlbumRipper.java index a92f3870..124ef163 100644 --- a/src/main/java/com/rarchives/ripme/ripper/AlbumRipper.java +++ b/src/main/java/com/rarchives/ripme/ripper/AlbumRipper.java @@ -197,8 +197,11 @@ public abstract class AlbumRipper extends AbstractRipper { title = super.getAlbumTitle(this.url); } logger.debug("Using album title '" + title + "'"); + title = Utils.filesystemSafe(title); - path += title + File.separator; + path += title; + path = Utils.getOriginalDirectory(path) + File.separator; // check for case sensitive (unix only) + this.workingDir = new File(path); if (!this.workingDir.exists()) { logger.info("[+] Creating directory: " + Utils.removeCWD(this.workingDir)); diff --git a/src/main/java/com/rarchives/ripme/utils/Utils.java b/src/main/java/com/rarchives/ripme/utils/Utils.java index d9f8bf9e..61acc81f 100644 --- a/src/main/java/com/rarchives/ripme/utils/Utils.java +++ b/src/main/java/com/rarchives/ripme/utils/Utils.java @@ -370,6 +370,42 @@ public class Utils { return text; } + /** + * Checks if given path already exists as lowercase + * + * @param path - original path entered to be ripped + * @return path of existing folder or the original path if not present + */ + public static String getOriginalDirectory(String path) { + + int index; + if(isUnix() || isMacOS()) { + index = path.lastIndexOf('/'); + } else { + // current OS is windows - nothing to do here + return path; + } + + String original = path; // needs to be checked if lowercase exists + String lastPart = original.substring(index+1).toLowerCase(); // setting lowercase to check if it exists + String lowerCaseOriginal = path.substring(0, index) + + File.separator + + lastPart; + + if(original.equals(lowerCaseOriginal)) { + // same name, nothing to do + return original; + } + + // At last, check if the File with the original exists + File f = new File(original); + if(f.exists()) { + return original; + } else { + return lowerCaseOriginal; + } + } + public static String bytesToHumanReadable(int bytes) { float fbytes = (float) bytes; String[] mags = new String[] {"", "K", "M", "G", "T"}; From cec606c4f04e602f04538c8152e7969dab261825 Mon Sep 17 00:00:00 2001 From: mszkb Date: Sat, 20 Jan 2018 18:05:54 +0100 Subject: [PATCH 2/3] change file check --- src/main/java/com/rarchives/ripme/utils/Utils.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/rarchives/ripme/utils/Utils.java b/src/main/java/com/rarchives/ripme/utils/Utils.java index 61acc81f..6418a164 100644 --- a/src/main/java/com/rarchives/ripme/utils/Utils.java +++ b/src/main/java/com/rarchives/ripme/utils/Utils.java @@ -398,11 +398,11 @@ public class Utils { } // At last, check if the File with the original exists - File f = new File(original); + File f = new File(lowerCaseOriginal); if(f.exists()) { - return original; - } else { return lowerCaseOriginal; + } else { + return original; } } From d515ffd9b47d05d59d8b012494af211a8f29c0da Mon Sep 17 00:00:00 2001 From: mszkb Date: Sat, 20 Jan 2018 18:50:49 +0100 Subject: [PATCH 3/3] Checking directories and its lowercase names --- .../java/com/rarchives/ripme/utils/Utils.java | 30 ++++++++----------- 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/rarchives/ripme/utils/Utils.java b/src/main/java/com/rarchives/ripme/utils/Utils.java index 6418a164..9517c528 100644 --- a/src/main/java/com/rarchives/ripme/utils/Utils.java +++ b/src/main/java/com/rarchives/ripme/utils/Utils.java @@ -8,11 +8,7 @@ import java.lang.reflect.Constructor; import java.net.URISyntaxException; import java.net.URL; import java.net.URLDecoder; -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.jar.JarEntry; import java.util.jar.JarFile; @@ -388,22 +384,20 @@ public class Utils { String original = path; // needs to be checked if lowercase exists String lastPart = original.substring(index+1).toLowerCase(); // setting lowercase to check if it exists - String lowerCaseOriginal = path.substring(0, index) - + File.separator - + lastPart; - if(original.equals(lowerCaseOriginal)) { - // same name, nothing to do - return original; + // Get a List of all Directories and check its lowercase + // if file exists return it + File f = new File(path.substring(0, index)); + ArrayList names = new ArrayList(Arrays.asList(f.list())); + + for (String s : names) { + if(s.toLowerCase().equals(lastPart)) { + // Building Path of existing file + return path.substring(0, index) + File.separator + s; + } } - // At last, check if the File with the original exists - File f = new File(lowerCaseOriginal); - if(f.exists()) { - return lowerCaseOriginal; - } else { - return original; - } + return original; } public static String bytesToHumanReadable(int bytes) {