Disable more usage of PosixPermission on Windows in InstallPluginCommand

Releates to #17201
This commit is contained in:
Boaz Leskes 2016-03-19 12:02:42 +01:00
parent ee95c0a384
commit ef4293a993
1 changed files with 22 additions and 12 deletions

View File

@ -403,8 +403,9 @@ class InstallPluginCommand extends Command {
}
Files.createDirectory(destBinDir);
// setup file attributes for the installed files to those of the parent dir
Set<PosixFilePermission> perms = new HashSet<>();
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());
@ -413,6 +414,7 @@ class InstallPluginCommand extends Command {
perms.add(PosixFilePermission.GROUP_EXECUTE);
perms.add(PosixFilePermission.OTHERS_EXECUTE);
}
}
try (DirectoryStream<Path> stream = Files.newDirectoryStream(tmpBinDir)) {
for (Path srcFile : stream) {
@ -444,10 +446,16 @@ class InstallPluginCommand extends Command {
// create the plugin's config dir "if necessary"
Files.createDirectories(destConfigDir);
final PosixFileAttributes 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) {
if (Files.isDirectory(srcFile)) {
@ -457,10 +465,12 @@ class InstallPluginCommand extends Command {
Path destFile = destConfigDir.resolve(tmpConfigDir.relativize(srcFile));
if (Files.exists(destFile) == false) {
Files.copy(srcFile, destFile);
if (Constants.WINDOWS == false) {
setOwnerGroup(destFile, destConfigDirAttributes);
}
}
}
}
IOUtils.rm(tmpConfigDir); // clean up what we just copied
}