Skip to content

Commit

Permalink
Moved changes to convertToURI to separate PR
Browse files Browse the repository at this point in the history
  • Loading branch information
malhotrashivam committed May 15, 2024
1 parent cf4e8ff commit 8ded8be
Showing 1 changed file with 12 additions and 21 deletions.
33 changes: 12 additions & 21 deletions Base/src/main/java/io/deephaven/base/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public static void deleteRecursively(File file) {
/**
* Move files accepted by a filter from their relative path under source to the same relative path under
* destination. Creates missing destination subdirectories as needed.
*
*
* @param source Must be a directory.
* @param destination Must be a directory if it exists.
* @param filter Applied to normal files, only. We recurse on directories automatically.
Expand Down Expand Up @@ -129,7 +129,7 @@ private static void moveRecursivelyInternal(File source, File destination, FileF

/**
* Recursive delete method that copes with .nfs files. Uses the file's parent as the trash directory.
*
*
* @param file
*/
public static void deleteRecursivelyOnNFS(File file) {
Expand All @@ -138,7 +138,7 @@ public static void deleteRecursivelyOnNFS(File file) {

/**
* Recursive delete method that copes with .nfs files.
*
*
* @param trashFile Filename to move regular files to before deletion. .nfs files may be created in its parent
* directory.
* @param fileToBeDeleted File or directory at which to begin recursive deletion.
Expand Down Expand Up @@ -169,7 +169,7 @@ public static void deleteRecursivelyOnNFS(final File trashFile, final File fileT

/**
* Scan directory recursively to find all files
*
*
* @param dir
* @return
*/
Expand Down Expand Up @@ -282,30 +282,21 @@ public static URI convertToURI(final String source, final boolean isDirectory) {
URI uri;
try {
uri = new URI(source);
if (uri.getScheme() == null) {
// Convert to a "file" URI
return convertToURI(new File(source), isDirectory);
}
String path = uri.getPath();
boolean isUpdated = false;
// Directory URIs should end with a slash
if (isDirectory && path.charAt(path.length() - 1) != URI_SEPARATOR_CHAR) {
path = path + URI_SEPARATOR_CHAR;
isUpdated = true;
}
// Replace two or more consecutive slashes in the path with a single slash
final String path = uri.getPath();
if (path.contains(REPEATED_URI_SEPARATOR)) {
path = REPEATED_URI_SEPARATOR_PATTERN.matcher(path).replaceAll(URI_SEPARATOR);
isUpdated = true;
}
if (isUpdated) {
uri = new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), path, uri.getQuery(),
uri.getFragment());
final String canonicalizedPath = REPEATED_URI_SEPARATOR_PATTERN.matcher(path).replaceAll(URI_SEPARATOR);
uri = new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), canonicalizedPath,
uri.getQuery(), uri.getFragment());
}
} catch (final URISyntaxException e) {
// If the URI is invalid, assume it's a file path
return convertToURI(new File(source), isDirectory);
}
if (uri.getScheme() == null) {
// Convert to a "file" URI
return convertToURI(new File(source), isDirectory);
}
return uri;
}

Expand Down

0 comments on commit 8ded8be

Please sign in to comment.