Skip to content
Snippets Groups Projects
Commit c36cdd13 authored by juanf's avatar juanf
Browse files

SSDM-13521: adding more methods to the Unix replacement library

parent 5de4103e
No related branches found
No related tags found
1 merge request!40SSDM-13578 : 2PT : Database and V3 Implementation - include the new AFS "free"...
...@@ -36,6 +36,24 @@ public final class Posix ...@@ -36,6 +36,24 @@ public final class Posix
return true; return true;
} }
public static Set<PosixFilePermission> getPermissions(String path) throws IOExceptionUnchecked {
try
{
return Files.getPosixFilePermissions(Path.of(path));
} catch (IOException e)
{
throw new IOExceptionUnchecked(e);
}
}
public static void setAccessMode(String path, Set<PosixFilePermission> permissions) throws IOExceptionUnchecked {
try {
Files.setPosixFilePermissions(Path.of(path), permissions);
} catch (IOException e) {
throw new IOExceptionUnchecked(e);
}
}
public static void setAccessMode(String path, short mode) throws IOExceptionUnchecked { public static void setAccessMode(String path, short mode) throws IOExceptionUnchecked {
if (mode != (short) 0777) { if (mode != (short) 0777) {
throw new IOExceptionUnchecked("Failure to set file permissions for '" + path + "', mode 777 is supported."); throw new IOExceptionUnchecked("Failure to set file permissions for '" + path + "', mode 777 is supported.");
......
...@@ -16,12 +16,14 @@ ...@@ -16,12 +16,14 @@
package ch.systemsx.cisd.common.process; package ch.systemsx.cisd.common.process;
import java.io.File; import java.io.File;
import java.nio.file.attribute.PosixFilePermission;
import java.util.Set;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import ch.systemsx.cisd.common.io.Posix;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import ch.systemsx.cisd.base.exceptions.IOExceptionUnchecked; import ch.systemsx.cisd.base.exceptions.IOExceptionUnchecked;
import ch.systemsx.cisd.base.unix.Unix;
import ch.systemsx.cisd.common.logging.LogCategory; import ch.systemsx.cisd.common.logging.LogCategory;
import ch.systemsx.cisd.common.logging.LogFactory; import ch.systemsx.cisd.common.logging.LogFactory;
...@@ -72,16 +74,16 @@ public final class FileRenamingCallable implements Callable<Boolean> ...@@ -72,16 +74,16 @@ public final class FileRenamingCallable implements Callable<Boolean>
boolean renamed = sourceFile.renameTo(destinationFile); boolean renamed = sourceFile.renameTo(destinationFile);
if (renamed == false) if (renamed == false)
{ {
if (Unix.isOperational()) if (Posix.isOperational())
{ {
try try
{ {
// Try to set the permissions to "all can write" // Try to set the permissions to "all can write"
final short permissions = Set<PosixFilePermission> permissions =
Unix.getFileInfo(sourceFile.getPath()).getPermissions(); Posix.getPermissions(sourceFile.getPath());
Unix.setAccessMode(sourceFile.getPath(), (short) 0777); Posix.setAccessMode(sourceFile.getPath(), (short) 0777);
renamed = sourceFile.renameTo(destinationFile); renamed = sourceFile.renameTo(destinationFile);
Unix.setAccessMode(destinationFile.getPath(), permissions); Posix.setAccessMode(destinationFile.getPath(), permissions);
} catch (IOExceptionUnchecked ex) } catch (IOExceptionUnchecked ex)
{ {
operationLog.warn(String.format( operationLog.warn(String.format(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment