From 331fbc638684c605d90d49269202dde071db10c4 Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Wed, 20 Jul 2011 16:03:07 -0400
Subject: [PATCH] Cancel buttons on edit pages. Column fix for flat repositories view.

---
 src/com/gitblit/utils/FileUtils.java |   26 +++++++++++++++++++++++++-
 1 files changed, 25 insertions(+), 1 deletions(-)

diff --git a/src/com/gitblit/utils/FileUtils.java b/src/com/gitblit/utils/FileUtils.java
index 3cfe689..ce8cdf9 100644
--- a/src/com/gitblit/utils/FileUtils.java
+++ b/src/com/gitblit/utils/FileUtils.java
@@ -34,7 +34,7 @@
 	 * 
 	 * @param file
 	 * @param lineEnding
-	 * @return
+	 * @return the string content of the file
 	 */
 	public static String readContent(File file, String lineEnding) {
 		StringBuilder sb = new StringBuilder();
@@ -56,4 +56,28 @@
 		}
 		return sb.toString();
 	}
+
+	/**
+	 * Recursively traverses a folder and its subfolders to calculate the total
+	 * size in bytes.
+	 * 
+	 * @param directory
+	 * @return folder size in bytes
+	 */
+	public static long folderSize(File directory) {
+		if (directory == null || !directory.exists()) {
+			return -1;
+		}
+		if (directory.isFile()) {
+			return directory.length();
+		}
+		long length = 0;
+		for (File file : directory.listFiles()) {
+			if (file.isFile())
+				length += file.length();
+			else
+				length += folderSize(file);
+		}
+		return length;
+	}
 }

--
Gitblit v1.9.1