Class CommonFiles

java.lang.Object
org.terracotta.utilities.test.io.CommonFiles

public final class CommonFiles extends Object
Tool for creating a system-wide, all-user-writable application file.
  • Field Details

    • LOGGER

      private static final org.slf4j.Logger LOGGER
    • IS_WINDOWS

      private static final boolean IS_WINDOWS
    • OWNER_TO_OTHER_MAPPING

      private static final EnumMap<PosixFilePermission,PosixFilePermission> OWNER_TO_OTHER_MAPPING
      Maps OWNER permissions into the corresponding OTHER permission.
  • Constructor Details

    • CommonFiles

      public CommonFiles()
  • Method Details

    • createCommonAppFile

      public static Path createCommonAppFile(Path path) throws IOException
      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 CommonApplicationData special folder is used. On *NIX machines, /var/tmp (not java.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 exist
      IOException - if an error is raised while attempting to create the file
      IllegalArgumentException - if path is not relative or is empty
      See Also:
    • copyOwnerPermissions

      private static void copyOwnerPermissions(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(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 the INHERITED_ACE header 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(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(String description, org.slf4j.event.Level logLevel, Path path)
      Logs the POSIX permissions for a Path at the logging level specified.
      Parameters:
      description - a description to write ahead of the logged permissions
      logLevel - the level at which the ACL is to be logged
      path - the path for which the ACL is logged
    • logAcl

      private static void logAcl(String description, org.slf4j.event.Level logLevel, Path path)
      Logs the ACL for a Path at the logging level specified. If running on Windows, the ICACLS to get the Windows view of the ACL.
      Parameters:
      description - a description to write ahead of the logged ACL
      logLevel - the level at which the ACL is to be logged
      path - the path for which the ACL is logged