Browse Source

Add best-effort variant of File.getCanonicalFile()

See https://git.eclipse.org/r/#/c/58405/.

Change-Id: I097c4b1369754f59137eb8848a680c61b06510ad
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
stable-4.2
Thomas Wolf 9 years ago committed by Andrey Loskutov
parent
commit
d9e9015a00
  1. 25
      org.eclipse.jgit/src/org/eclipse/jgit/util/FileUtils.java

25
org.eclipse.jgit/src/org/eclipse/jgit/util/FileUtils.java

@ -735,4 +735,29 @@ public class FileUtils {
}
return name;
}
/**
* Best-effort variation of {@link File#getCanonicalFile()} returning the
* input file if the file cannot be canonicalized instead of throwing
* {@link IOException}.
*
* @param file
* to be canonicalized; may be {@code null}
* @return canonicalized file, or the unchanged input file if
* canonicalization failed or if {@code file == null}
* @throws SecurityException
* if {@link File#getCanonicalFile()} throws one
* @since 4.2
*/
public static File canonicalize(File file) {
if (file == null) {
return null;
}
try {
return file.getCanonicalFile();
} catch (IOException e) {
return file;
}
}
}

Loading…
Cancel
Save