diff --git a/primitiveFTPd/src/org/primftpd/filesystem/FsFile.java b/primitiveFTPd/src/org/primftpd/filesystem/FsFile.java index 87b8779d..4ef5b5db 100644 --- a/primitiveFTPd/src/org/primftpd/filesystem/FsFile.java +++ b/primitiveFTPd/src/org/primftpd/filesystem/FsFile.java @@ -13,33 +13,39 @@ import java.io.OutputStream; import java.io.RandomAccessFile; import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; -import static java.util.Map.entry; public abstract class FsFile extends AbstractFile { protected final File file; protected final boolean injectedDirectory; - private final static Map DIRECTORY_INJECTIONS = Map.ofEntries( - // entry("/", new String[] {"dev", "etc", "mnt", "proc", "product", "storage", "system", "vendor"}), // comment out the line below if you enable this injection!!! - entry("/", new String[] {"storage"}), - entry("/storage/emulated", new String[] {"0"}) - ); + private final static Map DIRECTORY_INJECTIONS; + static { + Map tmp = new HashMap<>(); + // more known directories might be added + //tmp.put("/", new String[] {"dev", "etc", "mnt", "proc", "product", "storage", "system", "vendor"}); + tmp.put("/", new String[] {"storage"}); + tmp.put("/storage/emulated", new String[] {"0"}); + DIRECTORY_INJECTIONS = Collections.unmodifiableMap(tmp); + } - private final static Set CUSTOMIZED_DIRECTORIES; + private final static Set INJECTIONS_AND_CHILDREN; static { - CUSTOMIZED_DIRECTORIES = new HashSet(); + Set tmp = new HashSet<>(); for (Map.Entry entry : DIRECTORY_INJECTIONS.entrySet()) { String k = entry.getKey(); - CUSTOMIZED_DIRECTORIES.add(k); + tmp.add(k); for (String v : entry.getValue()) { - CUSTOMIZED_DIRECTORIES.add(k + File.separator + v); + tmp.add(k + File.separator + v); } } + INJECTIONS_AND_CHILDREN = Collections.unmodifiableSet(tmp); } public FsFile(File file, PftpdService pftpdService) { @@ -54,7 +60,7 @@ public FsFile(File file, PftpdService pftpdService) { pftpdService); this.file = file; this.name = file.getName(); - this.injectedDirectory = file.isDirectory() && CUSTOMIZED_DIRECTORIES.contains(file.getAbsolutePath()); + this.injectedDirectory = file.isDirectory() && INJECTIONS_AND_CHILDREN.contains(file.getAbsolutePath()); } protected abstract T createFile(File file, PftpdService pftpdService); @@ -167,7 +173,10 @@ public List listFiles() { logger.trace("[{}] listFiles()", name); postClientAction(ClientActionEvent.ClientAction.LIST_DIR); File[] filesArray = file.listFiles(); + + // if the OS did not provide child elements: if (filesArray == null) { + // check if requested file is among injected ones String[] folders = DIRECTORY_INJECTIONS.get(file.getAbsolutePath()); if (folders != null) { filesArray = new File[folders.length]; @@ -176,6 +185,7 @@ public List listFiles() { } } } + if (filesArray != null) { List files = new ArrayList<>(filesArray.length); for (File file : filesArray) {