소스 검색

Fix for HADOOP-112. All operations on local files are now performed
through a LocalFileSystem. In particular, listing the local
directory, which was causing this bug, when CRC files were included
in the listing. Now they are correctly excluded.


git-svn-id: https://svn.apache.org/repos/asf/lucene/hadoop/trunk@390218 13f79535-47bb-0310-9956-ffa450edef68

Doug Cutting 19 년 전
부모
커밋
ecf45fd810
1개의 변경된 파일10개의 추가작업 그리고 6개의 파일을 삭제
  1. 10 6
      src/java/org/apache/hadoop/dfs/DistributedFileSystem.java

+ 10 - 6
src/java/org/apache/hadoop/dfs/DistributedFileSystem.java

@@ -155,15 +155,17 @@ public class DistributedFileSystem extends FileSystem {
             }
         }
 
-        if (src.isDirectory()) {
+        FileSystem localFs = getNamed("local", getConf());
+
+        if (localFs.isDirectory(src)) {
             mkdirs(dst);
-            File contents[] = src.listFiles();
+            File contents[] = localFs.listFiles(src);
             for (int i = 0; i < contents.length; i++) {
                 doFromLocalFile(contents[i], new File(dst, contents[i].getName()), deleteSource);
             }
         } else {
             byte buf[] = new byte[getConf().getInt("io.file.buffer.size", 4096)];
-            InputStream in = new BufferedInputStream(new FileInputStream(src));
+            InputStream in = localFs.open(src);
             try {
                 OutputStream out = create(dst);
                 try {
@@ -180,7 +182,7 @@ public class DistributedFileSystem extends FileSystem {
             } 
         }
         if (deleteSource)
-            src.delete();
+            localFs.delete(src);
     }
 
     public void copyToLocalFile(File src, File dst) throws IOException {
@@ -196,8 +198,10 @@ public class DistributedFileSystem extends FileSystem {
         }
         dst = dst.getCanonicalFile();
 
+        FileSystem localFs = getNamed("local", getConf());
+
         if (isDirectory(src)) {
-            dst.mkdirs();
+            localFs.mkdirs(dst);
             File contents[] = listFiles(src);
             for (int i = 0; i < contents.length; i++) {
                 copyToLocalFile(contents[i], new File(dst, contents[i].getName()));
@@ -206,7 +210,7 @@ public class DistributedFileSystem extends FileSystem {
             byte buf[] = new byte[getConf().getInt("io.file.buffer.size", 4096)];
             InputStream in = open(src);
             try {
-                OutputStream out = FileSystem.getNamed("local", getConf()).create(dst);
+                OutputStream out = localFs.create(dst);
                 try {
                     int bytesRead = in.read(buf);
                     while (bytesRead >= 0) {