Skip to content

Commit 1dee253

Browse files
committed
Add JavaDoc.
1 parent 3a067e5 commit 1dee253

File tree

2 files changed

+107
-28
lines changed

2 files changed

+107
-28
lines changed

src/main/java/com/gitblit/utils/JGitUtils.java

+20-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ public static Repository createRepository(File repositoriesFolder, String name)
266266

267267
/**
268268
* Creates a bare, shared repository.
269-
*
269+
*
270270
* @param repositoriesFolder
271271
* @param name
272272
* @param shared
@@ -372,13 +372,32 @@ boolean isShared() {
372372
}
373373

374374

375+
/**
376+
* Adjust file permissions of a file/directory for shared repositories
377+
*
378+
* @param path
379+
* File that should get its permissions changed.
380+
* @param configShared
381+
* Configuration string value for the shared mode.
382+
* @return Upon successful completion, a value of 0 is returned. Otherwise, a value of -1 is returned.
383+
*/
375384
public static int adjustSharedPerm(File path, String configShared) {
376385
return adjustSharedPerm(path, new GitConfigSharedRepository(configShared));
377386
}
378387

379388

389+
/**
390+
* Adjust file permissions of a file/directory for shared repositories
391+
*
392+
* @param path
393+
* File that should get its permissions changed.
394+
* @param configShared
395+
* Configuration setting for the shared mode.
396+
* @return Upon successful completion, a value of 0 is returned. Otherwise, a value of -1 is returned.
397+
*/
380398
public static int adjustSharedPerm(File path, GitConfigSharedRepository configShared) {
381399
if (! configShared.isShared()) return 0;
400+
if (! path.exists()) return -1;
382401

383402
int perm = configShared.getPerm();
384403
int mode = JnaUtils.getFilemode(path);

src/main/java/com/gitblit/utils/JnaUtils.java

+87-27
Original file line numberDiff line numberDiff line change
@@ -34,38 +34,43 @@
3434
* @author Florian Zschocke
3535
*/
3636
public class JnaUtils {
37-
public static final int S_IFMT = 0170000;
38-
public static final int S_IFIFO = 0010000;
39-
public static final int S_IFCHR = 0020000;
40-
public static final int S_IFDIR = 0040000;
41-
public static final int S_IFBLK = 0060000;
42-
public static final int S_IFREG = 0100000;
43-
public static final int S_IFLNK = 0120000;
44-
public static final int S_IFSOCK = 0140000;
45-
46-
public static final int S_ISUID = 0004000;
47-
public static final int S_ISGID = 0002000;
48-
public static final int S_ISVTX = 0001000;
49-
50-
public static final int S_IRWXU = 0000700;
51-
public static final int S_IRUSR = 0000400;
52-
public static final int S_IWUSR = 0000200;
53-
public static final int S_IXUSR = 0000100;
54-
public static final int S_IRWXG = 0000070;
55-
public static final int S_IRGRP = 0000040;
56-
public static final int S_IWGRP = 0000020;
57-
public static final int S_IXGRP = 0000010;
58-
public static final int S_IRWXO = 0000007;
59-
public static final int S_IROTH = 0000004;
60-
public static final int S_IWOTH = 0000002;
61-
public static final int S_IXOTH = 0000001;
37+
public static final int S_ISUID = 0004000; // set user id on execution
38+
public static final int S_ISGID = 0002000; // set group id on execution
39+
public static final int S_ISVTX = 0001000; // sticky bit, save swapped text even after use
40+
41+
public static final int S_IRWXU = 0000700; // RWX mask for owner
42+
public static final int S_IRUSR = 0000400; // read permission for owner
43+
public static final int S_IWUSR = 0000200; // write permission for owner
44+
public static final int S_IXUSR = 0000100; // execute/search permission for owner
45+
public static final int S_IRWXG = 0000070; // RWX mask for group
46+
public static final int S_IRGRP = 0000040; // read permission for group
47+
public static final int S_IWGRP = 0000020; // write permission for group
48+
public static final int S_IXGRP = 0000010; // execute/search permission for group
49+
public static final int S_IRWXO = 0000007; // RWX mask for other
50+
public static final int S_IROTH = 0000004; // read permission for other
51+
public static final int S_IWOTH = 0000002; // write permission for other
52+
public static final int S_IXOTH = 0000001; // execute/search permission for other
53+
54+
public static final int S_IFMT = 0170000; // type of file mask
55+
public static final int S_IFIFO = 0010000; // named pipe (fifo)
56+
public static final int S_IFCHR = 0020000; // character special device
57+
public static final int S_IFDIR = 0040000; // directory
58+
public static final int S_IFBLK = 0060000; // block special device
59+
public static final int S_IFREG = 0100000; // regular file
60+
public static final int S_IFLNK = 0120000; // symbolic link
61+
public static final int S_IFSOCK = 0140000; // socket
6262

6363

6464
private static final Logger LOGGER = LoggerFactory.getLogger(JGitUtils.class);
6565

6666
private static UnixCLibrary unixlibc = null;
6767

6868

69+
/**
70+
* Utility method to check if the JVM is running on a Windows OS.
71+
*
72+
* @return true, if the system property 'os.name' starts with 'Windows'.
73+
*/
6974
public static boolean isWindows()
7075
{
7176
return System.getProperty("os.name").toLowerCase().startsWith("windows");
@@ -77,11 +82,37 @@ private interface UnixCLibrary extends Library {
7782
}
7883

7984

80-
public static int setFilemode(File path, int mode)
85+
/**
86+
* Set the permission bits of a file.
87+
*
88+
* The permission bits are set to the provided mode. This method is only
89+
* implemented for OSes of the Unix family and makes use of the 'chmod'
90+
* function of the native C library. See 'man 2 chmod' for more information.
91+
*
92+
* @param path
93+
* File/directory to set the permission bits for.
94+
* @param mode
95+
* A mode created from or'd permission bit masks S_I*
96+
* @return Upon successful completion, a value of 0 returned. Otherwise, a value of -1 is returned.
97+
*/
98+
public static int setFilemode(File file, int mode)
8199
{
82-
return setFilemode(path.getAbsolutePath(), mode);
100+
return setFilemode(file.getAbsolutePath(), mode);
83101
}
84102

103+
/**
104+
* Set the permission bits of a file.
105+
*
106+
* The permission bits are set to the provided mode. This method is only
107+
* implemented for OSes of the Unix family and makes use of the 'chmod'
108+
* function of the native C library. See 'man 2 chmod' for more information.
109+
*
110+
* @param path
111+
* Path to a file/directory to set the permission bits for.
112+
* @param mode
113+
* A mode created from or'd permission bit masks S_I*
114+
* @return Upon successful completion, a value of 0 returned. Otherwise, a value of -1 is returned.
115+
*/
85116
public static int setFilemode(String path, int mode)
86117
{
87118
if (isWindows()) {
@@ -93,11 +124,33 @@ public static int setFilemode(String path, int mode)
93124

94125

95126

127+
/**
128+
* Get the file mode bits of a file.
129+
*
130+
* This method is only implemented for OSes of the Unix family. It returns the file mode
131+
* information as available in the st_mode member of the resulting struct stat when calling
132+
* 'lstat' on a file.
133+
*
134+
* @param path
135+
* File/directory to get the file mode from.
136+
* @return Upon successful completion, the file mode bits are returned. Otherwise, a value of -1 is returned.
137+
*/
96138
public static int getFilemode(File path)
97139
{
98140
return getFilemode(path.getAbsolutePath());
99141
}
100142

143+
/**
144+
* Get the file mode bits of a file.
145+
*
146+
* This method is only implemented for OSes of the Unix family. It returns the file mode
147+
* information as available in the st_mode member of the resulting struct stat when calling
148+
* 'lstat' on a file.
149+
*
150+
* @param path
151+
* Path to a file/directory to get the file mode from.
152+
* @return Upon successful completion, the file mode bits are returned. Otherwise, a value of -1 is returned.
153+
*/
101154
public static int getFilemode(String path)
102155
{
103156
if (isWindows()) {
@@ -178,6 +231,13 @@ public static int getFilemode(String path)
178231
}
179232

180233

234+
/**
235+
* Run the unix command 'ls -ldO' on a single file and return the resulting output line.
236+
*
237+
* @param path
238+
* Path to a single file or directory.
239+
* @return The first line of output from the 'ls' command. Null, if an error occurred and no line could be read.
240+
*/
181241
private static String runProcessLs(String path)
182242
{
183243
String cmd = "ls -ldO " + path;

0 commit comments

Comments
 (0)