Package org.terracotta.utilities.test.io
Class CommonFiles
java.lang.Object
org.terracotta.utilities.test.io.CommonFiles
Tool for creating a system-wide, all-user-writable application file.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final classBridge to permit variable-level use of SLF4j.private static final classWindows Well-Known Security Identifiers (SIDs) for use with ACL operations. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final booleanprivate static final org.slf4j.Loggerprivate static final EnumMap<PosixFilePermission,PosixFilePermission> Maps OWNER permissions into the corresponding OTHER permission. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static voidcopyOwnerPermissions(Path path) Grant all permissions held by the owner to other users.static PathcreateCommonAppFile(Path path) Creates a file, using the relative path provided, in the system-appropriate directory for persistent, cross-process, cross-user data.private static voidLogs the ACL for aPathat the logging level specified.private static voidlogPermissions(String description, org.slf4j.event.Level logLevel, Path path) Logs the POSIX permissions for aPathat the logging level specified.private static voidUpdates ACL-based permissions.private static voidupdatePosixPermissions(Path path) Updates POSIX-based permissions.
-
Field Details
-
LOGGER
private static final org.slf4j.Logger LOGGER -
IS_WINDOWS
private static final boolean IS_WINDOWS -
OWNER_TO_OTHER_MAPPING
Maps OWNER permissions into the corresponding OTHER permission.
-
-
Constructor Details
-
CommonFiles
public CommonFiles()
-
-
Method Details
-
createCommonAppFile
Creates 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:
FileNotFoundException- if the system-appropriate directory does not existIOException- if an error is raised while attempting to create the fileIllegalArgumentException- ifpathis not relative or is empty- See Also:
-
copyOwnerPermissions
Grant all permissions held by the owner to other users.- Parameters:
path- the path on which permissions are altered
-
updateAcl
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
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
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
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
-