From 63fc7d80b2513828e53d0ad2aba79618ba8168d5 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Sat, 21 Apr 2018 12:09:47 +0700 Subject: [PATCH] List files within /Volumes as media root (sandbox seems to give access to folder listings for that) --- source/net/filebot/platform/mac/DropToUnlock.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/source/net/filebot/platform/mac/DropToUnlock.java b/source/net/filebot/platform/mac/DropToUnlock.java index 5c8e5748..6b482847 100644 --- a/source/net/filebot/platform/mac/DropToUnlock.java +++ b/source/net/filebot/platform/mac/DropToUnlock.java @@ -98,12 +98,24 @@ public class DropToUnlock extends JList { } } + // NOTE: The app sandbox seems to allow read access to /Volumes by default + private static final File VOLUMES_FOLDER = new File("/Volumes"); + public static List getParentFolders(Collection files) { return files.stream().map(f -> f.isDirectory() ? f : f.getParentFile()).sorted().distinct().filter(f -> !f.exists() || isLockedFolder(f)).map(f -> { try { File file = f.getCanonicalFile(); File root = MediaDetection.getStructureRoot(file); + if (VOLUMES_FOLDER.equals(root)) { + List path = listPath(file); + + // i.e. [0] / [1] Volumes / [2] HDD + if (path.size() >= 3) { + return listPath(file).get(2); + } + } + // if structure root doesn't work just grab first existing parent folder if (root == null || root.getName().isEmpty() || root.getParentFile() == null || root.getParentFile().getName().isEmpty()) { for (File it : listPathTail(file, Integer.MAX_VALUE, true)) { @@ -114,6 +126,7 @@ public class DropToUnlock extends JList { } return root; } catch (Exception e) { + debug.log(Level.WARNING, e, e::toString); return null; } }).filter(f -> f != null && !f.getName().isEmpty() && isLockedFolder(f)).sorted().distinct().collect(Collectors.toList());