/** * Executes some program on the machine that this {@link FilePath} exists, * so that one can perform local file operations. */ public <T> T act(final FileCallable<T> callable) throws IOException, InterruptedException { return act(callable,callable.getClass().getClassLoader()); }
/** * Returns the number of usable bytes in the partition of that file. * @since 1.542 */ public long getUsableDiskSpace() throws IOException, InterruptedException { return act(new GetUsableDiskSpace()); } private static class GetUsableDiskSpace extends SecureFileCallable<Long> {
/** * Overwrites this file by placing the given String as the content. * * @param encoding * Null to use the platform default encoding on the remote machine. * @since 1.105 */ public void write(final String content, final String encoding) throws IOException, InterruptedException { act(new Write(encoding, content)); } private class Write extends SecureFileCallable<Void> {
/** * Resolves symlink, if the given file is a symlink. Otherwise return null. * <p> * If the resolution fails, report an error. * * @since 1.456 */ public String readLink() throws IOException, InterruptedException { return act(new ReadLink()); } private class ReadLink extends SecureFileCallable<String> {
/** * Deletes this file. * @throws IOException if it exists but could not be successfully deleted * @return true, for a modicum of compatibility */ public boolean delete() throws IOException, InterruptedException { act(new Delete()); return true; } private class Delete extends SecureFileCallable<Void> {
/** * Checks if the file exists. */ public boolean exists() throws IOException, InterruptedException { return act(new Exists()); } private class Exists extends SecureFileCallable<Boolean> {
private void setLastModifiedIfPossible(final long timestamp) throws IOException, InterruptedException { String message = act(new SetLastModified(timestamp)); if (message!=null) { LOGGER.warning(message); } } private class SetLastModified extends SecureFileCallable<String> {
/** * Returns the total number of bytes in the partition of that file. * @since 1.542 */ public long getTotalDiskSpace() throws IOException, InterruptedException { return act(new GetTotalDiskSpace()); } private static class GetTotalDiskSpace extends SecureFileCallable<Long> {
@Override public Collection<String> list(String includes, String excludes, boolean useDefaultExcludes) throws IOException { try { return f.act(new Scanner(includes, excludes, useDefaultExcludes)); } catch (InterruptedException x) { throw new IOException(x); } } @Override public VirtualFile child(String name) {
/** * Converts this file to the URI, relative to the machine * on which this file is available. */ public URI toURI() throws IOException, InterruptedException { return act(new ToURI()); } private static class ToURI extends SecureFileCallable<URI> {
/** * Creates a file (if not already exist) and sets the timestamp. * * @since 1.299 */ public void touch(final long timestamp) throws IOException, InterruptedException { act(new Touch(timestamp)); } private class Touch extends SecureFileCallable<Void> {
/** * Moves all the contents of this directory into the specified directory, then delete this directory itself. * * @since 1.308. */ public void moveAllChildrenTo(final FilePath target) throws IOException, InterruptedException { if(this.channel != target.channel) { throw new IOException("pullUpTo target must be on the same host"); } act(new MoveAllChildrenTo(target)); } private class MoveAllChildrenTo extends SecureFileCallable<Void> {
/** * Creates this directory. */ public void mkdirs() throws IOException, InterruptedException { if (!act(new Mkdirs())) { throw new IOException("Failed to mkdirs: " + remote); } } private class Mkdirs extends SecureFileCallable<Boolean> {
/** * Deletes all the contents of this directory, but not the directory itself */ public void deleteContents() throws IOException, InterruptedException { act(new DeleteContents()); } private class DeleteContents extends SecureFileCallable<Void> {
/** * Gets the last modified time stamp of this file, by using the clock * of the machine where this file actually resides. * * @see File#lastModified() * @see #touch(long) */ public long lastModified() throws IOException, InterruptedException { return act(new LastModified()); } private class LastModified extends SecureFileCallable<Long> {
/** * Reads this file into a string, by using the current system encoding on the remote machine. */ public String readToString() throws IOException, InterruptedException { return act(new ReadToString()); } private final class ReadToString extends SecureFileCallable<String> {
/** * Computes the MD5 digest of the file in hex string. * @see Util#getDigestOf(File) */ public String digest() throws IOException, InterruptedException { return act(new Digest()); } private class Digest extends SecureFileCallable<String> {
/** * Rename this file/directory to the target filepath. This FilePath and the target must * be on the some host */ public void renameTo(final FilePath target) throws IOException, InterruptedException { if(this.channel != target.channel) { throw new IOException("renameTo target must be on the same host"); } act(new RenameTo(target)); } private class RenameTo extends SecureFileCallable<Void> {
/** * Absolutizes this {@link FilePath} and returns the new one. */ public FilePath absolutize() throws IOException, InterruptedException { return new FilePath(channel, act(new Absolutize())); } private static class Absolutize extends SecureFileCallable<String> {
private void record(Run<?,?> build, FilePath ws, TaskListener listener, Map<String,String> record, final String targets) throws IOException, InterruptedException { for (Record r : ws.act(new FindRecords(targets, build.getTimeInMillis()))) { Fingerprint fp = r.addRecord(build); if(fp==null) { listener.error(Messages.Fingerprinter_FailedFor(r.relativePath)); continue; } fp.addFor(build); record.put(r.relativePath,fp.getHashString()); } }