Преглед на файлове

HADOOP-5085. Copying a file to local with Crc throws an exception. Contributed by Hairong Kuang.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/core/trunk@740157 13f79535-47bb-0310-9956-ffa450edef68
Hairong Kuang преди 16 години
родител
ревизия
cf4fa7b939
променени са 2 файла, в които са добавени 13 реда и са изтрити 1 реда
  1. 3 0
      CHANGES.txt
  2. 10 1
      src/core/org/apache/hadoop/fs/FsShell.java

+ 3 - 0
CHANGES.txt

@@ -677,6 +677,9 @@ Release 0.20.0 - Unreleased
     HADOOP-5139. Catch IllegalArgumentException during metrics registration 
     HADOOP-5139. Catch IllegalArgumentException during metrics registration 
     in RPC.  (Hairong Kuang via szetszwo)
     in RPC.  (Hairong Kuang via szetszwo)
 
 
+    HADOOP-5085. Copying a file to local with Crc throws an exception.
+    (hairong)
+
 Release 0.19.1 - Unreleased
 Release 0.19.1 - Unreleased
 
 
   IMPROVEMENTS
   IMPROVEMENTS

+ 10 - 1
src/core/org/apache/hadoop/fs/FsShell.java

@@ -168,7 +168,7 @@ public class FsShell extends Configured implements Tool {
       System.err.println("Usage: java FsShell " + GET_SHORT_USAGE);
       System.err.println("Usage: java FsShell " + GET_SHORT_USAGE);
       throw iae;
       throw iae;
     }
     }
-    final boolean copyCrc = cf.getOpt("crc");
+    boolean copyCrc = cf.getOpt("crc");
     final boolean verifyChecksum = !cf.getOpt("ignoreCrc");
     final boolean verifyChecksum = !cf.getOpt("ignoreCrc");
 
 
     if (dststr.equals("-")) {
     if (dststr.equals("-")) {
@@ -180,6 +180,11 @@ public class FsShell extends Configured implements Tool {
       File dst = new File(dststr);      
       File dst = new File(dststr);      
       Path srcpath = new Path(srcstr);
       Path srcpath = new Path(srcstr);
       FileSystem srcFS = getSrcFileSystem(srcpath, verifyChecksum);
       FileSystem srcFS = getSrcFileSystem(srcpath, verifyChecksum);
+      if (copyCrc && !(srcFS instanceof ChecksumFileSystem)) {
+        System.err.println("-crc option is not valid when source file system " +
+            "does not have crc files. Automatically turn the option off.");
+        copyCrc = false;
+      }
       FileStatus[] srcs = srcFS.globStatus(srcpath);
       FileStatus[] srcs = srcFS.globStatus(srcpath);
       boolean dstIsDir = dst.isDirectory(); 
       boolean dstIsDir = dst.isDirectory(); 
       if (srcs.length > 1 && !dstIsDir) {
       if (srcs.length > 1 && !dstIsDir) {
@@ -249,6 +254,10 @@ public class FsShell extends Configured implements Tool {
       }
       }
 
 
       if (copyCrc) {
       if (copyCrc) {
+        if (!(srcFS instanceof ChecksumFileSystem)) {
+          throw new IOException("Source file system does not have crc files");
+        }
+        
         ChecksumFileSystem csfs = (ChecksumFileSystem) srcFS;
         ChecksumFileSystem csfs = (ChecksumFileSystem) srcFS;
         File dstcs = FileSystem.getLocal(srcFS.getConf())
         File dstcs = FileSystem.getLocal(srcFS.getConf())
           .pathToFile(csfs.getChecksumFile(new Path(dst.getCanonicalPath())));
           .pathToFile(csfs.getChecksumFile(new Path(dst.getCanonicalPath())));