|
6 | 6 | import java.io.IOException; |
7 | 7 | import java.io.InputStream; |
8 | 8 | 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; |
15 | 9 | import java.sql.Clob; |
16 | 10 | import java.sql.SQLException; |
17 | 11 | import java.util.Date; |
18 | 12 | import java.util.LinkedHashMap; |
19 | 13 | import java.util.Map; |
20 | 14 | import java.util.Properties; |
21 | 15 | import java.util.Random; |
22 | | -import java.util.Set; |
23 | 16 | import java.util.regex.Matcher; |
24 | 17 | import java.util.regex.Pattern; |
25 | 18 | import java.util.stream.Stream; |
|
39 | 32 | import javax.mail.internet.MimeMultipart; |
40 | 33 |
|
41 | 34 | import org.apache.log4j.Logger; |
42 | | -import org.gusdb.fgputil.functional.FunctionalInterfaces.BiFunctionWithException; |
43 | 35 |
|
44 | 36 | /** |
45 | 37 | * 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 |
358 | 350 | return sortingMap; |
359 | 351 | } |
360 | 352 |
|
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 | | - } |
417 | 353 | } |
0 commit comments