/** * Strips the bucket prefix or the preceding path separator from the path if it is present. For * example, for input path ufs://my-bucket-name/my-path/file, the output would be my-path/file. If * path is an absolute path like /my-path/file, the output would be my-path/file. This method will * leave keys without a prefix unaltered, ie. my-path/file returns my-path/file. * * @param path the path to strip * @return the path without the bucket prefix */ protected String stripPrefixIfPresent(String path) { String stripedKey = CommonUtils.stripPrefixIfPresent(path, PathUtils.normalizePath(getRootKey(), PATH_SEPARATOR)); if (!stripedKey.equals(path)) { return stripedKey; } return CommonUtils.stripPrefixIfPresent(path, PATH_SEPARATOR); } }
for (int i = 0; i < inputs.length; i++) { assertEquals(results[i], CommonUtils.stripPrefixIfPresent(inputs[i], prefixToStrip[i]));
@Test public void listLargeDirectory() throws IOException { LargeDirectoryConfig config = prepareLargeDirectoryTest(); String[] children = config.getChildren(); // Retry for some time to allow list operation eventual consistency for S3 and GCS. // See http://docs.aws.amazon.com/AmazonS3/latest/dev/Introduction.html and // https://cloud.google.com/storage/docs/consistency for more details. // Note: not using CommonUtils.waitFor here because we intend to sleep with a longer interval. UfsStatus[] results = new UfsStatus[] {}; for (int i = 0; i < 20; i++) { results = mUfs.listStatus(config.getTopLevelDirectory()); if (children.length == results.length) { break; } CommonUtils.sleepMs(500); } assertEquals(children.length, results.length); String[] resultNames = UfsStatus.convertToNames(results); Arrays.sort(resultNames); for (int i = 0; i < children.length; ++i) { assertTrue(resultNames[i].equals(CommonUtils.stripPrefixIfPresent(children[i], PathUtils.normalizePath(config.getTopLevelDirectory(), "/")))); } }
/** * Strips the bucket prefix or the preceding path separator from the path if it is present. For * example, for input path ufs://my-bucket-name/my-path/file, the output would be my-path/file. If * path is an absolute path like /my-path/file, the output would be my-path/file. This method will * leave keys without a prefix unaltered, ie. my-path/file returns my-path/file. * * @param path the path to strip * @return the path without the bucket prefix */ protected String stripPrefixIfPresent(String path) { String stripedKey = CommonUtils.stripPrefixIfPresent(path, PathUtils.normalizePath(getRootKey(), PATH_SEPARATOR)); if (!stripedKey.equals(path)) { return stripedKey; } return CommonUtils.stripPrefixIfPresent(path, PATH_SEPARATOR); } }