From 8b5730a0e32d5707b6ac6df5fb0906b7981853eb Mon Sep 17 00:00:00 2001
From: Florian Zschocke <florian.zschocke@cycos.com>
Date: Mon, 26 Aug 2013 06:39:57 -0400
Subject: [PATCH] Fix setting wrrong custom mode on file and in config.

---
 src/main/java/com/gitblit/utils/JGitUtils.java |   28 +++++++++++++++++++++++++---
 1 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/src/main/java/com/gitblit/utils/JGitUtils.java b/src/main/java/com/gitblit/utils/JGitUtils.java
index 49b3ad7..66dbd60 100644
--- a/src/main/java/com/gitblit/utils/JGitUtils.java
+++ b/src/main/java/com/gitblit/utils/JGitUtils.java
@@ -266,7 +266,7 @@
 
 	/**
 	 * Creates a bare, shared repository.
-	 * 
+	 *
 	 * @param repositoriesFolder
 	 * @param name
 	 * @param shared
@@ -353,7 +353,10 @@
 		}
 
 		String getValue() {
-			if ( enumValue == GitConfigSharedRepositoryValue.Oxxx ) return Integer.toOctalString(intValue);
+			if ( enumValue == GitConfigSharedRepositoryValue.Oxxx ) {
+				if (intValue == 0) return "0";
+				return String.format("0%o", intValue);
+			}
 			return enumValue.getConfigValue();
 		}
 
@@ -372,13 +375,32 @@
 	}
 
 
+	/**
+	 * Adjust file permissions of a file/directory for shared repositories
+	 *
+	 * @param path
+	 * 			File that should get its permissions changed.
+	 * @param configShared
+	 * 			Configuration string value for the shared mode.
+	 * @return Upon successful completion, a value of 0 is returned. Otherwise, a value of -1 is returned.
+	 */
 	public static int adjustSharedPerm(File path, String configShared) {
 		return adjustSharedPerm(path, new GitConfigSharedRepository(configShared));
 	}
 
 
+	/**
+	 * Adjust file permissions of a file/directory for shared repositories
+	 *
+	 * @param path
+	 * 			File that should get its permissions changed.
+	 * @param configShared
+	 * 			Configuration setting for the shared mode.
+	 * @return Upon successful completion, a value of 0 is returned. Otherwise, a value of -1 is returned.
+	 */
 	public static int adjustSharedPerm(File path, GitConfigSharedRepository configShared) {
 		if (! configShared.isShared()) return 0;
+		if (! path.exists()) return -1;
 
 		int perm = configShared.getPerm();
 		int mode = JnaUtils.getFilemode(path);
@@ -391,7 +413,7 @@
 
 		if (configShared.isCustom()) {
 			// Use the custom value for access permissions.
-			mode |= (mode & ~0777) | perm;
+			mode = (mode & ~0777) | perm;
 		}
 		else {
 			// Just add necessary bits to existing permissions.

--
Gitblit v1.9.1