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

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

本文整理了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

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

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

/**
 * @deprecated as of 1.456
 *      Use {@link #resolveSymlink(File)}
 */
@Deprecated
public static String resolveSymlink(File link, TaskListener listener) throws InterruptedException, IOException {
  return resolveSymlink(link);
}

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

/**
 * Resolves a symlink to the {@link File} that points to.
 *
 * @return null
 *      if the specified file is not a symlink.
 */
@CheckForNull
public static File resolveSymlinkToFile(@Nonnull File link) throws InterruptedException, IOException {
  String target = resolveSymlink(link);
  if (target==null)   return null;
  File f = new File(target);
  if (f.isAbsolute()) return f;   // absolute symlink
  return new File(link.getParentFile(),target);   // relative symlink
}

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

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

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

static String readSymlink(File cache) throws IOException, InterruptedException {
  synchronized (symlinks) {
    String target = symlinks.get(cache);
    if (target != null) {
      LOGGER.log(Level.FINE, "readSymlink cached {0} → {1}", new Object[] {cache, target});
      return target;
    }
  }
  String target = Util.resolveSymlink(cache);
  if (target==null && cache.exists()) {
    // if this file isn't a symlink, it must be a regular file
    target = FileUtils.readFileToString(cache,"UTF-8").trim();
  }
  LOGGER.log(Level.FINE, "readSymlink {0} → {1}", new Object[] {cache, target});
  synchronized (symlinks) {
    symlinks.put(cache, target);
  }
  return target;
}

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

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

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

static void writeSymlink(File cache, String target) throws IOException, InterruptedException {
  LOGGER.log(Level.FINE, "writeSymlink {0} → {1}", new Object[] {cache, target});
  synchronized (symlinks) {
    symlinks.put(cache, target);
  }
  StringWriter w = new StringWriter();
  StreamTaskListener listener = new StreamTaskListener(w);
  Util.createSymlink(cache.getParentFile(),target,cache.getName(),listener);
  // Avoid calling resolveSymlink on a nonexistent file as it will probably throw an IOException:
  if (!exists(cache) || Util.resolveSymlink(cache)==null) {
   // symlink not supported. use a regular file
   AtomicFileWriter cw = new AtomicFileWriter(cache);
   try {
     cw.write(target);
     cw.commit();
   } finally {
     cw.abort();
   }
  }
}

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

/**
 * @since 1.532
 */
protected final void scanSingle(File f, String relative, FileVisitor visitor) throws IOException {
  if (visitor.understandsSymlink()) {
    String target;
    try {
      target = Util.resolveSymlink(f);
    } catch (IOException x) { // JENKINS-13202
      target = null;
    }
    if (target != null) {
      visitor.visitSymlink(f, target, relative);
      return;
    }
  }
  visitor.visit(f, relative);
}

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

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

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

/**
 * @deprecated as of 1.456
 *      Use {@link #resolveSymlink(File)}
 */
@Deprecated
public static String resolveSymlink(File link, TaskListener listener) throws InterruptedException, IOException {
  return resolveSymlink(link);
}

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

/**
 * Resolves a symlink to the {@link File} that points to.
 *
 * @return null
 *      if the specified file is not a symlink.
 */
@CheckForNull
public static File resolveSymlinkToFile(@Nonnull File link) throws InterruptedException, IOException {
  String target = resolveSymlink(link);
  if (target==null)   return null;
  File f = new File(target);
  if (f.isAbsolute()) return f;   // absolute symlink
  return new File(link.getParentFile(),target);   // relative symlink
}

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

static String readSymlink(File cache) throws IOException, InterruptedException {
  synchronized (symlinks) {
    String target = symlinks.get(cache);
    if (target != null) {
      LOGGER.log(Level.FINE, "readSymlink cached {0} → {1}", new Object[] {cache, target});
      return target;
    }
  }
  String target = Util.resolveSymlink(cache);
  if (target==null && cache.exists()) {
    // if this file isn't a symlink, it must be a regular file
    target = FileUtils.readFileToString(cache,"UTF-8").trim();
  }
  LOGGER.log(Level.FINE, "readSymlink {0} → {1}", new Object[] {cache, target});
  synchronized (symlinks) {
    symlinks.put(cache, target);
  }
  return target;
}

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

