Jason Boss wrote:

Doug and Andrzej,

What do I need to do to get my local system working?  Can I use the new
version or do I still need to wait for a revised patch?

Pls wait - Mike C. was doing some changes concurrently, and we need to resolve our versions. In the meantime you can use the attached patches.
--
Best regards,
Andrzej Bialecki


-------------------------------------------------
Software Architect, System Integration Specialist
CEN/ISSS EC Workshop, ECIMF project chair
EU FP6 E-Commerce Expert/Evaluator
-------------------------------------------------
FreeBSD developer (http://www.freebsd.org)

Index: LocalFileSystem.java
===================================================================
RCS file: /cvsroot/nutch/nutch/src/java/net/nutch/util/LocalFileSystem.java,v
retrieving revision 1.3
diff -d -u -r1.3 LocalFileSystem.java
--- LocalFileSystem.java        4 Oct 2004 15:42:58 -0000       1.3
+++ LocalFileSystem.java        4 Oct 2004 19:43:11 -0000
@@ -7,6 +7,10 @@
 import java.util.*;
 import java.nio.channels.*;
 
+import net.nutch.fs.NDFSFile;
+import net.nutch.fs.NDFSFileInfo;
+import net.nutch.io.UTF8;
+
 /****************************************************************
  * Implement the NutchFileSystem interface for the local disk.
  * This is pretty easy.  The interface exists so we can use either
@@ -18,11 +22,19 @@
     TreeMap sharedLockDataSet = new TreeMap();
     TreeMap nonsharedLockDataSet = new TreeMap();
     TreeMap lockObjSet = new TreeMap();
+    // by default use copy/delete instead of rename
+    boolean useCopyForRename = true;
 
     /**
      */
     public LocalFileSystem() throws IOException {
         super();
+        // if you find an OS which reliably supports non-POSIX
+        // rename(2) across filesystems / volumes, you can
+        // uncomment this.
+        // String os = System.getProperty("os.name");
+        // if (os.toLowerCase().indexOf("os-with-super-rename") != -1)
+        //     useCopyForRename = false;
     }
 
     /*******************************************************
@@ -212,14 +224,19 @@
      * Rename files/dirs
      */
     public boolean rename(File src, File dst) throws IOException {
-        return src.renameTo(dst);
+        if (useCopyForRename) {
+            FileUtil.copyContents(this, src, dst, true);
+            return fullyDelete(src);
+        } else return src.renameTo(dst);
     }
 
     /**
      * Get rid of File f, whether a true file or dir.
      */
     public boolean delete(File f) throws IOException {
-        return f.delete();
+        if (f.isFile()) {
+            return f.delete();
+        } else return fullyDelete(f);
     }
 
     /**
@@ -243,7 +260,16 @@
     /**
      */
     public File[] listFiles(File f) throws IOException {
-        return f.listFiles();
+        File[] files = f.listFiles();
+        if (files == null) return null;
+        NDFSFile[] nfiles = new NDFSFile[files.length];
+        for (int i = 0; i < files.length; i++) {
+            long len = files[i].length();
+            UTF8 name = new UTF8(files[i].toString());
+            NDFSFileInfo info = new NDFSFileInfo(name, len, len, 
files[i].isDirectory());
+            nfiles[i] = new NDFSFile(info);
+        }
+        return nfiles;
     }
 
     /**
@@ -302,7 +328,10 @@
      */
     public void addLocalFile(File src, File dst) throws IOException {
         if (! src.equals(dst)) {
-            src.renameTo(dst);
+            if (useCopyForRename) {
+                FileUtil.copyContents(this, src, dst, true);
+                fullyDelete(src);
+            } else src.renameTo(dst);
         }
     }
 
@@ -360,4 +389,29 @@
     public String toString() {
         return "LocalFS";
     }
+    
+    /**
+     * Implement our own version instead of using FileUtil, to avoid
+     * infinite loop.
+     * @param dir
+     * @return
+     * @throws IOException
+     */
+    private boolean fullyDelete(File dir) throws IOException {
+        File contents[] = dir.listFiles();
+        if (contents != null) {
+            for (int i = 0; i < contents.length; i++) {
+                if (contents[i].isFile()) {
+                    if (! contents[i].delete()) {
+                        return false;
+                    }
+                } else {
+                    if (! fullyDelete(contents[i])) {
+                        return false;
+                    }
+                }
+            }
+        }
+        return dir.delete();
+    }
 }

Reply via email to