This is an automated email from the ASF dual-hosted git repository.

dongjoon pushed a commit to branch branch-1.7
in repository https://gitbox.apache.org/repos/asf/orc.git


The following commit(s) were added to refs/heads/branch-1.7 by this push:
     new 163e6e2  ORC-1035: Fix the way to get the backupDataPath in 
recoverFile (#945)
163e6e2 is described below

commit 163e6e2b25f69a484a1db641bf0e93bc80a433b7
Author: Guiyanakaung <[email protected]>
AuthorDate: Sun Oct 24 11:54:47 2021 +0800

    ORC-1035: Fix the way to get the backupDataPath in recoverFile (#945)
    
    ### What changes were proposed in this pull request?
    
    This pr aims to fix the way to get the backupDataPath.
    ```java
          public static final String DEFAULT_BACKUP_PATH = 
System.getProperty("java.io.tmpdir");
          ......
          String scheme = corruptPath.toUri().getScheme();
          String authority = corruptPath.toUri().getAuthority();
          String filePath = corruptPath.toUri().getPath();
          if (backup.equals(DEFAULT_BACKUP_PATH)) {
            backupDataPath = new Path(scheme, authority, DEFAULT_BACKUP_PATH + 
filePath);
          } else {
            backupDataPath = Path.mergePaths(new Path(backup), corruptPath);
          }
    ```
    
    1.  System.getProperty("java.io.tmpdir") gets a path that may or may not 
end in Path.SEPARATOR, as seen in the [Travis ci 
](https://app.travis-ci.com/github/apache/orc/jobs/544381649#L1580) example, 
the path generated directly by DEFAULT_BACKUP_PATH + filePath may not be 
correct.
    
    2. corruptPath is the path entered by the user, which may be absolute or 
relative. The second argument of Path.mergePaths is expected to be a path 
starting with Path.SEPARATOR, so when the user enters a relative path, 
Path.mergePaths(new Path(backup), corruptPath) the result is also incorrect.
    
    example  `Path.mergePaths(new Path("/a/b/c/"), new 
Path("d")).toUri().getPath()`
    result:  `/a/b/cd`
    
    ### Why are the changes needed?
    
    Fix bug, otherwise backup files will fail.
    
    ### How was this patch tested?
    
    Pass the CIs.
    
    (cherry picked from commit 59192339fa6e120c5ae59cb706f1178985077852)
    Signed-off-by: Dongjoon Hyun <[email protected]>
---
 java/tools/src/java/org/apache/orc/tools/FileDump.java | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/java/tools/src/java/org/apache/orc/tools/FileDump.java 
b/java/tools/src/java/org/apache/orc/tools/FileDump.java
index bfc6e79..0257c23 100644
--- a/java/tools/src/java/org/apache/orc/tools/FileDump.java
+++ b/java/tools/src/java/org/apache/orc/tools/FileDump.java
@@ -567,17 +567,26 @@ public final class FileDump {
     // validate the recovered file once again and start moving corrupt files 
to backup folder
     if (isReadable(recoveredPath, conf, Long.MAX_VALUE)) {
       Path backupDataPath;
+      Path backupDirPath;
+      Path relativeCorruptPath;
       String scheme = corruptPath.toUri().getScheme();
       String authority = corruptPath.toUri().getAuthority();
-      String filePath = corruptPath.toUri().getPath();
 
       // use the same filesystem as corrupt file if backup-path is not 
explicitly specified
       if (backup.equals(DEFAULT_BACKUP_PATH)) {
-        backupDataPath = new Path(scheme, authority, DEFAULT_BACKUP_PATH + 
filePath);
+        backupDirPath = new Path(scheme, authority, DEFAULT_BACKUP_PATH);
       } else {
-        backupDataPath = Path.mergePaths(new Path(backup), corruptPath);
+        backupDirPath = new Path(backup);
       }
 
+      if (corruptPath.isUriPathAbsolute()) {
+        relativeCorruptPath = corruptPath;
+      } else {
+        relativeCorruptPath = Path.mergePaths(new Path(Path.SEPARATOR), 
corruptPath);
+      }
+
+      backupDataPath = Path.mergePaths(backupDirPath, relativeCorruptPath);
+
       // Move data file to backup path
       moveFiles(fs, corruptPath, backupDataPath);
 

Reply via email to