From b1dba764c201f4708b82767b2d91edb6e189ce6f Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Fri, 22 Jul 2011 10:09:18 -0400
Subject: [PATCH] Fixed (again) empty repository check (issue 13)

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

diff --git a/src/com/gitblit/utils/FileUtils.java b/src/com/gitblit/utils/FileUtils.java
index 468b2a8..310e35a 100644
--- a/src/com/gitblit/utils/FileUtils.java
+++ b/src/com/gitblit/utils/FileUtils.java
@@ -56,4 +56,29 @@
 		}
 		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