Skip to content

Commit 2d186b9

Browse files
committed
Move utils from WDK to FgpUtil for wider use
1 parent 416bcc4 commit 2d186b9

1 file changed

Lines changed: 0 additions & 64 deletions

File tree

Model/src/main/java/org/gusdb/wdk/model/Utilities.java

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,13 @@
66
import java.io.IOException;
77
import java.io.InputStream;
88
import java.io.OutputStream;
9-
import java.nio.file.FileAlreadyExistsException;
10-
import java.nio.file.Files;
11-
import java.nio.file.Path;
12-
import java.nio.file.attribute.FileAttribute;
13-
import java.nio.file.attribute.PosixFilePermission;
14-
import java.nio.file.attribute.PosixFilePermissions;
159
import java.sql.Clob;
1610
import java.sql.SQLException;
1711
import java.util.Date;
1812
import java.util.LinkedHashMap;
1913
import java.util.Map;
2014
import java.util.Properties;
2115
import java.util.Random;
22-
import java.util.Set;
2316
import java.util.regex.Matcher;
2417
import java.util.regex.Pattern;
2518
import java.util.stream.Stream;
@@ -39,7 +32,6 @@
3932
import javax.mail.internet.MimeMultipart;
4033

4134
import org.apache.log4j.Logger;
42-
import org.gusdb.fgputil.functional.FunctionalInterfaces.BiFunctionWithException;
4335

4436
/**
4537
* This class provided constants that are shared among different WDK model
@@ -358,60 +350,4 @@ public static Map<String, Boolean> parseSortList(String sortList) throws WdkMode
358350
return sortingMap;
359351
}
360352

361-
// use different default permissions for dirs and files
362-
private static final String DEFAULT_POSIX_PERMS_DIR = "rwxrwxr-x";
363-
private static final String DEFAULT_POSIX_PERMS_FILE = "rw-rw-r--";
364-
365-
private static Set<PosixFilePermission> getDefaultPerms(Path path) {
366-
return PosixFilePermissions.fromString(Files.isDirectory(path)
367-
? DEFAULT_POSIX_PERMS_DIR
368-
: DEFAULT_POSIX_PERMS_FILE);
369-
}
370-
371-
/**
372-
* Creates a new filesystem object (file or directory) with shared group write but only all-read perms aka "rwxrwxr-x"
373-
* Meant to be called with either Files::createFile or Files::createDirectory.
374-
*/
375-
public static void ensureCreation(BiFunctionWithException<Path, FileAttribute<?>[], Path> creationFunction, Path path) throws WdkRuntimeException {
376-
try {
377-
creationFunction.apply(path, new FileAttribute[] {
378-
PosixFilePermissions.asFileAttribute(getDefaultPerms(path))
379-
});
380-
tryToOpenGroupPerms(path);
381-
}
382-
catch (FileAlreadyExistsException e) {
383-
// this is ok; try to ensure perms on existing directory (may fail if not owned by us)
384-
tryToOpenGroupPerms(path);
385-
}
386-
catch (Exception e) {
387-
// any other exception is a problem
388-
throw new WdkRuntimeException("Could not create path " + path.toAbsolutePath(), e);
389-
}
390-
}
391-
392-
public static void tryToOpenGroupPerms(Path path) {
393-
try {
394-
// get the current permissions
395-
Set<PosixFilePermission> currentPerms = Files.getPosixFilePermissions(path);
396-
Set<PosixFilePermission> targetPerms = getDefaultPerms(path);
397-
398-
// if any desired permission is missing from the current perms, then try to add
399-
for (PosixFilePermission perm : targetPerms) {
400-
if (!currentPerms.contains(perm)) {
401-
// union the current perms with the defaults so we don't inadvertently remove permissions already granted
402-
targetPerms.addAll(currentPerms);
403-
Files.setPosixFilePermissions(path, targetPerms);
404-
return;
405-
}
406-
}
407-
}
408-
catch (UnsupportedOperationException e) {
409-
// log but ignore it since it's not supported on Windows
410-
LOG.warn("Cannot set permissions to " + path, e);
411-
}
412-
catch (IOException e) {
413-
// log but ignore since sometimes existing creation is not owned by us or system perms is enough
414-
LOG.warn("Cannot set permissions to " + path, e);
415-
}
416-
}
417353
}

0 commit comments

Comments
 (0)