diff --git a/core/src/main/java/hudson/FilePath.java b/core/src/main/java/hudson/FilePath.java index 2f21b2cd5d..49f6037655 100644 --- a/core/src/main/java/hudson/FilePath.java +++ b/core/src/main/java/hudson/FilePath.java @@ -139,6 +139,7 @@ import static hudson.Util.isSymlink; import java.util.Collections; import org.apache.tools.ant.BuildException; +import org.kohsuke.accmod.restrictions.Beta; /** * {@link File} like object with remoting support. @@ -903,6 +904,28 @@ public final class FilePath implements Serializable { } } + /** + * Copies the content of a URL to a remote file. + * Unlike {@link #copyFrom} this will not transfer content over a Remoting channel. + * @since FIXME + */ + @Restricted(Beta.class) + public void copyFromRemotely(URL url) throws IOException, InterruptedException { + act(new CopyFromRemotely(url)); + } + private final class CopyFromRemotely extends MasterToSlaveFileCallable { + private static final long serialVersionUID = 1; + private final URL url; + CopyFromRemotely(URL url) { + this.url = url; + } + @Override + public Void invoke(File f, VirtualChannel channel) throws IOException, InterruptedException { + copyFrom(url); + return null; + } + } + /** * Replaces the content of this file by the data from the given {@link InputStream}. * diff --git a/core/src/main/java/jenkins/util/VirtualFile.java b/core/src/main/java/jenkins/util/VirtualFile.java index 9427bbd85e..e59ad888bd 100644 --- a/core/src/main/java/jenkins/util/VirtualFile.java +++ b/core/src/main/java/jenkins/util/VirtualFile.java @@ -95,8 +95,7 @@ import org.kohsuke.accmod.restrictions.Beta; * would wind up transferring the file from the service to the Jenkins master and then on to an agent. * Similarly, if {@link DirectoryBrowserSupport} rendered a link to an in-Jenkins URL, * a large file could be transferred from the service to the Jenkins master and then on to the browser. - * To avoid this overhead, callers may check whether an implementation - * supports {@link #asRemotable} and/or {@link #toExternalURL}. + * To avoid this overhead, callers may check whether an implementation supports {@link #toExternalURL}. * * @see DirectoryBrowserSupport * @see FilePath @@ -334,24 +333,6 @@ public abstract class VirtualFile implements Comparable, Serializab return callable.call(); } - /** - * Optionally produces a variant of this handle which may be safely passed over a Remoting {@link Channel}. - * This would allow remote nodes such as agents to make calls such as {@link #open} - * and be assured of the most efficient possible access. - * Otherwise, all calls must be made on the node originally producing this object, - * and the caller must arrange for transport of the result. - *

Note that the result of {@link #forFilePath} does not implement this method, - * since a {@link FilePath} may only be transferred over the channel on which it was created. - * It cannot, for example, be used to represent a workspace file from one agent on another agent. - * @return this object or a variant which may be passed over a {@link Channel}, or null if there is no such support - * @since FIXME - * @see #toExternalURL - */ - @Restricted(Beta.class) - public @CheckForNull VirtualFile asRemotable() { - return null; - } - /** * Optionally obtains a URL which may be used to retrieve file contents from any process on any node. * For example, given cloud storage this might produce a permalink to the file. @@ -360,15 +341,12 @@ public abstract class VirtualFile implements Comparable, Serializab *

Any necessary authentication must be encoded somehow into the URL itself; * do not include any tokens or other authentication which might allow access to unrelated files * (for example {@link ArtifactManager} builds from a different job). - * The URL might be valid for only a limited amount of time or even only a single use; + * Authentication should be limited to download, not upload or any other modifications. + *

The URL might be valid for only a limited amount of time or even only a single use; * this method should be called anew every time an external URL is required. - *

Generally this will be harder to implement than {@link #asRemotable}, - * which would have the opportunity to perform arbitrary preparation for {@link #open} - * such as negotiating session authentication. * @return an externally usable URL like {@code https://gist.githubusercontent.com/ACCT/GISTID/raw/COMMITHASH/FILE}, or null if there is no such support * @since FIXME * @see #toURI - * @see #asRemotable */ @Restricted(Beta.class) public @CheckForNull URL toExternalURL() throws IOException {