Skip to content

Commit

Permalink
Disable more usage of PosixPermission on Windows in InstallPluginCommand
Browse files Browse the repository at this point in the history
Releates to elastic#17201
  • Loading branch information
bleskes committed Mar 19, 2016
1 parent ee95c0a commit ef4293a
Showing 1 changed file with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -403,15 +403,17 @@ private void installBin(PluginInfo info, Path tmpBinDir, Path destBinDir) throws
}
Files.createDirectory(destBinDir);

// setup file attributes for the installed files to those of the parent dir
Set<PosixFilePermission> perms = new HashSet<>();
PosixFileAttributeView binAttrs = Files.getFileAttributeView(destBinDir.getParent(), PosixFileAttributeView.class);
if (binAttrs != null) {
perms = new HashSet<>(binAttrs.readAttributes().permissions());
// setting execute bits, since this just means "the file is executable", and actual execution requires read
perms.add(PosixFilePermission.OWNER_EXECUTE);
perms.add(PosixFilePermission.GROUP_EXECUTE);
perms.add(PosixFilePermission.OTHERS_EXECUTE);
if (Constants.WINDOWS == false) {
// setup file attributes for the installed files to those of the parent dir
PosixFileAttributeView binAttrs = Files.getFileAttributeView(destBinDir.getParent(), PosixFileAttributeView.class);
if (binAttrs != null) {
perms = new HashSet<>(binAttrs.readAttributes().permissions());
// setting execute bits, since this just means "the file is executable", and actual execution requires read
perms.add(PosixFilePermission.OWNER_EXECUTE);
perms.add(PosixFilePermission.GROUP_EXECUTE);
perms.add(PosixFilePermission.OTHERS_EXECUTE);
}
}

try (DirectoryStream<Path> stream = Files.newDirectoryStream(tmpBinDir)) {
Expand Down Expand Up @@ -444,9 +446,15 @@ private void installConfig(PluginInfo info, Path tmpConfigDir, Path destConfigDi
// create the plugin's config dir "if necessary"
Files.createDirectories(destConfigDir);

final PosixFileAttributes destConfigDirAttributes =
Files.getFileAttributeView(destConfigDir.getParent(), PosixFileAttributeView.class).readAttributes();
setOwnerGroup(destConfigDir, destConfigDirAttributes);
final PosixFileAttributes destConfigDirAttributes;
if (Constants.WINDOWS) {
destConfigDirAttributes = null;
} else {
destConfigDirAttributes =
Files.getFileAttributeView(destConfigDir.getParent(), PosixFileAttributeView.class).readAttributes();
setOwnerGroup(destConfigDir, destConfigDirAttributes);

}

try (DirectoryStream<Path> stream = Files.newDirectoryStream(tmpConfigDir)) {
for (Path srcFile : stream) {
Expand All @@ -457,7 +465,9 @@ private void installConfig(PluginInfo info, Path tmpConfigDir, Path destConfigDi
Path destFile = destConfigDir.resolve(tmpConfigDir.relativize(srcFile));
if (Files.exists(destFile) == false) {
Files.copy(srcFile, destFile);
setOwnerGroup(destFile, destConfigDirAttributes);
if (Constants.WINDOWS == false) {
setOwnerGroup(destFile, destConfigDirAttributes);
}
}
}
}
Expand Down

0 comments on commit ef4293a

Please sign in to comment.