From 7dc890057cc7f02df8f27ab988aa7055cbb3af65 Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Tue, 08 Jan 2013 15:19:28 -0500
Subject: [PATCH] Wrap pushlog update code with an exception handler, just-in-case
---
src/com/gitblit/utils/FileUtils.java | 37 +++++++++++++++++++++++++++----------
1 files changed, 27 insertions(+), 10 deletions(-)
diff --git a/src/com/gitblit/utils/FileUtils.java b/src/com/gitblit/utils/FileUtils.java
index cba88d0..0834867 100644
--- a/src/com/gitblit/utils/FileUtils.java
+++ b/src/com/gitblit/utils/FileUtils.java
@@ -99,6 +99,25 @@
}
return defaultValue;
}
+
+ /**
+ * Returns the byte [] content of the specified file.
+ *
+ * @param file
+ * @return the byte content of the file
+ */
+ public static byte [] readContent(File file) {
+ byte [] buffer = new byte[(int) file.length()];
+ try {
+ BufferedInputStream is = new BufferedInputStream(new FileInputStream(file));
+ is.read(buffer, 0, buffer.length);
+ is.close();
+ } catch (Throwable t) {
+ System.err.println("Failed to read byte content of " + file.getAbsolutePath());
+ t.printStackTrace();
+ }
+ return buffer;
+ }
/**
* Returns the string content of the specified file.
@@ -157,19 +176,17 @@
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 {
+ }
+ if (directory.isDirectory()) {
+ long length = 0;
+ for (File file : directory.listFiles()) {
length += folderSize(file);
}
+ return length;
+ } else if (directory.isFile()) {
+ return directory.length();
}
- return length;
+ return 0;
}
/**
--
Gitblit v1.9.1