當前位置: 首頁>>代碼示例>>Java>>正文


Java Files.getPosixFilePermissions方法代碼示例

本文整理匯總了Java中java.nio.file.Files.getPosixFilePermissions方法的典型用法代碼示例。如果您正苦於以下問題:Java Files.getPosixFilePermissions方法的具體用法?Java Files.getPosixFilePermissions怎麽用?Java Files.getPosixFilePermissions使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.nio.file.Files的用法示例。


在下文中一共展示了Files.getPosixFilePermissions方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: stashOriginalFilePermissions

import java.nio.file.Files; //導入方法依賴的package包/類
@Override
protected void stashOriginalFilePermissions() throws IOException {
  // save off permissions in case we need to
  // rewrite the keystore in flush()
  if (!Shell.WINDOWS) {
    Path path = Paths.get(file.getCanonicalPath());
    permissions = Files.getPosixFilePermissions(path);
  } else {
    // On Windows, the JDK does not support the POSIX file permission APIs.
    // Instead, we can do a winutils call and translate.
    String[] cmd = Shell.getGetPermissionCommand();
    String[] args = new String[cmd.length + 1];
    System.arraycopy(cmd, 0, args, 0, cmd.length);
    args[cmd.length] = file.getCanonicalPath();
    String out = Shell.execCommand(args);
    StringTokenizer t = new StringTokenizer(out, Shell.TOKEN_SEPARATOR_REGEX);
    // The winutils output consists of 10 characters because of the leading
    // directory indicator, i.e. "drwx------".  The JDK parsing method expects
    // a 9-character string, so remove the leading character.
    String permString = t.nextToken().substring(1);
    permissions = PosixFilePermissions.fromString(permString);
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:24,代碼來源:LocalJavaKeyStoreProvider.java

示例2: fixPermissions

import java.nio.file.Files; //導入方法依賴的package包/類
public void fixPermissions() throws IOException {
    try {
        Set<PosixFilePermission> filePermissions = Files.getPosixFilePermissions(executable);
        Stream<PosixFilePermission> requiredPermissions = Stream
            .of(PosixFilePermission.OWNER_EXECUTE, PosixFilePermission.GROUP_EXECUTE);

        requiredPermissions.forEach(requiredPermission -> {
            filePermissions.add(requiredPermission);
        });
        Files.setPosixFilePermissions(executable, filePermissions);
    } catch (UnsupportedOperationException e) {
        // windows -.-
    }
}
 
開發者ID:MyCoRe-Org,項目名稱:solr-runner-maven-plugin,代碼行數:15,代碼來源:SOLRRunner.java

示例3: testPlatformBinPermissions

import java.nio.file.Files; //導入方法依賴的package包/類
public void testPlatformBinPermissions() throws Exception {
    assumeTrue("posix filesystem", isPosix);
    Tuple<Path, Environment> env = createEnv(fs, temp);
    Path pluginDir = createPluginDir(temp);
    Path platformDir = pluginDir.resolve("platform");
    Path platformNameDir = platformDir.resolve("linux-x86_64");
    Path platformBinDir = platformNameDir.resolve("bin");
    Files.createDirectories(platformBinDir);
    Path programFile = Files.createFile(platformBinDir.resolve("someprogram"));
    // a file created with Files.createFile() should not have execute permissions
    Set<PosixFilePermission> sourcePerms = Files.getPosixFilePermissions(programFile);
    assertFalse(sourcePerms.contains(PosixFilePermission.OWNER_EXECUTE));
    assertFalse(sourcePerms.contains(PosixFilePermission.GROUP_EXECUTE));
    assertFalse(sourcePerms.contains(PosixFilePermission.OTHERS_EXECUTE));
    String pluginZip = createPlugin("fake", pluginDir);
    installPlugin(pluginZip, env.v1());
    assertPlugin("fake", pluginDir, env.v2());
    // check that the installed program has execute permissions, even though the one added to the plugin didn't
    Path installedPlatformBinDir = env.v2().pluginsFile().resolve("fake").resolve("platform").resolve("linux-x86_64").resolve("bin");
    assertTrue(Files.isDirectory(installedPlatformBinDir));
    Path installedProgramFile = installedPlatformBinDir.resolve("someprogram");
    assertTrue(Files.isRegularFile(installedProgramFile));
    Set<PosixFilePermission> installedPerms = Files.getPosixFilePermissions(installedProgramFile);
    assertTrue(installedPerms.contains(PosixFilePermission.OWNER_EXECUTE));
    assertTrue(installedPerms.contains(PosixFilePermission.GROUP_EXECUTE));
    assertTrue(installedPerms.contains(PosixFilePermission.OTHERS_EXECUTE));
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:28,代碼來源:InstallPluginCommandTests.java

示例4: getLauncher

import java.nio.file.Files; //導入方法依賴的package包/類
private static String[] getLauncher() throws IOException {
    String platform = getPlatform();
    if (platform == null) {
        return null;
    }

    String launcher = TEST_SRC + File.separator + platform + "-" + ARCH +
                      File.separator + "launcher";

    final FileSystem FS = FileSystems.getDefault();
    Path launcherPath = FS.getPath(launcher);

    final boolean hasLauncher = Files.isRegularFile(launcherPath, LinkOption.NOFOLLOW_LINKS)&&
                                Files.isReadable(launcherPath);
    if (!hasLauncher) {
        System.out.println("Launcher [" + launcher + "] does not exist. Skipping the test.");
        return null;
    }

    // It is impossible to store an executable file in the source control
    // We need to copy the launcher to the working directory
    // and set the executable flag
    Path localLauncherPath = FS.getPath(WORK_DIR, "launcher");
    Files.copy(launcherPath, localLauncherPath,
               StandardCopyOption.REPLACE_EXISTING,
               StandardCopyOption.COPY_ATTRIBUTES);
    if (!Files.isExecutable(localLauncherPath)) {
        Set<PosixFilePermission> perms = new HashSet<>(
            Files.getPosixFilePermissions(
                localLauncherPath,
                LinkOption.NOFOLLOW_LINKS
            )
        );
        perms.add(PosixFilePermission.OWNER_EXECUTE);
        Files.setPosixFilePermissions(localLauncherPath, perms);
    }
    return new String[] {launcher, localLauncherPath.toAbsolutePath().toString()};
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:39,代碼來源:CustomLauncherTest.java

示例5: setExecutable

import java.nio.file.Files; //導入方法依賴的package包/類
/**
 * chmod ugo+x file
 */
private void setExecutable(Path file) {
    try {
        Set<PosixFilePermission> perms = Files.getPosixFilePermissions(file);
        perms.add(PosixFilePermission.OWNER_EXECUTE);
        perms.add(PosixFilePermission.GROUP_EXECUTE);
        perms.add(PosixFilePermission.OTHERS_EXECUTE);
        Files.setPosixFilePermissions(file, perms);
    } catch (IOException ioe) {
        throw new UncheckedIOException(ioe);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:15,代碼來源:DefaultImageBuilder.java

示例6: setReadOnly

import java.nio.file.Files; //導入方法依賴的package包/類
/**
 * chmod ugo-w file
 */
private void setReadOnly(Path file) {
    try {
        Set<PosixFilePermission> perms = Files.getPosixFilePermissions(file);
        perms.remove(PosixFilePermission.OWNER_WRITE);
        perms.remove(PosixFilePermission.GROUP_WRITE);
        perms.remove(PosixFilePermission.OTHERS_WRITE);
        Files.setPosixFilePermissions(file, perms);
    } catch (IOException ioe) {
        throw new UncheckedIOException(ioe);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:15,代碼來源:DefaultImageBuilder.java

示例7: getLauncher

import java.nio.file.Files; //導入方法依賴的package包/類
private static String[] getLauncher() throws IOException {
    String platform = getPlatform();
    if (platform == null) {
        return null;
    }

    String launcher = TEST_SRC + File.separator + platform + "-" + ARCH +
                      File.separator + "launcher";

    final FileSystem FS = FileSystems.getDefault();
    Path launcherPath = FS.getPath(launcher);

    final boolean hasLauncher = Files.isRegularFile(launcherPath, LinkOption.NOFOLLOW_LINKS)&&
                                Files.isReadable(launcherPath);
    if (!hasLauncher) {
        System.out.println("Launcher [" + launcher + "] does not exist. Skipping the test.");
        return null;
    }

    // It is impossible to store an executable file in the source control
    // We need to copy the launcher to the working directory
    // and set the executable flag
    Path localLauncherPath = FS.getPath(WORK_DIR, "launcher");
    Files.copy(launcherPath, localLauncherPath,
               StandardCopyOption.REPLACE_EXISTING);
    if (!Files.isExecutable(localLauncherPath)) {
        Set<PosixFilePermission> perms = new HashSet<>(
            Files.getPosixFilePermissions(
                localLauncherPath,
                LinkOption.NOFOLLOW_LINKS
            )
        );
        perms.add(PosixFilePermission.OWNER_EXECUTE);
        Files.setPosixFilePermissions(localLauncherPath, perms);
    }
    return new String[] {launcher, localLauncherPath.toAbsolutePath().toString()};
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:38,代碼來源:CustomLauncherTest.java

示例8: test2

import java.nio.file.Files; //導入方法依賴的package包/類
/**
 * Test 1 - SSL config file is secure - VM should start
 */
private void test2() throws Exception {
    final Set<PosixFilePermission> perms = Files.getPosixFilePermissions(file2PermissionTest);
    perms.add(PosixFilePermission.OTHERS_READ);
    perms.add(PosixFilePermission.OTHERS_EXECUTE);
    Files.setPosixFilePermissions(file2PermissionTest, perms);

    if (doTest() == 0) {
        ++failures;
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:14,代碼來源:AbstractFilePermissionTest.java

示例9: DefaulExecutable

import java.nio.file.Files; //導入方法依賴的package包/類
DefaulExecutable(Supplier<Log> log, Path file) throws IOException {
  requireNonNull(log);
  requireNonNull(file);
  this.log = log;

  this.file = file;

  if (!Files.exists(file)) {
    this.log.get().debug("Creating " + file);
    Files.createFile(file);
    truncate();
  } else {
    this.log.get().debug(file + " already exists");
  }

  this.log.get().debug("Marking '" + file + "' as executable");
  Set<PosixFilePermission> permissions;
  try {
    permissions = Files.getPosixFilePermissions(file);
  } catch (UnsupportedOperationException ignored) {
    return;
  }

  permissions.add(PosixFilePermission.OWNER_EXECUTE);
  permissions.add(PosixFilePermission.GROUP_EXECUTE);
  permissions.add(PosixFilePermission.OTHERS_EXECUTE);

  Files.setPosixFilePermissions(file, permissions);
}
 
開發者ID:Cosium,項目名稱:maven-git-code-format,代碼行數:30,代碼來源:DefaulExecutable.java

示例10: loadAndCheck

import java.nio.file.Files; //導入方法依賴的package包/類
private int loadAndCheck(Path p, AuthTimeWithHash time,
        KerberosTime currTime)
        throws IOException, KrbApErrException {
    int missed = 0;
    if (Files.isSymbolicLink(p)) {
        throw new IOException("Symlink not accepted");
    }
    try {
        Set<PosixFilePermission> perms =
                Files.getPosixFilePermissions(p);
        if (uid != -1 &&
                (Integer)Files.getAttribute(p, "unix:uid") != uid) {
            throw new IOException("Not mine");
        }
        if (perms.contains(PosixFilePermission.GROUP_READ) ||
                perms.contains(PosixFilePermission.GROUP_WRITE) ||
                perms.contains(PosixFilePermission.GROUP_EXECUTE) ||
                perms.contains(PosixFilePermission.OTHERS_READ) ||
                perms.contains(PosixFilePermission.OTHERS_WRITE) ||
                perms.contains(PosixFilePermission.OTHERS_EXECUTE)) {
            throw new IOException("Accessible by someone else");
        }
    } catch (UnsupportedOperationException uoe) {
        // No POSIX permissions? Ignore it.
    }
    chan = Files.newByteChannel(p, StandardOpenOption.WRITE,
            StandardOpenOption.READ);

    long timeLimit = currTime.getSeconds() - readHeader(chan);

    long pos = 0;
    boolean seeNewButNotSame = false;
    while (true) {
        try {
            pos = chan.position();
            AuthTime a = AuthTime.readFrom(chan);
            if (a instanceof AuthTimeWithHash) {
                if (time.equals(a)) {
                    // Exact match, must be a replay
                    throw new KrbApErrException(Krb5.KRB_AP_ERR_REPEAT);
                } else if (time.isSameIgnoresHash(a)) {
                    // Two different authenticators in the same second.
                    // Remember it
                    seeNewButNotSame = true;
                }
            } else {
                if (time.isSameIgnoresHash(a)) {
                    // Two authenticators in the same second. Considered
                    // same if we haven't seen a new style version of it
                    if (!seeNewButNotSame) {
                        throw new KrbApErrException(Krb5.KRB_AP_ERR_REPEAT);
                    }
                }
            }
            if (a.ctime < timeLimit) {
                missed++;
            } else {
                missed--;
            }
        } catch (BufferUnderflowException e) {
            // Half-written file?
            chan.position(pos);
            break;
        }
    }
    return missed;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:68,代碼來源:DflCache.java

示例11: loadAndCheck

import java.nio.file.Files; //導入方法依賴的package包/類
private int loadAndCheck(Path p, AuthTimeWithHash time,
        KerberosTime currTime)
        throws IOException, KrbApErrException {
    int missed = 0;
    if (Files.isSymbolicLink(p)) {
        throw new IOException("Symlink not accepted");
    }
    try {
        Set<PosixFilePermission> perms =
                Files.getPosixFilePermissions(p);
        if (uid != -1 &&
                (Integer)Files.getAttribute(p, "unix:uid") != uid) {
            throw new IOException("Not mine");
        }
        if (perms.contains(PosixFilePermission.GROUP_READ) ||
                perms.contains(PosixFilePermission.GROUP_WRITE) ||
                perms.contains(PosixFilePermission.GROUP_EXECUTE) ||
                perms.contains(PosixFilePermission.OTHERS_READ) ||
                perms.contains(PosixFilePermission.OTHERS_WRITE) ||
                perms.contains(PosixFilePermission.OTHERS_EXECUTE)) {
            throw new IOException("Accessible by someone else");
        }
    } catch (UnsupportedOperationException uoe) {
        // No POSIX permissions? Ignore it.
    }
    chan = Files.newByteChannel(p, StandardOpenOption.WRITE,
            StandardOpenOption.READ);

    long timeLimit = currTime.getSeconds() - readHeader(chan);

    long pos = 0;
    boolean seeNewButNotSame = false;
    while (true) {
        try {
            pos = chan.position();
            AuthTime a = AuthTime.readFrom(chan);
            if (a instanceof AuthTimeWithHash) {
                if (time.equals(a)) {
                    // Exact match, must be a replay
                    throw new KrbApErrException(Krb5.KRB_AP_ERR_REPEAT);
                } else if (time.sameTimeDiffHash((AuthTimeWithHash)a)) {
                    // Two different authenticators in the same second.
                    // Remember it
                    seeNewButNotSame = true;
                }
            } else {
                if (time.isSameIgnoresHash(a)) {
                    // Two authenticators in the same second. Considered
                    // same if we haven't seen a new style version of it
                    if (!seeNewButNotSame) {
                        throw new KrbApErrException(Krb5.KRB_AP_ERR_REPEAT);
                    }
                }
            }
            if (a.ctime < timeLimit) {
                missed++;
            } else {
                missed--;
            }
        } catch (BufferUnderflowException e) {
            // Half-written file?
            chan.position(pos);
            break;
        }
    }
    return missed;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:68,代碼來源:DflCache.java


注:本文中的java.nio.file.Files.getPosixFilePermissions方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。