From 9fc512b159e6921964f6fb1420f28aff3d77dc53 Mon Sep 17 00:00:00 2001
From: juanf <juanf@ethz.ch>
Date: Fri, 26 May 2023 18:38:24 +0200
Subject: [PATCH] SSDM-13521: adding more methods to the Unix replacement
 library

---
 .../ch/systemsx/cisd/common/io/Posix.java     | 29 ++++++++++++++++---
 1 file changed, 25 insertions(+), 4 deletions(-)

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 054a6665639..23e3c1483c8 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
@@ -104,6 +104,28 @@ public final class Posix
         }
     }
 
+    public static int getUid(String path)
+    {
+        try
+        {
+            return (int) Files.getAttribute(Path.of(path), "unix:uid");
+        } catch (IOException e)
+        {
+            throw new IOExceptionUnchecked(e);
+        }
+    }
+
+    public static int getGid(String path)
+    {
+        try
+        {
+            return (int) Files.getAttribute(Path.of(path), "unix:gid");
+        } catch (IOException e)
+        {
+            throw new IOExceptionUnchecked(e);
+        }
+    }
+
     public static String tryGetUserNameForUid(int uid)
     {
         try
@@ -187,7 +209,7 @@ public final class Posix
             return gid;
         }
 
-        public String getSymbolicLinkOrNull()
+        public String tryGetSymbolicLink()
         {
             return symbolicLinkOrNull;
         }
@@ -275,13 +297,12 @@ public final class Posix
                 linkType = FileLinkType.OTHER;
             }
             long lastModified = Files.getLastModifiedTime(path).toMillis();
-            int uid = (int) Files.getAttribute(path, "unix:uid");
-            int gid = (int) Files.getAttribute(path, "unix:gid");
+            int uid = getUid(pathAsString);
+            int gid = getGid(pathAsString);
             String symbolicLinkOrNull = null;
             if (linkType == FileLinkType.SYMLINK) {
                 symbolicLinkOrNull = Files.readSymbolicLink(path).toString();
             }
-
             long size = Files.size(path);
             return new Stat(permissions, linkType, lastModified, uid, gid, symbolicLinkOrNull, size);
         } catch (IOException e)
-- 
GitLab