You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by in...@apache.org on 2018/07/25 01:32:32 UTC
[49/50] hadoop git commit: HADOOP-15522. Deprecate Shell#ReadLink by
using native java code. Contributed by Giovanni Matteo Fumarola.
HADOOP-15522. Deprecate Shell#ReadLink by using native java code. Contributed by Giovanni Matteo Fumarola.
Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/866646eb
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/866646eb
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/866646eb
Branch: refs/heads/HADOOP-15461
Commit: 866646eb3bf15d101574d000c41915206e8db713
Parents: b8d2b09
Author: Inigo Goiri <in...@apache.org>
Authored: Mon Jun 11 13:14:34 2018 -0700
Committer: Inigo Goiri <in...@apache.org>
Committed: Tue Jul 24 18:30:47 2018 -0700
----------------------------------------------------------------------
.../java/org/apache/hadoop/fs/FileUtil.java | 21 +++++++++++---------
.../main/java/org/apache/hadoop/util/Shell.java | 8 +++++++-
2 files changed, 19 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hadoop/blob/866646eb/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileUtil.java
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileUtil.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileUtil.java
index 61cb8d2..f3b5d58 100644
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileUtil.java
+++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileUtil.java
@@ -196,22 +196,25 @@ public class FileUtil {
* a symlink.
*/
public static String readLink(File f) {
- /* NB: Use readSymbolicLink in java.nio.file.Path once available. Could
- * use getCanonicalPath in File to get the target of the symlink but that
- * does not indicate if the given path refers to a symlink.
- */
if (f == null) {
LOG.warn("Can not read a null symLink");
return "";
}
- try {
- return Shell.execCommand(
- Shell.getReadlinkCommand(f.toString())).trim();
- } catch (IOException x) {
- return "";
+ if (Files.isSymbolicLink(f.toPath())) {
+ java.nio.file.Path p = null;
+ try {
+ p = Files.readSymbolicLink(f.toPath());
+ } catch (Exception e) {
+ LOG.warn("Exception while reading the symbolic link "
+ + f.getAbsolutePath() + ". Exception= " + e.getMessage());
+ return "";
+ }
+ return p.toAbsolutePath().toString();
}
+ LOG.warn("The file " + f.getAbsolutePath() + " is not a symbolic link.");
+ return "";
}
/*
http://git-wip-us.apache.org/repos/asf/hadoop/blob/866646eb/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/Shell.java
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/Shell.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/Shell.java
index e902af0..691df63 100644
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/Shell.java
+++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/Shell.java
@@ -309,7 +309,13 @@ public abstract class Shell {
: new String[] { "ln", "-s", target, link };
}
- /** Return a command to read the target of the a symbolic link. */
+ /**
+ * Return a command to read the target of the a symbolic link.
+ *
+ * Deprecated and likely to be deleted in the near future. Please use
+ * FileUtil.symlink().
+ */
+ @Deprecated
public static String[] getReadlinkCommand(String link) {
return WINDOWS ?
new String[] { getWinUtilsPath(), "readlink", link }
---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org