hudson.Util.isSymlink()方法的使用及代码示例

x33g5p2x  于2022-01-31 转载在 其他  
字(5.4k)|赞(0)|评价(0)|浏览(249)

本文整理了Java中hudson.Util.isSymlink()方法的一些代码示例,展示了Util.isSymlink()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util.isSymlink()方法的具体详情如下:
包路径:hudson.Util
类名称:Util
方法名:isSymlink

Util.isSymlink介绍

[英]Checks if the given file represents a symlink. Unlike Files#isSymbolicLink(Path), this method also considers NTFS junction points as symbolic links.
[中]检查给定文件是否表示符号链接。与文件#isSymbolicLink(Path)不同,此方法还将NTFS junction points视为符号链接。

代码示例

代码示例来源:origin: jenkinsci/jenkins

  1. /**
  2. * @deprecated Use {@link Util#isSymlink} to detect symbolic links and junctions instead.
  3. */
  4. @Deprecated
  5. public static boolean isJunctionOrSymlink(File file) throws IOException {
  6. return Util.isSymlink(file);
  7. }

代码示例来源:origin: jenkinsci/jenkins

  1. private List<IOException> tryRemoveRecursive(@Nonnull Path path) {
  2. Path normalized = path.normalize();
  3. List<IOException> accumulatedErrors = Util.isSymlink(normalized) ? new ArrayList<>() :
  4. tryRemoveDirectoryContents(normalized);
  5. tryRemoveFile(normalized).ifPresent(accumulatedErrors::add);
  6. return accumulatedErrors;
  7. }

代码示例来源:origin: jenkinsci/jenkins

  1. if (Util.isSymlink(kid)) {
  2. LOGGER.log(FINE, "deleting build number symlink {0} → {1}", new Object[] {name, Util.resolveSymlink(kid)});
  3. } else if (kid.isDirectory()) {

代码示例来源:origin: jenkinsci/jenkins

  1. @Restricted(NoExternalUse.class)
  2. public static boolean isSymlink(@Nonnull Path path) {
  3. /*
  4. * Windows Directory Junctions are effectively the same as Linux symlinks to directories.
  5. * Unfortunately, the Java 7 NIO2 API function isSymbolicLink does not treat them as such.
  6. * It thinks of them as normal directories. To use the NIO2 API & treat it like a symlink,
  7. * you have to go through BasicFileAttributes and do the following check:
  8. * isSymbolicLink() || isOther()
  9. * The isOther() call will include Windows reparse points, of which a directory junction is.
  10. * It also includes includes devices, but reading the attributes of a device with NIO fails
  11. * or returns false for isOther(). (i.e. named pipes such as \\.\pipe\JenkinsTestPipe return
  12. * false for isOther(), and drives such as \\.\PhysicalDrive0 throw an exception when
  13. * calling readAttributes.
  14. */
  15. try {
  16. BasicFileAttributes attrs = Files.readAttributes(path, BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS);
  17. return attrs.isSymbolicLink() || (attrs instanceof DosFileAttributes && attrs.isOther());
  18. } catch (IOException ignored) {
  19. return false;
  20. }
  21. }

代码示例来源:origin: org.hudsonci.plugins/disk-usage

  1. public static Long getFileSize(File f) throws IOException {
  2. long size = 0;
  3. if (f.isDirectory() && !Util.isSymlink(f)) {
  4. File[] fileList = f.listFiles();
  5. if (fileList != null) {
  6. for (File child : fileList) {
  7. size += getFileSize(child);
  8. }
  9. } else {
  10. LOGGER.info("Failed to list files in " + f.getPath() + " - ignoring");
  11. }
  12. }
  13. return size + f.length();
  14. }
  15. }

代码示例来源:origin: org.jenkins-ci.plugins/disk-usage

  1. public static boolean isSymlink(File f){
  2. boolean symlink = false;
  3. try{
  4. Class<?> files = Thread.currentThread().getContextClassLoader().loadClass( "java.nio.file.Files" );
  5. Class<?> path = Thread.currentThread().getContextClassLoader().loadClass( "java.nio.file.Path" );
  6. Class<?> paths = Thread.currentThread().getContextClassLoader().loadClass( "java.nio.file.Paths" );
  7. URI uri = new URI(f.getAbsolutePath());
  8. Object filePath = paths.getMethod("get", URI.class).invoke(null, uri);
  9. symlink = (Boolean) files.getMethod("isSymbolicLink", path).invoke(null, filePath);
  10. }
  11. catch(Exception e){
  12. //not java 7, try native
  13. try{
  14. symlink = Util.isSymlink(f);
  15. }
  16. catch(NoClassDefFoundError error){
  17. Logger.getLogger(DiskUsageUtil.class.getName()).log(Level.WARNING, "Disk usage can not determine if file " + f.getAbsolutePath() + " is symlink.");
  18. //native fails
  19. }
  20. catch (IOException ex) {
  21. Logger.getLogger(DiskUsageUtil.class.getName()).log(Level.SEVERE, null, ex);
  22. }
  23. }
  24. return symlink;
  25. }

代码示例来源:origin: org.jvnet.hudson.main/hudson-core

  1. public static void deleteRecursive(File dir) throws IOException {
  2. if(!isSymlink(dir))
  3. deleteContentsRecursive(dir);
  4. deleteFile(dir);
  5. }

代码示例来源:origin: org.eclipse.hudson/hudson-core

  1. public static void deleteRecursive(File dir) throws IOException {
  2. if (!isSymlink(dir)) {
  3. deleteContentsRecursive(dir);
  4. }
  5. deleteFile(dir);
  6. }

代码示例来源:origin: org.eclipse.hudson.main/hudson-core

  1. public static void deleteRecursive(File dir) throws IOException {
  2. if (!isSymlink(dir)) {
  3. deleteContentsRecursive(dir);
  4. }
  5. deleteFile(dir);
  6. }

代码示例来源:origin: hudson/hudson-2.x

  1. public static void deleteRecursive(File dir) throws IOException {
  2. if(!isSymlink(dir))
  3. deleteContentsRecursive(dir);
  4. deleteFile(dir);
  5. }

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

  1. /**
  2. * Deletes a file or folder, throwing the first exception encountered, but
  3. * having a go at deleting everything. i.e. it does not <em>stop</em> on the
  4. * first exception, but tries (to delete) everything once.
  5. *
  6. * @param dir
  7. * What to delete. If a directory, the contents will be deleted
  8. * too.
  9. * @throws The first exception encountered.
  10. */
  11. private static void tryOnceDeleteRecursive(File dir) throws IOException {
  12. if(!isSymlink(dir))
  13. tryOnceDeleteContentsRecursive(dir);
  14. tryOnceDeleteFile(dir);
  15. }

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

  1. if (Util.isSymlink(kid)) {
  2. LOGGER.log(FINE, "deleting build number symlink {0} → {1}", new Object[] {name, Util.resolveSymlink(kid)});
  3. } else if (kid.isDirectory()) {

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

  1. private void deleteRecursive(File dir) throws IOException {
  2. if(!isSymlink(dir))
  3. deleteContentsRecursive(dir);
  4. try {
  5. deleteFile(deleting(dir));
  6. } catch (IOException e) {
  7. // if some of the child directories are big, it might take long enough to delete that
  8. // it allows others to create new files, causing problems like JENKINS-10113
  9. // so give it one more attempt before we give up.
  10. if(!isSymlink(dir))
  11. deleteContentsRecursive(dir);
  12. deleteFile(deleting(dir));
  13. }
  14. }

相关文章