cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r808546 - /incubator/cassandra/trunk/src/java/org/apache/cassandra/utils/FileUtils.java
Date Thu, 27 Aug 2009 17:22:04 GMT
Author: jbellis
Date: Thu Aug 27 17:22:03 2009
New Revision: 808546

URL: http://svn.apache.org/viewvc?rev=808546&view=rev
Log:
fix getUsedDiskSpace to look at data directories recursively.  Patch by Sammy Yu; reviewed
by jbellis for CASSANDRA-394

Modified:
    incubator/cassandra/trunk/src/java/org/apache/cassandra/utils/FileUtils.java

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/utils/FileUtils.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/utils/FileUtils.java?rev=808546&r1=808545&r2=808546&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/utils/FileUtils.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/utils/FileUtils.java Thu Aug 27
17:22:03 2009
@@ -209,26 +209,42 @@
         return d;
     }
     
+    /**
+     * calculate the total space used by a file or directory
+     * 
+     * @param path the path
+     * @return total space used.
+     */
+    public static long getUsedDiskSpaceForPath(String path)
+    {
+        File file = new File(path);
+        
+        if (file.isFile()) 
+        {
+            return file.length();
+        }
+        
+        long diskSpace = 0;
+        for (File childFile: file.listFiles())
+        {
+            diskSpace += getUsedDiskSpaceForPath(childFile.getPath());
+        }
+        return diskSpace;
+    }
+    
     public static long getUsedDiskSpace()
     {
         long diskSpace = 0L;
         String[] directories = DatabaseDescriptor.getAllDataFileLocations();        
         for ( String directory : directories )
         {
-            File f = new File(directory);
-            File[] files = f.listFiles();
-            for ( File file : files )
-            {
-                diskSpace += file.length();
-            }
+            diskSpace += getUsedDiskSpaceForPath(directory);
         }
 
         String value = df_.format(diskSpace);
         return Long.parseLong(value);
     }    
     
-    
-	
     /**
      * Deletes all files and subdirectories under "dir".
      * @param dir Directory to be deleted



Mime
View raw message