当前位置: 首页>>代码示例>>Java>>正文


Java PosixFilePermission类代码示例

本文整理汇总了Java中java.nio.file.attribute.PosixFilePermission的典型用法代码示例。如果您正苦于以下问题:Java PosixFilePermission类的具体用法?Java PosixFilePermission怎么用?Java PosixFilePermission使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


PosixFilePermission类属于java.nio.file.attribute包,在下文中一共展示了PosixFilePermission类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createLocalConfigFile

import java.nio.file.attribute.PosixFilePermission; //导入依赖的package包/类
/**
 * Create localconf folder and properties file necessary to run build task in order to check merge integrity.
 * @param branchName
 */
public void createLocalConfigFile(String branchName) throws Exception {
  String branchPath = SvnUtils.TEMP_FOLDER + "/" + branchName;
  //create localconf directory
  String newDirectoryPath = branchPath + "/localconf";
  if ( !Files.exists( Paths.get(newDirectoryPath))) {
    Set<PosixFilePermission> permissions = PosixFilePermissions.fromString("rwxrwxrwx");
    FileAttribute<Set<PosixFilePermission>> fileAttributes = PosixFilePermissions
        .asFileAttribute(permissions);
    Files.createDirectory(Paths.get(newDirectoryPath), fileAttributes);
  }
  //copy properties template
  Files.copy(
      Paths.get(branchPath + "/common/conf/worldnettps.properties.template"),
      Paths.get(newDirectoryPath + "/worldnettps.properties"),
      StandardCopyOption.REPLACE_EXISTING);
  //setting glassfish directory in properties file
  String appServerDir = PropertiesUtil.getString("appserver.dir");
  String sedCommand = String.format(
      "sed -i '/glassfish.dir/c\\glassfish.dir=%s' localconf/worldnettps.properties", appServerDir);
  CommandExecutor.run( sedCommand, branchPath);
  logger.info("worldnettps.properties file has been created in localconf folder.");
}
 
开发者ID:lpavone,项目名称:SVNAutoMerger,代码行数:27,代码来源:Merger.java

示例2: getPosixPerm

import java.nio.file.attribute.PosixFilePermission; //导入依赖的package包/类
/**
 * 获取Posix权限
 */
