borgbutler-core/src/main/java/de/micromata/borgbutler/cache/ArchiveFilelistCache.java
@@ -129,7 +129,7 @@ log.error("Error while reading file list '" + file.getAbsolutePath() + "': " + ex.getMessage(), ex); } log.info("Loading done."); return list; return filter.reduce(list); } /** borgbutler-core/src/main/java/de/micromata/borgbutler/cache/ButlerCache.java
@@ -254,7 +254,7 @@ if (items == null && forceLoad) { log.warn("Repo::archiv with name '" + archive.getBorgIdentifier() + "' not found."); } return items; return filter.reduce(items); } public List<BorgFilesystemItem> getArchiveContent(File file) { borgbutler-core/src/main/java/de/micromata/borgbutler/data/FileSystemFilter.java
@@ -9,9 +9,16 @@ import java.util.List; public class FileSystemFilter { public enum Mode {FLAT, TREE} @Getter private String searchString; @Getter private Mode mode; @Getter @Setter private String currentDirectory; @Getter @Setter private int maxResultSize = -1; /** @@ -68,6 +75,53 @@ } /** * After processing a list by using {@link #matches(BorgFilesystemItem)} you should call finally this method with * your result list to reduce the files and directories for mode {@link Mode#TREE}. For the mode {@link Mode#FLAT} * nothing is done. * @param list * @return The original list for mode {@link Mode#FLAT} or the reduced list for the tree view. */ public List reduce(List<BorgFilesystemItem> list) { if (mode == FileSystemFilter.Mode.TREE) { List<BorgFilesystemItem> list2 = list; list = new ArrayList<>(); for (BorgFilesystemItem item : list2) { if (matchesDirectoryView(item)) { list.add(item); } } } return list; } /** * After processing all files with {@link #matches(BorgFilesystemItem)} you should process the file list again * through this filter (for tree view) for displaying only the sub items of the current directory (not recursive). * * @return */ private boolean matchesDirectoryView(BorgFilesystemItem item) { if (mode != Mode.TREE) { return true; } String path = item.getPath(); if (StringUtils.isEmpty(currentDirectory)) { // root dir return path.indexOf('/') == -1; // Show only top level items. } if (!path.startsWith(currentDirectory)) { // item is not a child of currentDirectory. return false; } if (path.length() <= currentDirectory.length() + 1) { // Don't show the current directory itself. return false; } String subPath = path.substring(currentDirectory.length()); return subPath.indexOf('/') < 0; } /** * @param searchString The search string. If this string contains several key words separated by white chars, * all key words must be found. * @return this for chaining. @@ -102,6 +156,19 @@ return this; } /** * @param mode * @return this for chaining. */ public FileSystemFilter setMode(String mode) { if (mode != null && mode.toLowerCase().equals("tree")) { this.mode = Mode.TREE; } else { this.mode = Mode.FLAT; } return this; } private void processFinishedFlag() { if (maxResultSize > 0 && ++counter >= maxResultSize) { this.finished = true; borgbutler-server/src/main/java/de/micromata/borgbutler/server/rest/ArchivesRest.java
@@ -56,21 +56,28 @@ /** * * @param archiveId Id or name of archive. * @param forceLoad If false (default), non cached file lists will not be loaded by borg. * @param searchString The string to search for (key words separated by white chars, trailing ! char represents exclude). * @param mode Flat (default) or tree. * @param currentDirectory The current displayed directory (only files and directories contained will be returned). * @param maxResultSize maximum number of file items to return (default is 50). * @param force If false (default), non cached file lists will not be loaded by borg. * @param prettyPrinter If true then the json output will be in pretty format. * @return Repository (including list of archives) as json string. * @see JsonUtils#toJson(Object, boolean) */ public String getArchiveFileLIst(@QueryParam("archiveId") String archiveId, @QueryParam("searchString") String searchString, @QueryParam("mode") String mode, @QueryParam("currentDirectory") String currentDirectory, @QueryParam("maxResultSize") String maxResultSize, @QueryParam("force") boolean force, @QueryParam("prettyPrinter") boolean prettyPrinter) { int maxSize = NumberUtils.toInt(maxResultSize, 50); FileSystemFilter filter = new FileSystemFilter() .setSearchString(searchString) .setMaxResultSize(maxSize); .setMaxResultSize(maxSize) .setMode(mode) .setCurrentDirectory(currentDirectory); List<BorgFilesystemItem> items = ButlerCache.getInstance().getArchiveContent(archiveId, force, filter); if (items == null) {