本文整理了Java中hudson.Util.isSymlink()
方法的一些代码示例,展示了Util.isSymlink()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util.isSymlink()
方法的具体详情如下:
包路径:hudson.Util
类名称: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
/**
* @deprecated Use {@link Util#isSymlink} to detect symbolic links and junctions instead.
*/
@Deprecated
public static boolean isJunctionOrSymlink(File file) throws IOException {
return Util.isSymlink(file);
}
代码示例来源:origin: jenkinsci/jenkins
private List<IOException> tryRemoveRecursive(@Nonnull Path path) {
Path normalized = path.normalize();
List<IOException> accumulatedErrors = Util.isSymlink(normalized) ? new ArrayList<>() :
tryRemoveDirectoryContents(normalized);
tryRemoveFile(normalized).ifPresent(accumulatedErrors::add);
return accumulatedErrors;
}
代码示例来源:origin: jenkinsci/jenkins
if (Util.isSymlink(kid)) {
LOGGER.log(FINE, "deleting build number symlink {0} → {1}", new Object[] {name, Util.resolveSymlink(kid)});
} else if (kid.isDirectory()) {
代码示例来源:origin: jenkinsci/jenkins
@Restricted(NoExternalUse.class)
public static boolean isSymlink(@Nonnull Path path) {
/*
* Windows Directory Junctions are effectively the same as Linux symlinks to directories.
* Unfortunately, the Java 7 NIO2 API function isSymbolicLink does not treat them as such.
* It thinks of them as normal directories. To use the NIO2 API & treat it like a symlink,
* you have to go through BasicFileAttributes and do the following check:
* isSymbolicLink() || isOther()
* The isOther() call will include Windows reparse points, of which a directory junction is.
* It also includes includes devices, but reading the attributes of a device with NIO fails
* or returns false for isOther(). (i.e. named pipes such as \\.\pipe\JenkinsTestPipe return
* false for isOther(), and drives such as \\.\PhysicalDrive0 throw an exception when
* calling readAttributes.
*/
try {
BasicFileAttributes attrs = Files.readAttributes(path, BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS);
return attrs.isSymbolicLink() || (attrs instanceof DosFileAttributes && attrs.isOther());
} catch (IOException ignored) {
return false;
}
}
代码示例来源:origin: org.hudsonci.plugins/disk-usage
public static Long getFileSize(File f) throws IOException {
long size = 0;
if (f.isDirectory() && !Util.isSymlink(f)) {
File[] fileList = f.listFiles();
if (fileList != null) {
for (File child : fileList) {
size += getFileSize(child);
}
} else {
LOGGER.info("Failed to list files in " + f.getPath() + " - ignoring");
}
}
return size + f.length();
}
}
代码示例来源:origin: org.jenkins-ci.plugins/disk-usage
public static boolean isSymlink(File f){
boolean symlink = false;
try{
Class<?> files = Thread.currentThread().getContextClassLoader().loadClass( "java.nio.file.Files" );
Class<?> path = Thread.currentThread().getContextClassLoader().loadClass( "java.nio.file.Path" );
Class<?> paths = Thread.currentThread().getContextClassLoader().loadClass( "java.nio.file.Paths" );
URI uri = new URI(f.getAbsolutePath());
Object filePath = paths.getMethod("get", URI.class).invoke(null, uri);
symlink = (Boolean) files.getMethod("isSymbolicLink", path).invoke(null, filePath);
}
catch(Exception e){
//not java 7, try native
try{
symlink = Util.isSymlink(f);
}
catch(NoClassDefFoundError error){
Logger.getLogger(DiskUsageUtil.class.getName()).log(Level.WARNING, "Disk usage can not determine if file " + f.getAbsolutePath() + " is symlink.");
//native fails
}
catch (IOException ex) {
Logger.getLogger(DiskUsageUtil.class.getName()).log(Level.SEVERE, null, ex);
}
}
return symlink;
}
代码示例来源:origin: org.jvnet.hudson.main/hudson-core
public static void deleteRecursive(File dir) throws IOException {
if(!isSymlink(dir))
deleteContentsRecursive(dir);
deleteFile(dir);
}
代码示例来源:origin: org.eclipse.hudson/hudson-core
public static void deleteRecursive(File dir) throws IOException {
if (!isSymlink(dir)) {
deleteContentsRecursive(dir);
}
deleteFile(dir);
}
代码示例来源:origin: org.eclipse.hudson.main/hudson-core
public static void deleteRecursive(File dir) throws IOException {
if (!isSymlink(dir)) {
deleteContentsRecursive(dir);
}
deleteFile(dir);
}
代码示例来源:origin: hudson/hudson-2.x
public static void deleteRecursive(File dir) throws IOException {
if(!isSymlink(dir))
deleteContentsRecursive(dir);
deleteFile(dir);
}
代码示例来源:origin: org.jenkins-ci.main/jenkins-core
/**
* Deletes a file or folder, throwing the first exception encountered, but
* having a go at deleting everything. i.e. it does not <em>stop</em> on the
* first exception, but tries (to delete) everything once.
*
* @param dir
* What to delete. If a directory, the contents will be deleted
* too.
* @throws The first exception encountered.
*/
private static void tryOnceDeleteRecursive(File dir) throws IOException {
if(!isSymlink(dir))
tryOnceDeleteContentsRecursive(dir);
tryOnceDeleteFile(dir);
}
代码示例来源:origin: org.jenkins-ci.main/jenkins-core
if (Util.isSymlink(kid)) {
LOGGER.log(FINE, "deleting build number symlink {0} → {1}", new Object[] {name, Util.resolveSymlink(kid)});
} else if (kid.isDirectory()) {
代码示例来源:origin: org.jenkins-ci.main/jenkins-core
private void deleteRecursive(File dir) throws IOException {
if(!isSymlink(dir))
deleteContentsRecursive(dir);
try {
deleteFile(deleting(dir));
} catch (IOException e) {
// if some of the child directories are big, it might take long enough to delete that
// it allows others to create new files, causing problems like JENKINS-10113
// so give it one more attempt before we give up.
if(!isSymlink(dir))
deleteContentsRecursive(dir);
deleteFile(deleting(dir));
}
}
内容来源于网络,如有侵权,请联系作者删除!