Skip to content

Commit 9f08e39

Browse files
committed
Fixing fileWorkspaceMap listing test
1 parent 843ce07 commit 9f08e39

3 files changed

Lines changed: 73 additions & 29 deletions

File tree

src/main/java/picoded/dstack/core/Core_FileWorkspaceMap.java

Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package picoded.dstack.core;
22

33
import picoded.core.conv.ArrayConv;
4+
import picoded.core.conv.ConvertJSON;
45
import picoded.core.file.FileUtil;
56

67
// Java imports
@@ -559,12 +560,26 @@ protected Set<String> backend_filterPathSet(final Set<String> rawSet, final Stri
559560
}
560561
int searchPathLen = searchPath.length();
561562

563+
// // Debugging stuff
564+
// System.out.println( "#" );
565+
// System.out.println( "searchPath: "+searchPath );
566+
// System.out.println( "searchPathLen: "+searchPathLen );
567+
// System.out.println( "minDepth: "+minDepth );
568+
// System.out.println( "maxDepth: "+maxDepth );
569+
// System.out.println( "pathType: "+pathType );
570+
// System.out.println( ConvertJSON.fromObject(rawSet) );
571+
562572
// Return set
563573
Set<String> ret = new HashSet<>();
564574

565575
// Get the keyset, and iterate it
566576
for (String key : rawSet) {
567577

578+
// Skip the root folder of a workspace
579+
if( key.equals("") || key.equals("/") ) {
580+
continue;
581+
}
582+
568583
// If folder does not match - skip
569584
if (searchPathLen > 0 && !key.startsWith(searchPath)) {
570585
continue;
@@ -575,32 +590,36 @@ protected Set<String> backend_filterPathSet(final Set<String> rawSet, final Stri
575590

576591
// No filtering is needed, store and continue
577592
if (maxDepth <= 0 && minDepth <= 0) {
578-
// Does nothing
579-
} else {
580-
// Lets perform path filtering
581-
582-
// Lets filter out the ending "/"
583-
String filteredSubPath = subPath;
584-
if (filteredSubPath.endsWith("/")) {
585-
filteredSubPath = filteredSubPath.substring(0, filteredSubPath.length());
586-
}
587-
588-
// Split and count
589-
String[] splitSubPath = filteredSubPath.split("/");
590-
int subPathLength = (filteredSubPath.length() <= 0) ? 0 : splitSubPath.length;
591-
592-
// Check min depth - skip key if check failed
593-
if (subPathLength < minDepth) {
594-
continue;
595-
}
596-
597-
// Check max depth - skip key if check failed
598-
if (subPathLength > maxDepth) {
599-
continue;
600-
}
593+
// Does no checks, add and continue
594+
ret.add(subPath);
595+
continue;
596+
}
597+
598+
// Lets perform path filtering
599+
// ---
600+
601+
// Lets filter out the ending "/"
602+
String filteredSubPath = subPath;
603+
if (filteredSubPath.endsWith("/")) {
604+
filteredSubPath = filteredSubPath.substring(0, filteredSubPath.length() - 1);
605+
}
606+
607+
// Split and count
608+
String[] splitSubPath = filteredSubPath.split("/");
609+
int subPathLength = (filteredSubPath.length() <= 0) ? 0 : splitSubPath.length;
610+
611+
// Check min depth - skip key if check failed
612+
if (minDepth > 0 && subPathLength < minDepth) {
613+
continue;
614+
}
615+
616+
// Check max depth - skip key if check failed
617+
if (maxDepth > 0 && subPathLength > maxDepth) {
618+
continue;
601619
}
602620

603621
// Alrighto - lets check file / folder type - and add it in
622+
// ---
604623

605624
// Ignore empty, or root path
606625
if (subPath.isEmpty() || subPath.equals("/")) {
@@ -627,6 +646,10 @@ protected Set<String> backend_filterPathSet(final Set<String> rawSet, final Stri
627646
ret.add(subPath);
628647
}
629648

649+
// // Debugging stuff
650+
// System.out.println( "Filtered Set" );
651+
// System.out.println( ConvertJSON.fromObject(ret) );
652+
630653
// Return the filtered set
631654
return ret;
632655
}

src/main/java/picoded/dstack/mongodb/MongoDB_FileWorkspaceMap.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,8 @@ public Set<String> backend_getFileAndFolderPathSet(final String oid, String fold
877877
String[] cleanPathArr = cleanPath.split("/");
878878
List<String> cleanPathList = Arrays.asList(cleanPathArr);
879879

880-
// Lets handle parent folders, note that i<cleanPathArr.length, alread excludes the file itself
880+
// Lets handle parent folders, note that i<cleanPathArr.length,
881+
// already excludes the file itself
881882
for (int i = 1; i < cleanPathArr.length; ++i) {
882883
ret.add(String.join("/", cleanPathList.subList(0, i)) + "/");
883884
}

src/test/java/picoded/dstack/struct/simple/StructSimple_FileWorkspaceMap_test.java

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -346,17 +346,37 @@ public void getPathSetLookup() {
346346
fileWorkspace.writeString("test/one.txt", "anything");
347347
fileWorkspace.writeString("test/two.txt", "anything");
348348
fileWorkspace.writeString("test/d1/file.txt", "anything");
349-
fileWorkspace.writeString("test/d2/file.txt", "anything");
349+
fileWorkspace.writeString("test/d2/file1.txt", "anything");
350+
fileWorkspace.writeString("test/d2/file2.txt", "anything");
350351

351352
// List all files and folders
352-
assertEquals(4, fileWorkspace.getFileAndFolderPathSet(null).size());
353-
assertEquals(4, fileWorkspace.getFileAndFolderPathSet("").size());
354-
assertEquals(4, fileWorkspace.getFileAndFolderPathSet("/").size());
353+
// this includes, 5 files, and 3 folders (test/, test/d1/, test/d2/)
354+
assertEquals(8, fileWorkspace.getFileAndFolderPathSet(null, -1, -1).size());
355+
assertEquals(8, fileWorkspace.getFileAndFolderPathSet("", -1, -1).size());
356+
assertEquals(8, fileWorkspace.getFileAndFolderPathSet("/", -1, -1).size());
355357

356-
// List files in sub folders
358+
assertEquals(3, fileWorkspace.getFolderPathSet("", -1, -1).size());
359+
assertEquals(5, fileWorkspace.getFilePathSet("", -1, -1).size());
360+
361+
// List the `test/` folder
362+
assertEquals(1, fileWorkspace.getFileAndFolderPathSet(null).size());
363+
assertEquals(1, fileWorkspace.getFileAndFolderPathSet("").size());
364+
assertEquals(1, fileWorkspace.getFileAndFolderPathSet("/").size());
365+
assertEquals(1, fileWorkspace.getFolderPathSet("").size());
366+
367+
// The `test/` is not a file, hence 0
368+
assertEquals(0, fileWorkspace.getFilePathSet("").size());
369+
370+
// List files & folders in the `test/` sub folders
357371
assertEquals(4, fileWorkspace.getFileAndFolderPathSet("test").size());
358372
assertEquals(2, fileWorkspace.getFilePathSet("test").size());
359373
assertEquals(2, fileWorkspace.getFolderPathSet("test").size());
374+
375+
// List files & folders in the `test/d2/` sub folders
376+
assertEquals(2, fileWorkspace.getFileAndFolderPathSet("test/d2/").size());
377+
assertEquals(2, fileWorkspace.getFilePathSet("test/d2/").size());
378+
assertEquals(0, fileWorkspace.getFolderPathSet("test/d2/").size());
379+
360380
}
361381

362382
//-----------------------------------------------------------------------------------

0 commit comments

Comments
 (0)