Skip to content

Commit

Permalink
fix getUsedDiskSpace to look at data directories recursively. Patch b…
Browse files Browse the repository at this point in the history
…y Sammy Yu; reviewed by jbellis for CASSANDRA-394

git-svn-id: https://svn.apache.org/repos/asf/incubator/cassandra/trunk@808546 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
jbellis committed Aug 27, 2009
1 parent 866b06e commit ba88f55
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions src/java/org/apache/cassandra/utils/FileUtils.java
Expand Up @@ -209,26 +209,42 @@ else if ( peices[1].equals("KB") )
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
Expand Down

0 comments on commit ba88f55

Please sign in to comment.