private void scan(File f, String path, FileVisitor visitor) throws IOException {
  if (f.canRead()) {
    if (visitor.understandsSymlink()) {
      String target = Util.resolveSymlink(f, TaskListener.NULL);
      if (target != null) {
        visitor.visitSymlink(f, target, path + f.getName());
        return;
      } 
    }
    visitor.visit(f,path+f.getName());
    if(f.isDirectory()) {
      for( File child : f.listFiles() )
        scan(child,path+f.getName()+'/',visitor);
    }
  }
}

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

private void scan(File f, String path, FileVisitor visitor) throws IOException {
  if (f.canRead()) {
    if (visitor.understandsSymlink()) {
      try {
        String target = Util.resolveSymlink(f, TaskListener.NULL);
        if (target!=null) {
          visitor.visitSymlink(f,target,path+f.getName());
          return;
        }
      } catch (InterruptedException e) {
        throw (IOException)new InterruptedIOException().initCause(e);
      }
    }
    visitor.visit(f,path+f.getName());
    if(f.isDirectory()) {
      for( File child : f.listFiles() )
        scan(child,path+f.getName()+'/',visitor);
    }
  }
}

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

private void scan(File f, String path, FileVisitor visitor) throws IOException {
  if (f.canRead()) {
    if (visitor.understandsSymlink()) {
      try {
        String target = Util.resolveSymlink(f, TaskListener.NULL);
        if (target!=null) {
          visitor.visitSymlink(f,target,path+f.getName());
          return;
        }
      } catch (InterruptedException e) {
        throw (IOException)new InterruptedIOException().initCause(e);
      }
    }
    visitor.visit(f,path+f.getName());
    if(f.isDirectory()) {
      for( File child : f.listFiles() )
        scan(child,path+f.getName()+'/',visitor);
    }
  }
}

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

private void scan(File f, String path, FileVisitor visitor) throws IOException {
  if (f.canRead()) {
    if (visitor.understandsSymlink()) {
      String target = Util.resolveSymlink(f, TaskListener.NULL);
      if (target != null) {
        visitor.visitSymlink(f, target, path + f.getName());
        return;
      }
    }
    visitor.visit(f, path + f.getName());
    if (f.isDirectory()) {
      for (File child : f.listFiles()) {
        scan(child, path + f.getName() + '/', visitor);
      }
    }
  }
}

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

/**
 * @since 1.532
 */
protected final void scanSingle(File f, String relative, FileVisitor visitor) throws IOException {
  if (visitor.understandsSymlink()) {
    try {
      String target;
      try {
        target = Util.resolveSymlink(f);
      } catch (IOException x) { // JENKINS-13202
        target = null;
      }
      if (target != null) {
        visitor.visitSymlink(f, target, relative);
        return;
      }
    } catch (InterruptedException e) {
      throw (IOException) new InterruptedIOException().initCause(e);
    }
  }
  visitor.visit(f, relative);
}

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

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

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

static void writeSymlink(File cache, String target) throws IOException, InterruptedException {
  LOGGER.log(Level.FINE, "writeSymlink {0} → {1}", new Object[] {cache, target});
  synchronized (symlinks) {
    symlinks.put(cache, target);
  }
  StringWriter w = new StringWriter();
  StreamTaskListener listener = new StreamTaskListener(w);
  Util.createSymlink(cache.getParentFile(),target,cache.getName(),listener);
  // Avoid calling resolveSymlink on a nonexistent file as it will probably throw an IOException:
  if (!exists(cache) || Util.resolveSymlink(cache)==null) {
   // symlink not supported. use a regular file
   AtomicFileWriter cw = new AtomicFileWriter(cache);
   try {
     cw.write(target);
     cw.commit();
   } finally {
     cw.abort();
   }
  }
}

相关文章