diff --git a/lib-commonbase/source/java/ch/systemsx/cisd/common/io/Posix.java b/lib-commonbase/source/java/ch/systemsx/cisd/common/io/Posix.java index 80faddfb428b247e8ab5c6f19f44bb7159483903..22e3ffd4a596da549e1e28a883e53ef6cb919f1a 100644 --- a/lib-commonbase/source/java/ch/systemsx/cisd/common/io/Posix.java +++ b/lib-commonbase/source/java/ch/systemsx/cisd/common/io/Posix.java @@ -36,6 +36,24 @@ public final class Posix 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 { if (mode != (short) 0777) { throw new IOExceptionUnchecked("Failure to set file permissions for '" + path + "', mode 777 is supported."); diff --git a/lib-commonbase/source/java/ch/systemsx/cisd/common/process/FileRenamingCallable.java b/lib-commonbase/source/java/ch/systemsx/cisd/common/process/FileRenamingCallable.java index 75eca0f8188c5dae38771760e6b344528e59cb93..ceb3e81fa339f5aa0cf27ad6501dde8c6875febb 100644 --- a/lib-commonbase/source/java/ch/systemsx/cisd/common/process/FileRenamingCallable.java +++ b/lib-commonbase/source/java/ch/systemsx/cisd/common/process/FileRenamingCallable.java @@ -16,12 +16,14 @@ package ch.systemsx.cisd.common.process; import java.io.File; +import java.nio.file.attribute.PosixFilePermission; +import java.util.Set; import java.util.concurrent.Callable; +import ch.systemsx.cisd.common.io.Posix; import org.apache.log4j.Logger; 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.LogFactory; @@ -72,16 +74,16 @@ public final class FileRenamingCallable implements Callable<Boolean> boolean renamed = sourceFile.renameTo(destinationFile); if (renamed == false) { - if (Unix.isOperational()) + if (Posix.isOperational()) { try { // Try to set the permissions to "all can write" - final short permissions = - Unix.getFileInfo(sourceFile.getPath()).getPermissions(); - Unix.setAccessMode(sourceFile.getPath(), (short) 0777); + Set<PosixFilePermission> permissions = + Posix.getPermissions(sourceFile.getPath()); + Posix.setAccessMode(sourceFile.getPath(), (short) 0777); renamed = sourceFile.renameTo(destinationFile); - Unix.setAccessMode(destinationFile.getPath(), permissions); + Posix.setAccessMode(destinationFile.getPath(), permissions); } catch (IOExceptionUnchecked ex) { operationLog.warn(String.format(