Index: /Users/schmed/Projects/Krugle/hadoop/src/java/org/apache/hadoop/dfs/DFSShell.java
===================================================================
--- /Users/schmed/Projects/Krugle/hadoop/src/java/org/apache/hadoop/dfs/DFSShell.java	(revision 2610)
+++ /Users/schmed/Projects/Krugle/hadoop/src/java/org/apache/hadoop/dfs/DFSShell.java	(working copy)
@@ -16,6 +16,8 @@
 package org.apache.hadoop.dfs;
 
 import java.io.*;
+import java.text.SimpleDateFormat;
+import java.util.Date;
 
 import org.apache.hadoop.conf.*;
 import org.apache.hadoop.fs.*;
@@ -29,6 +31,7 @@
 public class DFSShell extends ToolBase {
 
     FileSystem fs;
+    String trashFolderName;
 
     /**
      */
@@ -37,6 +40,8 @@
 
     public void init() throws IOException {
         this.fs = FileSystem.get(conf);
+        // 2006-08-29 CSc Protect the world from my dangerous fingers!
+        this.trashFolderName = conf.get("dfs.trash.folder.name", "trash");
     }
     /**
      * Add a local file to the indicated name in DFS. src is kept.
@@ -224,15 +229,91 @@
       FileUtil.copy(fs, new Path(srcf), fs, new Path(dstf), false, conf);
     }
 
+    // 2006-08-29 CSc Protect the world from my dangerous fingers!
     /**
-     * Delete an DFS file
+     * Move the target file/folder into the trash folder, appending a timestamp.
      */
-    public void delete(String srcf) throws IOException {
-        if (fs.delete(new Path(srcf))) {
-            System.out.println("Deleted " + srcf);
-        } else {
-            System.out.println("Delete failed");
+    public void moveToTrash(String srcf) throws IOException {
+      Path srcPath = new Path(srcf);
+      if (!fs.exists(srcPath)) {
+        System.out.println(srcf + " does not exist.");
+        return;
+      }
+      long srcSize = getSize(srcPath);
+            
+      Path trashPath = new Path(trashFolderName);
+      SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
+      fs.mkdirs(trashPath);
+      fs.rename(srcPath,
+                new Path( trashPath,
+                          srcPath.getName() + "." + sdf.format(new Date())));
+
+      long trashSize = getSize(trashPath);
+      System.out.println( "Moved "
+                        + byteDesc(srcSize)
+                        + " "
+                        + srcf
+                        + " to trash, which now totals "
+                        + byteDesc(trashSize)
+                        + ".");
+    }
+    
+    /**
+     * Return the disk usage in bytes of <code>srcPath</code>.
+     * @param srcPath file/folder to check disk usage of
+     * @throws IOException
+     */
+    private long getSize(Path srcPath) throws IOException {
+      Path items[] = fs.listPaths(srcPath);
+      
+      if (items == null) {
+        throw (new IOException(srcPath.toString() + " does not exist"));
+      }
+      long srcSize = 0;
+      for (int i = 0; i < items.length; i++) {
+        DfsPath cur = (DfsPath) items[i];
+        srcSize += cur.getContentsLength();
+      }
+      return(srcSize);
+    }
+
+    /**
+     * Empty the trash, after confirming request with the user
+     */
+    public void emptyTrash() throws IOException {
+      Path trashPath = new Path(trashFolderName);
+      Path items[] = fs.listPaths(trashPath);
+      
+      if ((items == null) || (items.length == 0)) {
+        System.out.println("Trash already empty.");
+        return;
+      }
+      
+      BufferedReader console = new BufferedReader(new InputStreamReader(System.in));
+      boolean abort = true;
+      System.out.println( "Are you sure you want to permanently remove all items from trash ("
+                        + byteDesc(getSize(trashPath))
+                        + "), y or n?");
+      try {
+        if (console.readLine().trim().toLowerCase().startsWith("y")) {
+          abort = false;
         }
+      } catch (IOException e) {
+      }
+      if (abort) {
+        System.out.println("Not emptying trash.");
+      } else {
+        for (int i = 0; i < items.length; i++) {
+          DfsPath cur = (DfsPath) items[i];
+          System.out.println( "Removing "
+                            + items[i].toString()
+                            + " ("
+                            + byteDesc(cur.getContentsLength())
+                            + ").");
+          fs.delete(cur);
+        }
+        System.out.println("Trash is now empty.");
+      }
     }
 
     /**
@@ -298,7 +379,7 @@
         if (argv.length < 1) {
             System.out.println("Usage: java DFSShell [-fs <local | namenode:port>]"+
                     " [-conf <configuration file>] [-D <[property=value>]"+
-                    " [-ls <path>] [-lsr <path>] [-du <path>] [-mv <src> <dst>] [-cp <src> <dst>] [-rm <src>]" +
+                    " [-ls <path>] [-lsr <path>] [-du <path>] [-mv <src> <dst>] [-cp <src> <dst>] [-rm <src>] [-emptyTrash <src>]" +
                     " [-put <localsrc> <dst>] [-copyFromLocal <localsrc> <dst>] [-moveFromLocal <localsrc> <dst>]" + 
                     " [-get <src> <localdst>] [-cat <src>] [-copyToLocal <src> <localdst>] [-moveToLocal <src> <localdst>]" +
                     " [-mkdir <path>] [-report] [-setrep [-R] <rep> <path/file>]");
@@ -334,8 +415,13 @@
                 rename(argv[i++], argv[i++]);
             } else if ("-cp".equals(cmd)) {
                 copy(argv[i++], argv[i++], conf);
+            
+            // 2006-08-29 CSc Protect the world from my dangerous fingers!
             } else if ("-rm".equals(cmd)) {
-                delete(argv[i++]);
+              moveToTrash(argv[i++]);
+            } else if ("-emptyTrash".equals(cmd)) {
+              emptyTrash();
+              
             } else if ("-du".equals(cmd)) {
                 String arg = i < argv.length ? argv[i++] : "";
                 du(arg);
