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 {
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);
}
}
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";
+ }
}