Skip to content

Commit

Permalink
Fix an OS-specific issue in ToolInvocationLogger
Browse files Browse the repository at this point in the history
Updated the ToolInvocationLogger to fix a problem that could cause
an error message to be printed when trying to create a file on
Windows system using POSIX file permissions.
  • Loading branch information
dirmgr committed Mar 12, 2018
1 parent 8c77d1e commit 58a46d0
Showing 1 changed file with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -690,16 +690,24 @@ private static void logMessageToFile(final byte[] logMessageBytes,
StandardOpenOption.APPEND, // Append to file if it already exists.
StandardOpenOption.DSYNC); // Synchronously flush file on writing.

final Set<PosixFilePermission> filePermissionsSet = EnumSet.of(
PosixFilePermission.OWNER_READ, // Grant owner read access.
PosixFilePermission.OWNER_WRITE); // Grant owner write access.

final FileAttribute<Set<PosixFilePermission>> filePermissionsAttribute=
PosixFilePermissions.asFileAttribute(filePermissionsSet);
final FileAttribute<?>[] fileAttributes;
if (StaticUtils.isWindows())
{
fileAttributes = new FileAttribute<?>[0];
}
else
{
final Set<PosixFilePermission> filePermissionsSet = EnumSet.of(
PosixFilePermission.OWNER_READ, // Grant owner read access.
PosixFilePermission.OWNER_WRITE); // Grant owner write access.
final FileAttribute<Set<PosixFilePermission>> filePermissionsAttribute =
PosixFilePermissions.asFileAttribute(filePermissionsSet);
fileAttributes = new FileAttribute<?>[] { filePermissionsAttribute };
}

try (FileChannel fileChannel =
FileChannel.open(logFile.toPath(), openOptionsSet,
filePermissionsAttribute))
fileAttributes))
{
try (FileLock fileLock =
acquireFileLock(fileChannel, logFile, toolErrorStream))
Expand Down

0 comments on commit 58a46d0

Please sign in to comment.