]> nmode's Git Repositories - signal-cli/blobdiff - src/main/java/org/asamk/signal/util/IOUtils.java
Reformat imports
[signal-cli] / src / main / java / org / asamk / signal / util / IOUtils.java
index 69128d015534eeabb29b33704b9ee7029f326581..434669de975fa0d463e9ac69a261dced80742e47 100644 (file)
@@ -12,7 +12,9 @@ import java.nio.file.attribute.PosixFilePermissions;
 import java.util.EnumSet;
 import java.util.Set;
 
-import static java.nio.file.attribute.PosixFilePermission.*;
+import static java.nio.file.attribute.PosixFilePermission.OWNER_EXECUTE;
+import static java.nio.file.attribute.PosixFilePermission.OWNER_READ;
+import static java.nio.file.attribute.PosixFilePermission.OWNER_WRITE;
 
 public class IOUtils {
 
@@ -33,13 +35,18 @@ public class IOUtils {
         return output.toString();
     }
 
-    public static void createPrivateDirectories(String path) throws IOException {
-        final Path file = new File(path).toPath();
+    public static void createPrivateDirectories(String directoryPath) throws IOException {
+        final File file = new File(directoryPath);
+        if (file.exists()) {
+            return;
+        }
+
+        final Path path = file.toPath();
         try {
             Set<PosixFilePermission> perms = EnumSet.of(OWNER_READ, OWNER_WRITE, OWNER_EXECUTE);
-            Files.createDirectories(file, PosixFilePermissions.asFileAttribute(perms));
+            Files.createDirectories(path, PosixFilePermissions.asFileAttribute(perms));
         } catch (UnsupportedOperationException e) {
-            Files.createDirectories(file);
+            Files.createDirectories(path);
         }
     }
 
@@ -52,4 +59,13 @@ public class IOUtils {
             Files.createFile(file);
         }
     }
+
+    public static String getDataHomeDir() {
+        String dataHome = System.getenv("XDG_DATA_HOME");
+        if (dataHome != null) {
+            return dataHome;
+        }
+
+        return System.getProperty("user.home") + "/.local/share";
+    }
 }