Esempio n. 1
0
 private static void setPosixFileAttributes(
     Path path, UserPrincipal owner, GroupPrincipal group, Set<PosixFilePermission> permissions)
     throws IOException {
   PosixFileAttributeView fileAttributeView =
       Files.getFileAttributeView(path, PosixFileAttributeView.class);
   fileAttributeView.setOwner(owner);
   fileAttributeView.setGroup(group);
   fileAttributeView.setPermissions(permissions);
 }
Esempio n. 2
0
 private void setOwnership(File dir, String group, String owner) {
   try {
     Path path = dir.toPath();
     UserPrincipalLookupService lookupService =
         FileSystems.getDefault().getUserPrincipalLookupService();
     GroupPrincipal groupPrincipal = lookupService.lookupPrincipalByGroupName(group);
     UserPrincipal userPrincipal = lookupService.lookupPrincipalByName(owner);
     PosixFileAttributeView pfav =
         Files.getFileAttributeView(path, PosixFileAttributeView.class, LinkOption.NOFOLLOW_LINKS);
     pfav.setGroup(groupPrincipal);
     pfav.setOwner(userPrincipal);
   } catch (Exception ex) {
     cp.appendln("Unable to set the file group and owner for\n   " + dir);
   }
 }
  @Test
  public void testLocalPluginInstallWithBinAndConfig() throws Exception {
    String pluginName = "plugin-test";
    Tuple<Settings, Environment> initialSettings =
        InternalSettingsPreparer.prepareSettings(
            ImmutableSettings.settingsBuilder().build(), false);
    Environment env = initialSettings.v2();
    Path binDir = env.homeFile().resolve("bin");
    if (!Files.exists(binDir)) {
      Files.createDirectories(binDir);
    }
    Path pluginBinDir = binDir.resolve(pluginName);
    Path configDir = env.configFile();
    if (!Files.exists(configDir)) {
      Files.createDirectories(configDir);
    }
    Path pluginConfigDir = configDir.resolve(pluginName);
    try {

      PluginManager pluginManager =
          pluginManager(getPluginUrlForResource("plugin_with_bin_and_config.zip"), initialSettings);

      pluginManager.downloadAndExtract(pluginName);

      Path[] plugins = pluginManager.getListInstalledPlugins();

      assertThat(plugins, arrayWithSize(1));
      assertDirectoryExists(pluginBinDir);
      assertDirectoryExists(pluginConfigDir);
      Path toolFile = pluginBinDir.resolve("tool");
      assertFileExists(toolFile);

      // check that the file is marked executable, without actually checking that we can execute it.
      PosixFileAttributeView view =
          Files.getFileAttributeView(toolFile, PosixFileAttributeView.class);
      // the view might be null, on e.g. windows, there is nothing to check there!
      if (view != null) {
        PosixFileAttributes attributes = view.readAttributes();
        assertTrue(
            "unexpected permissions: " + attributes.permissions(),
            attributes.permissions().contains(PosixFilePermission.OWNER_EXECUTE));
      }
    } finally {
      // we need to clean up the copied dirs
      IOUtils.rm(pluginBinDir, pluginConfigDir);
    }
  }