Skip to content

Commit

Permalink
Standardize documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
raphw committed Jul 8, 2024
1 parent da3cee9 commit ceabf1d
Showing 1 changed file with 36 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 1081,7 @@ public Response execute(String protocol, String... argument) {
* Custom {@link WinBase.SECURITY_ATTRIBUTES} is required here to "get" Medium Integrity Level.
* In order to allow Medium Integrity Level clients to open
* and use a NamedPipe created by an High Integrity Level process.
*
* @return A security attributes object that gives everyone read and write access.
*/
private WinBase.SECURITY_ATTRIBUTES createSecurityAttributesToAllowMediumIntegrity() {
Expand Down Expand Up @@ -2064,7 2065,7 @@ public interface Dispatcher {
/**
* Changes the ownership of a file. Can be called only if this process is owned by root.
*
* @param file The path of the file to change ownership of.
* @param file The path of the file to change ownership of.
* @param userId The user that should own the file.
*/
void chownFileToUser(File file, long userId);
Expand All @@ -2079,6 2080,9 @@ class ForJnaPosixEnvironment implements Dispatcher {
*/
private final PosixLibrary library;

/**
* The posix owner to use.
*/
private final PosixOwner posixOwner;

/**
Expand Down Expand Up @@ -2187,21 2191,17 @@ private void notifySemaphore(File directory, String name, int count, short opera
PosixLibrary.SemaphoreOperation target = new PosixLibrary.SemaphoreOperation();
target.operation = operation;
target.flags = flags;
try {
while (count-- > 0) {
try {
library.semop(semaphore, target, 1);
} catch (LastErrorException exception) {
if (acceptUnavailable && (Native.getLastError() == PosixLibrary.EAGAIN
|| Native.getLastError() == PosixLibrary.EDEADLK)) {
break;
} else {
throw exception;
}
while (count-- > 0) {
try {
library.semop(semaphore, target, 1);
} catch (LastErrorException exception) {
if (acceptUnavailable && (Native.getLastError() == PosixLibrary.EAGAIN
|| Native.getLastError() == PosixLibrary.EDEADLK)) {
break;
} else {
throw exception;
}
}
} finally {
target = null;
}
}

Expand Down Expand Up @@ -2346,7 2346,11 @@ protected List<String> getFieldOrder() {
}
}

/**
* Represents a system that supports posix.
*/
protected interface PosixOwner {

/**
* Returns the user id of the owner of the supplied file.
*
Expand All @@ -2355,6 2359,9 @@ protected interface PosixOwner {
*/
int getOwnerIdOf(File file);

/**
* An implementation of a posix owner for Linux.
*/
class ForLinuxEnvironment implements PosixOwner {

/**
Expand Down Expand Up @@ -2386,12 2393,8 @@ public ForLinuxEnvironment(int attempts, long pause, TimeUnit timeUnit) {
}

/**
* Returns the user id of the owner of the supplied file.
*
* @param file The file for which to locate the owner.
* @return The owner id of the supplied file.
* {@inheritDoc}
*/
@Override
public int getOwnerIdOf(File file) {
try {
// The binding for 'stat' is very platform dependant. To avoid the complexity of binding the correct method,
Expand Down Expand Up @@ -2430,8 2433,16 @@ public int getOwnerIdOf(File file) {
}
}

/**
* An implementation for a posix owner that represents AIX.
*/
class ForAixEnvironment implements PosixOwner {

/**
* A pattern to represent the owner on the console output.
*/
private static final Pattern AIX_OWNER_PATTERN = Pattern.compile("Owner: (\\d )\\(");

/**
* The maximum amount of attempts for checking the result of a foreign process.
*/
Expand Down Expand Up @@ -2460,15 2471,9 @@ public ForAixEnvironment(int attempts, long pause, TimeUnit timeUnit) {
this.timeUnit = timeUnit;
}

private static final Pattern AIX_OWNER_PATTERN = Pattern.compile("Owner: (\\d )\\(");

/**
* Returns the user id of the owner of the supplied file.
*
* @param file The file for which to locate the owner.
* @return The owner id of the supplied file.
* {@inheritDoc}
*/
@Override
public int getOwnerIdOf(File file) {
try {
Process process = Runtime.getRuntime().exec(new String[]{"istat", file.getAbsolutePath()});
Expand Down Expand Up @@ -2501,7 2506,6 @@ public int getOwnerIdOf(File file) {
throw new IllegalStateException("Command for istat did not exit in time");
}
Matcher matcher = AIX_OWNER_PATTERN.matcher(output.toString());
// Find and print the Owner UID
if (matcher.find()) {
return Integer.parseInt(matcher.group(1));
} else {
Expand All @@ -2513,6 2517,9 @@ public int getOwnerIdOf(File file) {
}
}

/**
* An implementation for a posix owner that represents MacOS.
*/
class ForMacEnvironment implements PosixOwner {

/**
Expand Down Expand Up @@ -2544,18 2551,14 @@ public ForMacEnvironment(int attempts, long pause, TimeUnit timeUnit) {
}

/**
* Returns the user id of the owner of the supplied file.
*
* @param file The file for which to locate the owner.
* @return The owner id of the supplied file.
* {@inheritDoc}
*/
@Override
public int getOwnerIdOf(File file) {
try {
// The binding for 'stat' is very platform dependant. To avoid the complexity of binding the correct method,
// stat is called as a separate command. This is less efficient but more portable.
Process process = Runtime.getRuntime().exec(new String[]{"stat",
"-f",
"-f",
"%u",
file.getAbsolutePath()});
int attempts = this.attempts;
Expand Down

0 comments on commit ceabf1d

Please sign in to comment.