Package org.terracotta.utilities.test.io
Class CommonFiles
- java.lang.Object
-
- org.terracotta.utilities.test.io.CommonFiles
-
public final class CommonFiles extends java.lang.ObjectTool for creating a system-wide, all-user-writable application file.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classCommonFiles.LoggerBridgeBridge to permit variable-level use of SLF4j.private static classCommonFiles.WindowsWellKnownIdentitiesWindows Well-Known Security Identifiers (SIDs) for use with ACL operations.
-
Field Summary
Fields Modifier and Type Field Description private static booleanIS_WINDOWSprivate static org.slf4j.LoggerLOGGERprivate static java.util.EnumMap<java.nio.file.attribute.PosixFilePermission,java.nio.file.attribute.PosixFilePermission>OWNER_TO_OTHER_MAPPINGMaps OWNER permissions into the corresponding OTHER permission.
-
Constructor Summary
Constructors Constructor Description CommonFiles()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static voidcopyOwnerPermissions(java.nio.file.Path path)Grant all permissions held by the owner to other users.static java.nio.file.PathcreateCommonAppFile(java.nio.file.Path path)Creates a file, using the relative path provided, in the system-appropriate directory for persistent, cross-process, cross-user data.private static voidlogAcl(java.lang.String description, org.slf4j.event.Level logLevel, java.nio.file.Path path)Logs the ACL for aPathat the logging level specified.private static voidlogPermissions(java.lang.String description, org.slf4j.event.Level logLevel, java.nio.file.Path path)Logs the POSIX permissions for aPathat the logging level specified.private static voidupdateAcl(java.nio.file.Path path)Updates ACL-based permissions.private static voidupdatePosixPermissions(java.nio.file.Path path)Updates POSIX-based permissions.
-
-
-
Field Detail
-
LOGGER
private static final org.slf4j.Logger LOGGER
-
IS_WINDOWS
private static final boolean IS_WINDOWS
-
OWNER_TO_OTHER_MAPPING
private static final java.util.EnumMap<java.nio.file.attribute.PosixFilePermission,java.nio.file.attribute.PosixFilePermission> OWNER_TO_OTHER_MAPPING
Maps OWNER permissions into the corresponding OTHER permission.
-
-
Method Detail
-
createCommonAppFile
public static java.nio.file.Path createCommonAppFile(java.nio.file.Path path) throws java.io.IOExceptionCreates a file, using the relative path provided, in the system-appropriate directory for persistent, cross-process, cross-user data.On Windows machines, the Windows directory assigned to the
CommonApplicationDataspecial folder is used. On *NIX machines,/var/tmp(notjava.io.tmpdir) is used.- Parameters:
path- the relative path to the file to create within the common directory- Returns:
- the path of the created file
- Throws:
java.io.FileNotFoundException- if the system-appropriate directory does not existjava.io.IOException- if an error is raised while attempting to create the filejava.lang.IllegalArgumentException- ifpathis not relative or is empty- See Also:
- Environment.SpecialFolder Enum, Filesystem Hierarchy Standard
-
copyOwnerPermissions
private static void copyOwnerPermissions(java.nio.file.Path path)
Grant all permissions held by the owner to other users.- Parameters:
path- the path on which permissions are altered
-
updateAcl
private static void updateAcl(java.nio.file.Path path)
Updates ACL-based permissions. This method copies the owner permissions into an ACL entry representing all users.NOTE
The JDK does not expose theINHERITED_ACEheader bit designating whether or not an ACE is actually present in the ACL or inherited from a parent ACL. (This not the only thing in a Windows ACL not exposed by the JDK.) Because of this lack, all ACEs, not only the owner and "All Users" ACEs, are explicitly replicated breaking the rights inheritance chain that existed.- Parameters:
path- the file for which permissions are altered
-
updatePosixPermissions
private static void updatePosixPermissions(java.nio.file.Path path)
Updates POSIX-based permissions. This method ensures that "other" includes all permissions granted to "owner".- Parameters:
path- the file for which permissions are altered
-
logPermissions
private static void logPermissions(java.lang.String description, org.slf4j.event.Level logLevel, java.nio.file.Path path)Logs the POSIX permissions for aPathat the logging level specified.- Parameters:
description- a description to write ahead of the logged permissionslogLevel- the level at which the ACL is to be loggedpath- the path for which the ACL is logged
-
logAcl
private static void logAcl(java.lang.String description, org.slf4j.event.Level logLevel, java.nio.file.Path path)Logs the ACL for aPathat the logging level specified. If running on Windows, theICACLSto get the Windows view of the ACL.- Parameters:
description- a description to write ahead of the logged ACLlogLevel- the level at which the ACL is to be loggedpath- the path for which the ACL is logged
-
-