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

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

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

Util.resolveSymlink介绍

[英]Resolves symlink, if the given file is a symlink. Otherwise return null.

If the resolution fails, report an error.
[中]如果给定文件是符号链接,则解析符号链接。否则返回null。
如果解决方案失败,请报告错误。

代码示例

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

  1. @Override
  2. public String invoke(File f, VirtualChannel channel) throws IOException, InterruptedException {
  3. return Util.resolveSymlink(reading(f));
  4. }
  5. }

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

  1. /**
  2. * @deprecated as of 1.456
  3. * Use {@link #resolveSymlink(File)}
  4. */
  5. @Deprecated
  6. public static String resolveSymlink(File link, TaskListener listener) throws InterruptedException, IOException {
  7. return resolveSymlink(link);
  8. }

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

  1. /**
  2. * Resolves a symlink to the {@link File} that points to.
  3. *
  4. * @return null
  5. * if the specified file is not a symlink.
  6. */
  7. @CheckForNull
  8. public static File resolveSymlinkToFile(@Nonnull File link) throws InterruptedException, IOException {
  9. String target = resolveSymlink(link);
  10. if (target==null) return null;
  11. File f = new File(target);
  12. if (f.isAbsolute()) return f; // absolute symlink
  13. return new File(link.getParentFile(),target); // relative symlink
  14. }

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

  1. @Override public String readLink() throws IOException {
  2. if (isIllegalSymlink()) {
  3. return null; // best to just ignore link -> ../whatever
  4. }
  5. return Util.resolveSymlink(f);
  6. }
  7. @Override public VirtualFile[] list() throws IOException {

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

  1. static String readSymlink(File cache) throws IOException, InterruptedException {
  2. synchronized (symlinks) {
  3. String target = symlinks.get(cache);
  4. if (target != null) {
  5. LOGGER.log(Level.FINE, "readSymlink cached {0} → {1}", new Object[] {cache, target});
  6. return target;
  7. }
  8. }
  9. String target = Util.resolveSymlink(cache);
  10. if (target==null && cache.exists()) {
  11. // if this file isn't a symlink, it must be a regular file
  12. target = FileUtils.readFileToString(cache,"UTF-8").trim();
  13. }
  14. LOGGER.log(Level.FINE, "readSymlink {0} → {1}", new Object[] {cache, target});
  15. synchronized (symlinks) {
  16. symlinks.put(cache, target);
  17. }
  18. return target;
  19. }

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

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

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

  1. static void writeSymlink(File cache, String target) throws IOException, InterruptedException {
  2. LOGGER.log(Level.FINE, "writeSymlink {0} → {1}", new Object[] {cache, target});
  3. synchronized (symlinks) {
  4. symlinks.put(cache, target);
  5. }
  6. StringWriter w = new StringWriter();
  7. StreamTaskListener listener = new StreamTaskListener(w);
  8. Util.createSymlink(cache.getParentFile(),target,cache.getName(),listener);
  9. // Avoid calling resolveSymlink on a nonexistent file as it will probably throw an IOException:
  10. if (!exists(cache) || Util.resolveSymlink(cache)==null) {
  11. // symlink not supported. use a regular file
  12. AtomicFileWriter cw = new AtomicFileWriter(cache);
  13. try {
  14. cw.write(target);
  15. cw.commit();
  16. } finally {
  17. cw.abort();
  18. }
  19. }
  20. }

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

  1. /**
  2. * @since 1.532
  3. */
  4. protected final void scanSingle(File f, String relative, FileVisitor visitor) throws IOException {
  5. if (visitor.understandsSymlink()) {
  6. String target;
  7. try {
  8. target = Util.resolveSymlink(f);
  9. } catch (IOException x) { // JENKINS-13202
  10. target = null;
  11. }
  12. if (target != null) {
  13. visitor.visitSymlink(f, target, relative);
  14. return;
  15. }
  16. }
  17. visitor.visit(f, relative);
  18. }

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

  1. public String invoke(File f, VirtualChannel channel) throws IOException, InterruptedException {
  2. return Util.resolveSymlink(reading(f));
  3. }
  4. });

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

  1. /**
  2. * @deprecated as of 1.456
  3. * Use {@link #resolveSymlink(File)}
  4. */
  5. @Deprecated
  6. public static String resolveSymlink(File link, TaskListener listener) throws InterruptedException, IOException {
  7. return resolveSymlink(link);
  8. }

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

  1. /**
  2. * Resolves a symlink to the {@link File} that points to.
  3. *
  4. * @return null
  5. * if the specified file is not a symlink.
  6. */
  7. @CheckForNull
  8. public static File resolveSymlinkToFile(@Nonnull File link) throws InterruptedException, IOException {
  9. String target = resolveSymlink(link);
  10. if (target==null) return null;
  11. File f = new File(target);
  12. if (f.isAbsolute()) return f; // absolute symlink
  13. return new File(link.getParentFile(),target); // relative symlink
  14. }

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

  1. static String readSymlink(File cache) throws IOException, InterruptedException {
  2. synchronized (symlinks) {
  3. String target = symlinks.get(cache);
  4. if (target != null) {
  5. LOGGER.log(Level.FINE, "readSymlink cached {0} → {1}", new Object[] {cache, target});
  6. return target;
  7. }
  8. }
  9. String target = Util.resolveSymlink(cache);
  10. if (target==null && cache.exists()) {
  11. // if this file isn't a symlink, it must be a regular file
  12. target = FileUtils.readFileToString(cache,"UTF-8").trim();
  13. }
  14. LOGGER.log(Level.FINE, "readSymlink {0} → {1}", new Object[] {cache, target});
  15. synchronized (symlinks) {
  16. symlinks.put(cache, target);
  17. }
  18. return target;
  19. }

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

  1. private void scan(File f, String path, FileVisitor visitor) throws IOException {
  2. if (f.canRead()) {
  3. if (visitor.understandsSymlink()) {
  4. String target = Util.resolveSymlink(f, TaskListener.NULL);
  5. if (target != null) {
  6. visitor.visitSymlink(f, target, path + f.getName());
  7. return;
  8. }
  9. }
  10. visitor.visit(f,path+f.getName());
  11. if(f.isDirectory()) {
  12. for( File child : f.listFiles() )
  13. scan(child,path+f.getName()+'/',visitor);
  14. }
  15. }
  16. }

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

  1. private void scan(File f, String path, FileVisitor visitor) throws IOException {
  2. if (f.canRead()) {
  3. if (visitor.understandsSymlink()) {
  4. try {
  5. String target = Util.resolveSymlink(f, TaskListener.NULL);
  6. if (target!=null) {
  7. visitor.visitSymlink(f,target,path+f.getName());
  8. return;
  9. }
  10. } catch (InterruptedException e) {
  11. throw (IOException)new InterruptedIOException().initCause(e);
  12. }
  13. }
  14. visitor.visit(f,path+f.getName());
  15. if(f.isDirectory()) {
  16. for( File child : f.listFiles() )
  17. scan(child,path+f.getName()+'/',visitor);
  18. }
  19. }
  20. }

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

  1. private void scan(File f, String path, FileVisitor visitor) throws IOException {
  2. if (f.canRead()) {
  3. if (visitor.understandsSymlink()) {
  4. try {
  5. String target = Util.resolveSymlink(f, TaskListener.NULL);
  6. if (target!=null) {
  7. visitor.visitSymlink(f,target,path+f.getName());
  8. return;
  9. }
  10. } catch (InterruptedException e) {
  11. throw (IOException)new InterruptedIOException().initCause(e);
  12. }
  13. }
  14. visitor.visit(f,path+f.getName());
  15. if(f.isDirectory()) {
  16. for( File child : f.listFiles() )
  17. scan(child,path+f.getName()+'/',visitor);
  18. }
  19. }
  20. }

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

  1. private void scan(File f, String path, FileVisitor visitor) throws IOException {
  2. if (f.canRead()) {
  3. if (visitor.understandsSymlink()) {
  4. String target = Util.resolveSymlink(f, TaskListener.NULL);
  5. if (target != null) {
  6. visitor.visitSymlink(f, target, path + f.getName());
  7. return;
  8. }
  9. }
  10. visitor.visit(f, path + f.getName());
  11. if (f.isDirectory()) {
  12. for (File child : f.listFiles()) {
  13. scan(child, path + f.getName() + '/', visitor);
  14. }
  15. }
  16. }
  17. }

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

  1. /**
  2. * @since 1.532
  3. */
  4. protected final void scanSingle(File f, String relative, FileVisitor visitor) throws IOException {
  5. if (visitor.understandsSymlink()) {
  6. try {
  7. String target;
  8. try {
  9. target = Util.resolveSymlink(f);
  10. } catch (IOException x) { // JENKINS-13202
  11. target = null;
  12. }
  13. if (target != null) {
  14. visitor.visitSymlink(f, target, relative);
  15. return;
  16. }
  17. } catch (InterruptedException e) {
  18. throw (IOException) new InterruptedIOException().initCause(e);
  19. }
  20. }
  21. visitor.visit(f, relative);
  22. }

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

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

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

  1. static void writeSymlink(File cache, String target) throws IOException, InterruptedException {
  2. LOGGER.log(Level.FINE, "writeSymlink {0} → {1}", new Object[] {cache, target});
  3. synchronized (symlinks) {
  4. symlinks.put(cache, target);
  5. }
  6. StringWriter w = new StringWriter();
  7. StreamTaskListener listener = new StreamTaskListener(w);
  8. Util.createSymlink(cache.getParentFile(),target,cache.getName(),listener);
  9. // Avoid calling resolveSymlink on a nonexistent file as it will probably throw an IOException:
  10. if (!exists(cache) || Util.resolveSymlink(cache)==null) {
  11. // symlink not supported. use a regular file
  12. AtomicFileWriter cw = new AtomicFileWriter(cache);
  13. try {
  14. cw.write(target);
  15. cw.commit();
  16. } finally {
  17. cw.abort();
  18. }
  19. }
  20. }

相关文章