提交 00cf9f43 编写于 作者: K kohsuke

copy a file with permissions

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@18899 71c3de6d-444a-0410-be80-ed276b4c234a
上级 b172a606
......@@ -318,6 +318,11 @@ THE SOFTWARE.
</exclusions>
</dependency>
<dependency>
<groupId>org.jruby.ext.posix</groupId>
<artifactId>jna-posix</artifactId>
<version>1.0.1</version>
</dependency>
<dependency>
<groupId>org.jvnet.hudson.svnkit</groupId>
<artifactId>svnkit</artifactId>
......
......@@ -43,6 +43,7 @@ import hudson.util.FormValidation;
import static hudson.util.jna.GNUCLibrary.LIBC;
import static hudson.Util.fixEmpty;
import static hudson.FilePath.TarCompression.GZIP;
import hudson.os.PosixAPI;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Project;
......@@ -938,10 +939,14 @@ public final class FilePath implements Serializable {
*
* On Windows, no-op.
*
* @param mask
* File permission mask. To simplify the permission copying,
* if the parameter is -1, this method becomes no-op.
* @since 1.303
* @see #mode()
*/
public void chmod(final int mask) throws IOException, InterruptedException {
if(!isUnix()) return;
if(!isUnix() || mask==-1) return;
act(new FileCallable<Void>() {
public Void invoke(File f, VirtualChannel channel) throws IOException {
if(LIBC.chmod(f.getAbsolutePath(),mask)!=0)
......@@ -951,6 +956,23 @@ public final class FilePath implements Serializable {
});
}
/**
* Gets the file permission bit mask.
*
* @return
* -1 on Windows, since such a concept doesn't make sense.
* @since 1.311
* @see #chmod(int)
*/
public int mode() throws IOException, InterruptedException {
if(!isUnix()) return -1;
return act(new FileCallable<Integer>() {
public Integer invoke(File f, VirtualChannel channel) throws IOException {
return PosixAPI.get().stat(f.getPath()).mode();
}
});
}
/**
* List up files and directories in this directory.
*
......@@ -1186,6 +1208,16 @@ public final class FilePath implements Serializable {
}
}
/**
* Copies this file to the specified target, with file permissions intact.
* @since 1.311
*/
public void copyToWithPermission(FilePath target) throws IOException, InterruptedException {
copyToWithPermission(target);
// copy file permission
target.chmod(mode());
}
/**
* Sends the contents of this file into the given {@link OutputStream}.
*/
......
package hudson.os;
import org.jruby.ext.posix.POSIX;
import org.jruby.ext.posix.POSIXFactory;
import org.jruby.ext.posix.POSIXHandler;
import org.jruby.ext.posix.POSIX.ERRORS;
import java.io.File;
import java.io.InputStream;
import java.io.PrintStream;
import java.util.logging.Logger;
/**
* POSIX API wrapper.
*
* @author Kohsuke Kawaguchi
*/
public class PosixAPI {
public static POSIX get() {
return posix;
}
private static final POSIX posix = POSIXFactory.getPOSIX(new POSIXHandler() {
public void error(ERRORS errors, String s) {
throw new RuntimeException(s+" "+errors);
}
public void unimplementedError(String s) {
throw new UnsupportedOperationException(s);
}
public void warn(WARNING_ID warning_id, String s, Object... objects) {
LOGGER.fine(s);
}
public boolean isVerbose() {
return false;
}
public File getCurrentWorkingDirectory() {
// TODO
throw new UnsupportedOperationException();
}
public String[] getEnv() {
// TODO
throw new UnsupportedOperationException();
}
public InputStream getInputStream() {
// TODO
throw new UnsupportedOperationException();
}
public PrintStream getOutputStream() {
// TODO
throw new UnsupportedOperationException();
}
public int getPID() {
// TODO
throw new UnsupportedOperationException();
}
public PrintStream getErrorStream() {
// TODO
throw new UnsupportedOperationException();
}
}, true);
private static final Logger LOGGER = Logger.getLogger(PosixAPI.class.getName());
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册