public static Set<PosixFilePermission> getPosixPerm(int perm) {
  StringBuilder permStr = new StringBuilder();

  permStr.append(uCanRead(perm) ? "r" : "-");
  permStr.append(uCanWrite(perm) ? "w" : "-");
  permStr.append(uCanExec(perm) ? "x" : "-");
  permStr.append(gCanRead(perm) ? "r" : "-");
  permStr.append(gCanWrite(perm) ? "w" : "-");
  permStr.append(gCanExec(perm) ? "x" : "-");
  permStr.append(oCanRead(perm) ? "r" : "-");
  permStr.append(oCanWrite(perm) ? "w" : "-");
  permStr.append(oCanExec(perm) ? "x" : "-");

  return PosixFilePermissions.fromString(permStr.toString());
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:19,代码来源:FilePerm.java

示例3: testMissingWritePermissionOnShard

import java.nio.file.attribute.PosixFilePermission; //导入依赖的package包/类
public void testMissingWritePermissionOnShard() throws IOException {
    assumeTrue("posix filesystem", isPosix);
    final String[] tempPaths = tmpPaths();
    Path path = PathUtils.get(randomFrom(tempPaths));
    Path fooIndex = path.resolve("nodes").resolve("0").resolve(NodeEnvironment.INDICES_FOLDER)
        .resolve("foo");
    Path fooShard = fooIndex.resolve("0");
    Path fooShardIndex = fooShard.resolve("index");
    Path fooShardTranslog = fooShard.resolve("translog");
    Path fooShardState = fooShard.resolve("_state");
    Path pick = randomFrom(fooShard, fooShardIndex, fooShardTranslog, fooShardState);
    Files.createDirectories(pick);
    try (PosixPermissionsResetter attr = new PosixPermissionsResetter(pick)) {
        attr.setPermissions(new HashSet<>(Arrays.asList(PosixFilePermission.OTHERS_READ, PosixFilePermission.GROUP_READ,
            PosixFilePermission.OWNER_READ)));
        Settings build = Settings.builder()
            .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toAbsolutePath().toString())
            .putArray(Environment.PATH_DATA_SETTING.getKey(), tempPaths).build();
        IOException ioException = expectThrows(IOException.class, () -> {
            new NodeEnvironment(build, new Environment(build));
        });
        assertTrue(ioException.getMessage(), ioException.getMessage().startsWith("failed to write in data directory"));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:25,代码来源:NodeEnvironmentEvilTests.java

示例4: setFilePerm

import java.nio.file.attribute.PosixFilePermission; //导入依赖的package包/类
/**
 * 设置文件权限。前提:必须支持PosixFileAttributeView.
 */
public static void setFilePerm(File file, String perm) {
  if (filePermSupported()) {
    try {
      Set<PosixFilePermission> perms = PosixFilePermissions.fromString(perm);
      PosixFileAttributes attr = Files.readAttributes(file.toPath(), PosixFileAttributes.class);
      attr.permissions().clear();
      Files.setPosixFilePermissions(file.toPath(), perms);
    } catch (IOException e) {
      throw new IllegalStateException(e);
    }
  }
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:16,代码来源:FilePerm.java

示例5: testMissingWritePermission

import java.nio.file.attribute.PosixFilePermission; //导入依赖的package包/类
public void testMissingWritePermission() throws IOException {
    assumeTrue("posix filesystem", isPosix);
    final String[] tempPaths = tmpPaths();
    Path path = PathUtils.get(randomFrom(tempPaths));
    try (PosixPermissionsResetter attr = new PosixPermissionsResetter(path)) {
        attr.setPermissions(new HashSet<>(Arrays.asList(PosixFilePermission.OTHERS_READ, PosixFilePermission.GROUP_READ,
            PosixFilePermission.OWNER_READ)));
        Settings build = Settings.builder()
                .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toAbsolutePath().toString())
                .putArray(Environment.PATH_DATA_SETTING.getKey(), tempPaths).build();
        IOException ioException = expectThrows(IOException.class, () -> {
            new NodeEnvironment(build, new Environment(build));
        });
        assertTrue(ioException.getMessage(), ioException.getMessage().startsWith(path.toString()));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:17,代码来源:NodeEnvironmentEvilTests.java

示例6: testMissingWritePermissionOnIndex

import java.nio.file.attribute.PosixFilePermission; //导入依赖的package包/类
public void testMissingWritePermissionOnIndex() throws IOException {
    assumeTrue("posix filesystem", isPosix);
    final String[] tempPaths = tmpPaths();
    Path path = PathUtils.get(randomFrom(tempPaths));
    Path fooIndex = path.resolve("nodes").resolve("0").resolve(NodeEnvironment.INDICES_FOLDER)
        .resolve("foo");
    Files.createDirectories(fooIndex);
    try (PosixPermissionsResetter attr = new PosixPermissionsResetter(fooIndex)) {
        attr.setPermissions(new HashSet<>(Arrays.asList(PosixFilePermission.OTHERS_READ, PosixFilePermission.GROUP_READ,
            PosixFilePermission.OWNER_READ)));
        Settings build = Settings.builder()
            .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toAbsolutePath().toString())
            .putArray(Environment.PATH_DATA_SETTING.getKey(), tempPaths).build();
        IOException ioException = expectThrows(IOException.class, () -> {
            new NodeEnvironment(build, new Environment(build));
        });
        assertTrue(ioException.getMessage(), ioException.getMessage().startsWith("failed to write in data directory"));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:NodeEnvironmentEvilTests.java

示例7: testBinPermissions

import java.nio.file.attribute.PosixFilePermission; //导入依赖的package包/类
public void testBinPermissions() throws Exception {
    assumeTrue("posix filesystem", isPosix);
    Tuple<Path, Environment> env = createEnv(fs, temp);
    Path pluginDir = createPluginDir(temp);
    Path binDir = pluginDir.resolve("bin");
    Files.createDirectory(binDir);
    Files.createFile(binDir.resolve("somescript"));
    String pluginZip = createPlugin("fake", pluginDir);
    try (PosixPermissionsResetter binAttrs = new PosixPermissionsResetter(env.v2().binFile())) {
        Set<PosixFilePermission> perms = binAttrs.getCopyPermissions();
        // make sure at least one execute perm is missing, so we know we forced it during installation
        perms.remove(PosixFilePermission.GROUP_EXECUTE);
        binAttrs.setPermissions(perms);
        installPlugin(pluginZip, env.v1());
        assertPlugin("fake", pluginDir, env.v2());
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:InstallPluginCommandTests.java

示例8: setAsExecutable

import java.nio.file.attribute.PosixFilePermission; //导入依赖的package包/类
public static void setAsExecutable(String filePath) throws IOException {
	
	//using PosixFilePermission to set file permissions 755
       Set<PosixFilePermission> perms = new HashSet<PosixFilePermission>();
       //add owners permission
       perms.add(PosixFilePermission.OWNER_READ);
       perms.add(PosixFilePermission.OWNER_WRITE);
       perms.add(PosixFilePermission.OWNER_EXECUTE);
       //add group permissions
       perms.add(PosixFilePermission.GROUP_READ);
       perms.add(PosixFilePermission.GROUP_EXECUTE);
       //add others permissions
       perms.add(PosixFilePermission.OTHERS_READ);
       perms.add(PosixFilePermission.OTHERS_EXECUTE);
       
       Files.setPosixFilePermissions(Paths.get(filePath), perms);
       logger.info("Modified as executable " + filePath);
	
}
 
开发者ID:elastest,项目名称:elastest-instrumentation-manager,代码行数:20,代码来源:FileTextUtils.java

示例9: build

import java.nio.file.attribute.PosixFilePermission; //导入依赖的package包/类
public TestWorkspaceBuilder build() throws IOException {
  // mkdir -p
  Files.createDirectories(path.getParent());

  try (Writer out = Files.newBufferedWriter(path, Charset.defaultCharset())) {
    out.write(contents);
  }

  Set<PosixFilePermission> permissions = Sets.newHashSet(
      PosixFilePermission.OWNER_READ,
      PosixFilePermission.OWNER_WRITE);
  if (isExecutable) {
    permissions.add(PosixFilePermission.OWNER_EXECUTE);
  }

  Files.setPosixFilePermissions(path, permissions);
  return workspaceBuilder;
}
 
开发者ID:GoogleCloudPlatform,项目名称:runtime-builder-java,代码行数:19,代码来源:TestUtils.java

示例10: execute

import java.nio.file.attribute.PosixFilePermission; //导入依赖的package包/类
public int execute(String[] args, @Nullable Path workingDir, Map<String, String> addEnv) throws IOException {
  if (!Files.isExecutable(file)) {
    Set<PosixFilePermission> perms = new HashSet<PosixFilePermission>();
    perms.add(PosixFilePermission.OWNER_READ);
    perms.add(PosixFilePermission.OWNER_EXECUTE);
    Files.setPosixFilePermissions(file, perms);
  }

  ExecuteWatchdog watchdog = new ExecuteWatchdog(TIMEOUT);
  CommandLine cmd = new CommandLine(file.toFile());
  cmd.addArguments(args);
  DefaultExecutor exec = new DefaultExecutor();
  exec.setWatchdog(watchdog);
  exec.setStreamHandler(createStreamHandler());
  exec.setExitValues(null);
  if (workingDir != null) {
    exec.setWorkingDirectory(workingDir.toFile());
  }
  in.close();
  LOG.info("Executing: {}", cmd.toString());
  Map<String, String> env = new HashMap<>(System.getenv());
  env.putAll(addEnv);
  return exec.execute(cmd, env);
}
 
开发者ID:SonarSource,项目名称:sonarlint-cli,代码行数:25,代码来源:CommandExecutor.java

示例11: copyFilesAndApplyPermissions

import java.nio.file.attribute.PosixFilePermission; //导入依赖的package包/类
public static void copyFilesAndApplyPermissions(Path sourceDir, Path targetDir, List<String> filenames) throws IOException {
    for (String fileName : filenames) {
        Files.copy(sourceDir.resolve(fileName),
                targetDir.resolve(fileName));

        try {
            Set<PosixFilePermission> perms = new HashSet<PosixFilePermission>();
            perms.add(PosixFilePermission.OWNER_READ);
            perms.add(PosixFilePermission.OWNER_WRITE);
            perms.add(PosixFilePermission.OWNER_EXECUTE);
            perms.add(PosixFilePermission.GROUP_READ);
            perms.add(PosixFilePermission.GROUP_WRITE);
            perms.add(PosixFilePermission.GROUP_EXECUTE);
            perms.add(PosixFilePermission.OTHERS_READ);
            perms.add(PosixFilePermission.OTHERS_WRITE);
            perms.add(PosixFilePermission.OTHERS_EXECUTE);
            Files.setPosixFilePermissions(targetDir.resolve(fileName), perms);
        } catch (Throwable ignored) {
        }

    }

}
 
开发者ID:itesla,项目名称:ipst,代码行数:24,代码来源:Utils.java

示例12: permissionToInt

import java.nio.file.attribute.PosixFilePermission; //导入依赖的package包/类
private static int permissionToInt(PosixFilePermission permission) {
	switch (permission) {
	case OWNER_EXECUTE:
		return 100;
	case GROUP_EXECUTE:
		return 10;
	case OTHERS_EXECUTE:
		return 1;
	case OWNER_WRITE:
		return 200;
	case GROUP_WRITE:
		return 20;
	case OTHERS_WRITE:
		return 2;
	case OWNER_READ:
		return 400;
	case GROUP_READ:
		return 40;
	case OTHERS_READ:
		return 4;
	default:
		return 0;
	}
}
 
开发者ID:fergusq,项目名称:roda,代码行数:25,代码来源:FilePopulator.java

示例13: chmodFiles

import java.nio.file.attribute.PosixFilePermission; //导入依赖的package包/类
private static void chmodFiles(final Args arg,
		final HashMap<String, String> pairs,
		final String[] chmodList) throws IOException {
	final HashSet<PosixFilePermission> chmodSet = new HashSet<>();
	chmodSet.add(PosixFilePermission.OWNER_EXECUTE);
	chmodSet.add(PosixFilePermission.OWNER_READ);
	chmodSet.add(PosixFilePermission.OWNER_WRITE);
	System.out.println("Setting file permissions...");
	for(final String filename: chmodList) {
		System.out.println("\t" + arg.projectFolder.toString() + substitute(filename, pairs));
		final String resourceName = WebFramework.getResourceName(filename);
		final Path path =
			FileSystems.getDefault().getPath(arg.projectFolder.toString() + substitute(filename, pairs));
		Files.setPosixFilePermissions(path, chmodSet);
	}
}
 
开发者ID:emily-e,项目名称:webframework,代码行数:17,代码来源:WebFramework.java

示例14: mkdirs

import java.nio.file.attribute.PosixFilePermission; //导入依赖的package包/类
private boolean mkdirs(File file, Set<PosixFilePermission> permissions) throws IOException {
  if (file.exists()) {
    return false;
  }
  if (file.mkdir()) {
    Files.setPosixFilePermissions(file.toPath(), permissions);
    return true;
  }
  File parent = file.getParentFile();
  if (parent == null) {
    return false;
  }
  if (!mkdirs(parent, permissions) && !parent.exists()) {
    return false;
  }
  if (file.mkdir()) {
    Files.setPosixFilePermissions(file.toPath(), permissions);
    return true;
  }
  return false;
}
 
开发者ID:apache,项目名称:twill,代码行数:22,代码来源:LocalLocation.java

示例15: assertFilePermissions

import java.nio.file.attribute.PosixFilePermission; //导入依赖的package包/类
public static void assertFilePermissions(Path testRoot) throws IOException {
  Path file1 = testRoot.resolve(FILE_1); // mode 664
  PosixFileAttributeView allAttributesFile1 =
      Files.getFileAttributeView(file1, PosixFileAttributeView.class);
  Assert.assertThat(
      allAttributesFile1.readAttributes().permissions(),
      Matchers.containsInAnyOrder(
          PosixFilePermission.OWNER_READ,
          PosixFilePermission.OWNER_WRITE,
          PosixFilePermission.GROUP_READ));

  Path file2 = testRoot.resolve(FILE_2); // mode 777
  PosixFileAttributeView allAttributesFile2 =
      Files.getFileAttributeView(file2, PosixFileAttributeView.class);
  Assert.assertThat(
      allAttributesFile2.readAttributes().permissions(),
      Matchers.containsInAnyOrder(PosixFilePermission.values()));
}
 
开发者ID:GoogleCloudPlatform,项目名称:appengine-plugins-core,代码行数:19,代码来源:GenericArchivesVerifier.java


注:本文中的java.nio.file.attribute.PosixFilePermission类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。