From f76fee63ed9cb3a30d3c0c092d860b1cb93a481b Mon Sep 17 00:00:00 2001
From: Gerard Smyth <gerard.smyth@gmail.com>
Date: Thu, 08 May 2014 13:09:30 -0400
Subject: [PATCH] Updated the SyndicationServlet to provide an additional option to return details of the tags in the repository instead of the commits. This uses a new 'ot' request parameter to indicate the object type of the content to return, which can be ither TAG or COMMIT. If this is not provided, then COMMIT is assumed to maintain backwards compatability. If tags are returned, then the paging parameters, 'l' and 'pg' are still supported, but searching options are currently ignored.
---
src/main/java/com/gitblit/utils/FileUtils.java | 64 ++++++++++++++++++++++----------
1 files changed, 44 insertions(+), 20 deletions(-)
diff --git a/src/main/java/com/gitblit/utils/FileUtils.java b/src/main/java/com/gitblit/utils/FileUtils.java
index fb3e09c..a1eb5bb 100644
--- a/src/main/java/com/gitblit/utils/FileUtils.java
+++ b/src/main/java/com/gitblit/utils/FileUtils.java
@@ -29,12 +29,12 @@
/**
* Common file utilities.
- *
+ *
* @author James Moger
- *
+ *
*/
public class FileUtils {
-
+
/** 1024 (number of bytes in one kilobyte) */
public static final int KB = 1024;
@@ -47,7 +47,7 @@
/**
* Returns an int from a string representation of a file size.
* e.g. 50m = 50 megabytes
- *
+ *
* @param aString
* @param defaultValue
* @return an int value or the defaultValue if aString can not be parsed
@@ -55,24 +55,24 @@
public static int convertSizeToInt(String aString, int defaultValue) {
return (int) convertSizeToLong(aString, defaultValue);
}
-
+
/**
* Returns a long from a string representation of a file size.
* e.g. 50m = 50 megabytes
- *
+ *
* @param aString
* @param defaultValue
* @return a long value or the defaultValue if aString can not be parsed
*/
public static long convertSizeToLong(String aString, long defaultValue) {
- // trim string and remove all spaces
+ // trim string and remove all spaces
aString = aString.toLowerCase().trim();
StringBuilder sb = new StringBuilder();
for (String a : aString.split(" ")) {
sb.append(a);
}
aString = sb.toString();
-
+
// identify value and unit
int idx = 0;
int len = aString.length();
@@ -99,10 +99,10 @@
}
return defaultValue;
}
-
+
/**
* Returns the byte [] content of the specified file.
- *
+ *
* @param file
* @return the byte content of the file
*/
@@ -130,7 +130,7 @@
/**
* Returns the string content of the specified file.
- *
+ *
* @param file
* @param lineEnding
* @return the string content of the file
@@ -166,7 +166,7 @@
/**
* Writes the string content to the file.
- *
+ *
* @param file
* @param content
*/
@@ -195,14 +195,14 @@
/**
* 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.isDirectory()) {
long length = 0;
for (File file : directory.listFiles()) {
@@ -216,8 +216,32 @@
}
/**
+ * Delete a file or recursively delete a folder.
+ *
+ * @param fileOrFolder
+ * @return true, if successful
+ */
+ public static boolean delete(File fileOrFolder) {
+ boolean success = false;
+ if (fileOrFolder.isDirectory()) {
+ File [] files = fileOrFolder.listFiles();
+ if (files != null) {
+ for (File file : files) {
+ if (file.isDirectory()) {
+ success |= delete(file);
+ } else {
+ success |= file.delete();
+ }
+ }
+ }
+ }
+ success |= fileOrFolder.delete();
+ return success;
+ }
+
+ /**
* Copies a file or folder (recursively) to a destination folder.
- *
+ *
* @param destinationFolder
* @param filesOrFolders
* @return
@@ -257,11 +281,11 @@
}
}
}
-
+
/**
* Determine the relative path between two files. Takes into account
* canonical paths, if possible.
- *
+ *
* @param basePath
* @param path
* @return a relative path from basePath to path
@@ -285,11 +309,11 @@
// no relative relationship
return null;
}
-
+
/**
* Returns the exact path for a file. This path will be the canonical path
* unless an exception is thrown in which case it will be the absolute path.
- *
+ *
* @param path
* @return the exact file
*/
@@ -303,7 +327,7 @@
public static File resolveParameter(String parameter, File aFolder, String path) {
if (aFolder == null) {
- // strip any parameter reference
+ // strip any parameter reference
path = path.replace(parameter, "").trim();
if (path.length() > 0 && path.charAt(0) == '/') {
// strip leading /
--
Gitblit v1.9.1