This is an automated email from the ASF dual-hosted git repository. ctubbsii pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/accumulo.git
The following commit(s) were added to refs/heads/main by this push: new 19cbf45 Fix error mistaking volume for directory (#2046) 19cbf45 is described below commit 19cbf4596773b27de0a9267556efcf0b7f12fad3 Author: jjmar11 <80709086+jjma...@users.noreply.github.com> AuthorDate: Wed May 12 12:22:40 2021 -0400 Fix error mistaking volume for directory (#2046) --- .../java/org/apache/accumulo/server/fs/VolumeManager.java | 8 ++++++-- .../java/org/apache/accumulo/server/fs/FileTypeTest.java | 13 +++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/server/base/src/main/java/org/apache/accumulo/server/fs/VolumeManager.java b/server/base/src/main/java/org/apache/accumulo/server/fs/VolumeManager.java index fec7a00..c2ee6ee 100644 --- a/server/base/src/main/java/org/apache/accumulo/server/fs/VolumeManager.java +++ b/server/base/src/main/java/org/apache/accumulo/server/fs/VolumeManager.java @@ -62,15 +62,19 @@ public interface VolumeManager extends AutoCloseable { private static int endOfVolumeIndex(String path, String dir) { // Strip off the suffix that starts with the FileType (e.g. tables, wal, etc) - int dirIndex = path.indexOf('/' + dir); + int dirIndex = path.indexOf('/' + dir + '/'); + if (dirIndex != -1) { return dirIndex; } + if (path.endsWith('/' + dir)) { + return path.length() - (dir.length() + 1); + } + if (path.contains(":")) throw new IllegalArgumentException(path + " is absolute, but does not contain " + dir); return -1; - } public Path getVolume(Path path) { diff --git a/server/base/src/test/java/org/apache/accumulo/server/fs/FileTypeTest.java b/server/base/src/test/java/org/apache/accumulo/server/fs/FileTypeTest.java index a083d48..ed94f84 100644 --- a/server/base/src/test/java/org/apache/accumulo/server/fs/FileTypeTest.java +++ b/server/base/src/test/java/org/apache/accumulo/server/fs/FileTypeTest.java @@ -100,5 +100,18 @@ public class FileTypeTest { assertEquals(new Path("tables/2b/t-001/C00.rf"), FileType.TABLE.removeVolume(new Path("hdfs://nn1/a/tables/2b/t-001/C00.rf"))); + assertEquals(new Path("tables"), + FileType.TABLE.removeVolume(new Path("file:/a/accumulo/tables"))); + assertEquals(new Path("tables/"), + FileType.TABLE.removeVolume(new Path("file:/a/accumulo/tables/"))); + assertEquals(new Path("file:/a/accumulo"), + FileType.TABLE.getVolume(new Path("file:/a/accumulo/tables/"))); + assertEquals(null, FileType.TABLE.getVolume(new Path("/a/accumulo/tables2/"))); + assertEquals(new Path("tables/2b/t-001/C00.rf"), FileType.TABLE + .removeVolume(new Path("file:/a/accumulo/tablesstuff/tables/2b/t-001/C00.rf"))); + assertEquals(new Path("tables/tablestuff2"), + FileType.TABLE.removeVolume(new Path("file:/a/accumulo/tablesstuff/tables/tablestuff2"))); + assertEquals(new Path("tables/tables"), + FileType.TABLE.removeVolume(new Path("file:/a/accumulo/tablesstuff/tables/tables"))); } }