Github user gallenvara commented on a diff in the pull request:
https://github.com/apache/flink/pull/1035#discussion_r37610286
--- Diff: flink-core/src/main/java/org/apache/flink/core/fs/Path.java ---
@@ -430,40 +296,127 @@ public int depth() {
}
/**
- * Returns a qualified path object.
- *
- * @param fs
- * the FileSystem that should be used to obtain the current
working directory
- * @return the qualified path object
+ * Checks if the provided path string is either null or has zero length
and throws
+ * a {@link IllegalArgumentException} if any of the two conditions
apply.
+ * In addition, leading and tailing whitespaces are removed.
+ *
+ * @param path
+ * the path string to be checked
+ * @return The checked and trimmed path.
+ */
+ private String checkAndTrimPathArg(String path) {
+ // disallow construction of a Path from an empty string
+ if (path == null) {
+ throw new IllegalArgumentException("Can not create a
Path from a null string");
+ }
+ path = path.trim();
+ if (path.length() == 0) {
+ throw new IllegalArgumentException("Can not create a
Path from an empty string");
+ }
+ return path;
+ }
+
+ /**
+ * Initializes a path object given the scheme, authority and path
string.
+ *
+ * @param scheme
+ * the scheme string.
+ * @param authority
+ * the authority string.
+ * @param path
+ * the path string.
*/
- public Path makeQualified(FileSystem fs) {
- Path path = this;
- if (!isAbsolute()) {
- path = new Path(fs.getWorkingDirectory(), this);
+ private void initialize(String scheme, String authority, String path) {
+ try {
+ this.uri = new URI(scheme, authority,
normalizePath(path), null, null).normalize();
+ } catch (URISyntaxException e) {
+ throw new IllegalArgumentException(e);
}
+ }
- final URI pathUri = path.toUri();
- final URI fsUri = fs.getUri();
+ /**
+ * Normalizes a path string.
+ *
+ * @param path
+ * the path string to normalize
+ * @return the normalized path string
+ */
+ private String normalizePath(String path) {
- String scheme = pathUri.getScheme();
- String authority = pathUri.getAuthority();
+ // remove leading and tailing whitespaces
+ path = path.trim();
- if (scheme != null && (authority != null ||
fsUri.getAuthority() == null)) {
- return path;
+ // remove consecutive slashes & backslashes
+ path = path.replace("\\", "/");
+ path = path.replaceAll("/+", "/");
--- End diff --
Hi, @tillrohrmann thanks for your review. But i haven't modified this line.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---