ctubbsii commented on code in PR #8307:
URL: https://github.com/apache/hadoop/pull/8307#discussion_r2908466339
##########
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/Path.java:
##########
@@ -361,6 +378,48 @@ public static boolean isWindowsAbsolutePath(final String
pathString,
*/
public URI toUri() { return uri; }
+ /**
+ * Return a URI for this path that is suitable for use as a directory base
+ * with {@link URI#resolve(String)}. The returned URI's path component
+ * ends with "/", so that {@code dirUri.resolve("child")} yields
+ * {@code .../dir/child} rather than replacing the last segment.
+ *
+ * @param uri a filesystem or path URI
+ * @return a URI with path ending in "/" (or "/" when path is empty)
+ */
+ public static URI ensureDirectoryUri(URI uri) {
Review Comment:
Does this need any API annotations? It seems to be a new public method in an
otherwise stable API. Is there a better non-public place for this utility
method? I'm asking because I'm genuinely not sure what Hadoop norms are for API
changes.
##########
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/Path.java:
##########
@@ -361,6 +378,48 @@ public static boolean isWindowsAbsolutePath(final String
pathString,
*/
public URI toUri() { return uri; }
+ /**
+ * Return a URI for this path that is suitable for use as a directory base
+ * with {@link URI#resolve(String)}. The returned URI's path component
+ * ends with "/", so that {@code dirUri.resolve("child")} yields
+ * {@code .../dir/child} rather than replacing the last segment.
+ *
+ * @param uri a filesystem or path URI
+ * @return a URI with path ending in "/" (or "/" when path is empty)
+ */
+ public static URI ensureDirectoryUri(URI uri) {
+ String path = uri.getPath();
+ if (path == null) {
+ path = "";
+ }
+ if (path.endsWith(SEPARATOR)) {
+ return uri;
+ }
+ if (path.isEmpty()) {
+ path = SEPARATOR;
+ } else {
+ path = path + SEPARATOR;
+ }
+ try {
+ return new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(),
+ uri.getPort(), path, uri.getQuery(), uri.getFragment());
+ } catch (URISyntaxException e) {
+ throw new IllegalArgumentException(e);
+ }
+ }
+
+ /**
+ * Return a Path equivalent to this path but whose URI has a trailing "/"
+ * on the path component. Use when this path denotes a directory and you
+ * need to resolve relative names via {@link URI#resolve(String)} (e.g.
+ * {@code getWorkingDirectory().asDirectory().toUri().resolve("mytempdir")}).
+ *
+ * @return a Path with the same location and a directory-style URI
+ */
+ public Path asDirectory() {
Review Comment:
Same question about API changes.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]