hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gif...@apache.org
Subject [20/20] hadoop git commit: HADOOP-15522. Deprecate Shell#ReadLink by using native java code. Contributed by Giovanni Matteo Fumarola.
Date Tue, 12 Jun 2018 20:07:24 GMT
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/23755a81
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/23755a81
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/23755a81

Branch: refs/heads/HADOOP-15461
Commit: 23755a813a763041a57ef7a6c6e7277d46b87960
Parents: eb3a0fe
Author: Inigo Goiri <inigoiri@apache.org>
Authored: Mon Jun 11 13:14:34 2018 -0700
Committer: Giovanni Matteo Fumarola <gifuma@apache.com>
Committed: Tue Jun 12 13:06:09 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/23755a81/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/23755a81/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 091299c..c0ba5d1 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


Mime
View raw message