@@ -1081,6 +1081,7 @@ public Response execute(String protocol, String... argument) {
1081
1081
* Custom {@link WinBase.SECURITY_ATTRIBUTES} is required here to "get" Medium Integrity Level.
1082
1082
* In order to allow Medium Integrity Level clients to open
1083
1083
* and use a NamedPipe created by an High Integrity Level process.
1084
+ *
1084
1085
* @return A security attributes object that gives everyone read and write access.
1085
1086
*/
1086
1087
private WinBase .SECURITY_ATTRIBUTES createSecurityAttributesToAllowMediumIntegrity () {
@@ -2064,7 +2065,7 @@ public interface Dispatcher {
2064
2065
/**
2065
2066
* Changes the ownership of a file. Can be called only if this process is owned by root.
2066
2067
*
2067
- * @param file The path of the file to change ownership of.
2068
+ * @param file The path of the file to change ownership of.
2068
2069
* @param userId The user that should own the file.
2069
2070
*/
2070
2071
void chownFileToUser (File file , long userId );
@@ -2079,6 +2080,9 @@ class ForJnaPosixEnvironment implements Dispatcher {
2079
2080
*/
2080
2081
private final PosixLibrary library ;
2081
2082
2083
+ /**
2084
+ * The posix owner to use.
2085
+ */
2082
2086
private final PosixOwner posixOwner ;
2083
2087
2084
2088
/**
@@ -2187,21 +2191,17 @@ private void notifySemaphore(File directory, String name, int count, short opera
2187
2191
PosixLibrary .SemaphoreOperation target = new PosixLibrary .SemaphoreOperation ();
2188
2192
target .operation = operation ;
2189
2193
target .flags = flags ;
2190
- try {
2191
- while (count -- > 0 ) {
2192
- try {
2193
- library .semop (semaphore , target , 1 );
2194
- } catch (LastErrorException exception ) {
2195
- if (acceptUnavailable && (Native .getLastError () == PosixLibrary .EAGAIN
2196
- || Native .getLastError () == PosixLibrary .EDEADLK )) {
2197
- break ;
2198
- } else {
2199
- throw exception ;
2200
- }
2194
+ while (count -- > 0 ) {
2195
+ try {
2196
+ library .semop (semaphore , target , 1 );
2197
+ } catch (LastErrorException exception ) {
2198
+ if (acceptUnavailable && (Native .getLastError () == PosixLibrary .EAGAIN
2199
+ || Native .getLastError () == PosixLibrary .EDEADLK )) {
2200
+ break ;
2201
+ } else {
2202
+ throw exception ;
2201
2203
}
2202
2204
}
2203
- } finally {
2204
- target = null ;
2205
2205
}
2206
2206
}
2207
2207
@@ -2346,7 +2346,11 @@ protected List<String> getFieldOrder() {
2346
2346
}
2347
2347
}
2348
2348
2349
+ /**
2350
+ * Represents a system that supports posix.
2351
+ */
2349
2352
protected interface PosixOwner {
2353
+
2350
2354
/**
2351
2355
* Returns the user id of the owner of the supplied file.
2352
2356
*
@@ -2355,6 +2359,9 @@ protected interface PosixOwner {
2355
2359
*/
2356
2360
int getOwnerIdOf (File file );
2357
2361
2362
+ /**
2363
+ * An implementation of a posix owner for Linux.
2364
+ */
2358
2365
class ForLinuxEnvironment implements PosixOwner {
2359
2366
2360
2367
/**
@@ -2386,12 +2393,8 @@ public ForLinuxEnvironment(int attempts, long pause, TimeUnit timeUnit) {
2386
2393
}
2387
2394
2388
2395
/**
2389
- * Returns the user id of the owner of the supplied file.
2390
- *
2391
- * @param file The file for which to locate the owner.
2392
- * @return The owner id of the supplied file.
2396
+ * {@inheritDoc}
2393
2397
*/
2394
- @ Override
2395
2398
public int getOwnerIdOf (File file ) {
2396
2399
try {
2397
2400
// The binding for 'stat' is very platform dependant. To avoid the complexity of binding the correct method,
@@ -2430,8 +2433,16 @@ public int getOwnerIdOf(File file) {
2430
2433
}
2431
2434
}
2432
2435
2436
+ /**
2437
+ * An implementation for a posix owner that represents AIX.
2438
+ */
2433
2439
class ForAixEnvironment implements PosixOwner {
2434
2440
2441
+ /**
2442
+ * A pattern to represent the owner on the console output.
2443
+ */
2444
+ private static final Pattern AIX_OWNER_PATTERN = Pattern .compile ("Owner: (\\ d+)\\ (" );
2445
+
2435
2446
/**
2436
2447
* The maximum amount of attempts for checking the result of a foreign process.
2437
2448
*/
@@ -2460,15 +2471,9 @@ public ForAixEnvironment(int attempts, long pause, TimeUnit timeUnit) {
2460
2471
this .timeUnit = timeUnit ;
2461
2472
}
2462
2473
2463
- private static final Pattern AIX_OWNER_PATTERN = Pattern .compile ("Owner: (\\ d+)\\ (" );
2464
-
2465
2474
/**
2466
- * Returns the user id of the owner of the supplied file.
2467
- *
2468
- * @param file The file for which to locate the owner.
2469
- * @return The owner id of the supplied file.
2475
+ * {@inheritDoc}
2470
2476
*/
2471
- @ Override
2472
2477
public int getOwnerIdOf (File file ) {
2473
2478
try {
2474
2479
Process process = Runtime .getRuntime ().exec (new String []{"istat" , file .getAbsolutePath ()});
@@ -2501,7 +2506,6 @@ public int getOwnerIdOf(File file) {
2501
2506
throw new IllegalStateException ("Command for istat did not exit in time" );
2502
2507
}
2503
2508
Matcher matcher = AIX_OWNER_PATTERN .matcher (output .toString ());
2504
- // Find and print the Owner UID
2505
2509
if (matcher .find ()) {
2506
2510
return Integer .parseInt (matcher .group (1 ));
2507
2511
} else {
@@ -2513,6 +2517,9 @@ public int getOwnerIdOf(File file) {
2513
2517
}
2514
2518
}
2515
2519
2520
+ /**
2521
+ * An implementation for a posix owner that represents MacOS.
2522
+ */
2516
2523
class ForMacEnvironment implements PosixOwner {
2517
2524
2518
2525
/**
@@ -2544,18 +2551,14 @@ public ForMacEnvironment(int attempts, long pause, TimeUnit timeUnit) {
2544
2551
}
2545
2552
2546
2553
/**
2547
- * Returns the user id of the owner of the supplied file.
2548
- *
2549
- * @param file The file for which to locate the owner.
2550
- * @return The owner id of the supplied file.
2554
+ * {@inheritDoc}
2551
2555
*/
2552
- @ Override
2553
2556
public int getOwnerIdOf (File file ) {
2554
2557
try {
2555
2558
// The binding for 'stat' is very platform dependant. To avoid the complexity of binding the correct method,
2556
2559
// stat is called as a separate command. This is less efficient but more portable.
2557
2560
Process process = Runtime .getRuntime ().exec (new String []{"stat" ,
2558
- "-f" ,
2561
+ "-f" ,
2559
2562
"%u" ,
2560
2563
file .getAbsolutePath ()});
2561
2564
int attempts = this .attempts ;
0 commit comments