Skip to content

Commit a60cdc2

Browse files
Babcock, ScottBabcock, Scott
authored andcommitted
Merge pull request #6 in MFATT/common from pr/fix-glob-bug to master
* commit '6e9b418bfd9ddc584ff7d66c8aeb2e20d688ced7': Add white space to reveal file creation step. Match paths with regex instead of glob to eliminate false matches
2 parents 02e69ab + 6e9b418 commit a60cdc2

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/main/java/com/nordstrom/common/file/PathUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public static Path getNextPath(Path targetPath, String baseName, String extensio
8080
throw new IllegalArgumentException("[extension] must specify a non-empty string");
8181
}
8282

83-
PathMatcher pathMatcher = FileSystems.getDefault().getPathMatcher("glob:" + baseName + "*." + extension);
83+
PathMatcher pathMatcher = FileSystems.getDefault().getPathMatcher("regex:" + baseName + "(-\\d+)?\\." + extension);
8484

8585
try (Stream<Path> stream = Files.walk(targetPath, 1)) {
8686
int ext = extension.length() + 1;

src/test/java/com/nordstrom/common/file/PathUtilsTest.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,15 @@ public void testNextPath() throws IOException {
3030
Files.createDirectories(targetPath);
3131
}
3232

33-
Path path1 = PathUtils.getNextPath(targetPath, "test", "txt");
34-
assertEquals(path1.getFileName().toString(), "test.txt");
33+
Path path1 = PathUtils.getNextPath(targetPath, "testNextPath", "txt");
34+
assertEquals(path1.getFileName().toString(), "testNextPath.txt");
3535

3636
path1.toFile().createNewFile();
37-
Path path2 = PathUtils.getNextPath(targetPath, "test", "txt");
38-
assertEquals(path2.getFileName().toString(), "test-2.txt");
37+
38+
Path path2 = PathUtils.getNextPath(targetPath, "testNextPath", "txt");
39+
assertEquals(path2.getFileName().toString(), "testNextPath-2.txt");
40+
Path path3 = PathUtils.getNextPath(targetPath, "test", "txt");
41+
assertEquals(path3.getFileName().toString(), "test.txt");
3942
}
4043

4144
private Path getOutputPath() {

0 commit comments

Comments
 (0)