Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
jenkins
提交
6577d788
J
jenkins
项目概览
xxadev
/
jenkins
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
jenkins
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
6577d788
编写于
4月 15, 2011
作者:
K
Kohsuke Kawaguchi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[FIXED JENKINS-9397] fixed a bug in the implementation, added tests.
上级
00485b31
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
120 addition
and
25 deletion
+120
-25
core/src/main/java/hudson/FilePath.java
core/src/main/java/hudson/FilePath.java
+1
-2
core/src/main/java/hudson/util/IOUtils.java
core/src/main/java/hudson/util/IOUtils.java
+14
-0
core/src/main/java/hudson/util/io/Archiver.java
core/src/main/java/hudson/util/io/Archiver.java
+0
-18
core/src/main/java/hudson/util/io/TarArchiver.java
core/src/main/java/hudson/util/io/TarArchiver.java
+5
-2
core/src/main/java/hudson/util/io/ZipArchiver.java
core/src/main/java/hudson/util/io/ZipArchiver.java
+6
-3
core/src/test/java/hudson/util/io/TarArchiverTest.java
core/src/test/java/hudson/util/io/TarArchiverTest.java
+94
-0
未找到文件。
core/src/main/java/hudson/FilePath.java
浏览文件 @
6577d788
...
...
@@ -48,7 +48,6 @@ import hudson.util.IOUtils;
import
static
hudson
.
util
.
jna
.
GNUCLibrary
.
LIBC
;
import
static
hudson
.
Util
.
fixEmpty
;
import
static
hudson
.
FilePath
.
TarCompression
.
GZIP
;
import
hudson.os.PosixAPI
;
import
hudson.org.apache.tools.tar.TarInputStream
;
import
hudson.util.io.Archiver
;
import
hudson.util.io.ArchiverFactory
;
...
...
@@ -1132,7 +1131,7 @@ public final class FilePath implements Serializable {
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
(
);
return
IOUtils
.
mode
(
f
);
}
});
}
...
...
core/src/main/java/hudson/util/IOUtils.java
浏览文件 @
6577d788
package
hudson.util
;
import
hudson.FilePath.FileCallable
;
import
hudson.Functions
;
import
hudson.os.PosixAPI
;
import
hudson.remoting.VirtualChannel
;
import
java.io.*
;
import
java.util.regex.Pattern
;
...
...
@@ -110,5 +115,14 @@ public class IOUtils extends org.apache.commons.io.IOUtils {
return
path
.
startsWith
(
"/"
)
||
DRIVE_PATTERN
.
matcher
(
path
).
matches
();
}
/**
* Gets the mode of a file/directory, if appropriate. Returns -1 if not on Unix.
*/
public
static
int
mode
(
File
f
)
{
if
(
Functions
.
isWindows
())
return
-
1
;
return
PosixAPI
.
get
().
stat
(
f
.
getPath
()).
mode
();
}
private
static
final
byte
[]
SKIP_BUFFER
=
new
byte
[
8192
];
}
core/src/main/java/hudson/util/io/Archiver.java
浏览文件 @
6577d788
...
...
@@ -24,12 +24,9 @@
package
hudson.util.io
;
import
hudson.Functions
;
import
hudson.os.PosixAPI
;
import
hudson.util.FileVisitor
;
import
java.io.Closeable
;
import
java.io.File
;
/**
* {@link FileVisitor} that creates archive files.
...
...
@@ -46,19 +43,4 @@ public abstract class Archiver extends FileVisitor implements Closeable {
public
int
countEntries
()
{
return
entriesWritten
;
}
/**
* Gets the mode of a file/directory, if appropriate. Returns -1 if not on Unix.
*/
public
int
getPathMode
(
String
p
)
{
// If we're on Windows...
if
(
Functions
.
isWindows
())
{
return
-
1
;
}
// If we're on Unix...
else
{
return
PosixAPI
.
get
().
stat
(
p
).
mode
();
}
}
}
core/src/main/java/hudson/util/io/TarArchiver.java
浏览文件 @
6577d788
...
...
@@ -28,6 +28,7 @@ import hudson.Functions;
import
hudson.org.apache.tools.tar.TarOutputStream
;
import
hudson.util.FileVisitor
;
import
hudson.util.IOException2
;
import
hudson.util.IOUtils
;
import
org.apache.tools.tar.TarEntry
;
import
java.io.BufferedOutputStream
;
...
...
@@ -64,7 +65,8 @@ final class TarArchiver extends Archiver {
@Override
public
void
visitSymlink
(
File
link
,
String
target
,
String
relativePath
)
throws
IOException
{
TarEntry
e
=
new
TarEntry
(
relativePath
,
LF_SYMLINK
);
e
.
setMode
(
getPathMode
(
link
.
getPath
()));
int
mode
=
IOUtils
.
mode
(
link
);
if
(
mode
!=-
1
)
e
.
setMode
(
mode
);
try
{
StringBuffer
linkName
=
(
StringBuffer
)
LINKNAME_FIELD
.
get
(
e
);
...
...
@@ -90,7 +92,8 @@ final class TarArchiver extends Archiver {
if
(
file
.
isDirectory
())
relativePath
+=
'/'
;
TarEntry
te
=
new
TarEntry
(
relativePath
);
te
.
setMode
(
getPathMode
(
file
.
getPath
()));
int
mode
=
IOUtils
.
mode
(
file
);
if
(
mode
!=-
1
)
te
.
setMode
(
mode
);
te
.
setModTime
(
file
.
lastModified
());
if
(!
file
.
isDirectory
())
te
.
setSize
(
file
.
length
());
...
...
core/src/main/java/hudson/util/io/ZipArchiver.java
浏览文件 @
6577d788
...
...
@@ -25,6 +25,7 @@
package
hudson.util.io
;
import
hudson.util.FileVisitor
;
import
hudson.util.IOUtils
;
import
org.apache.tools.zip.ZipEntry
;
import
org.apache.tools.zip.ZipOutputStream
;
...
...
@@ -48,16 +49,18 @@ final class ZipArchiver extends Archiver {
}
public
void
visit
(
File
f
,
String
relativePath
)
throws
IOException
{
int
mode
=
IOUtils
.
mode
(
f
);
if
(
f
.
isDirectory
())
{
ZipEntry
dirZipEntry
=
new
ZipEntry
(
relativePath
+
'/'
);
dirZipEntry
.
setUnixMode
(
getPathMode
(
f
.
getPath
()));
// Setting this bit explicitly is needed by some unzipping applications (see HUDSON-3294).
// Setting this bit explicitly is needed by some unzipping applications (see JENKINS-3294).
dirZipEntry
.
setExternalAttributes
(
BITMASK_IS_DIRECTORY
);
if
(
mode
!=-
1
)
dirZipEntry
.
setUnixMode
(
mode
);
zip
.
putNextEntry
(
dirZipEntry
);
zip
.
closeEntry
();
}
else
{
ZipEntry
fileZipEntry
=
new
ZipEntry
(
relativePath
);
fileZipEntry
.
setUnixMode
(
getPathMode
(
f
.
getPath
())
);
if
(
mode
!=-
1
)
fileZipEntry
.
setUnixMode
(
mode
);
zip
.
putNextEntry
(
fileZipEntry
);
FileInputStream
in
=
new
FileInputStream
(
f
);
int
len
;
...
...
core/src/test/java/hudson/util/io/TarArchiverTest.java
0 → 100644
浏览文件 @
6577d788
/*
* The MIT License
*
* Copyright (c) 2011, CloudBees, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package
hudson.util.io
;
import
hudson.FilePath
;
import
hudson.Functions
;
import
hudson.Launcher.LocalLauncher
;
import
hudson.util.StreamTaskListener
;
import
junit.framework.TestCase
;
import
org.jvnet.hudson.test.Bug
;
import
java.io.File
;
import
java.io.FileOutputStream
;
/**
* @author Kohsuke Kawaguchi
*/
public
class
TarArchiverTest
extends
TestCase
{
/**
* Makes sure that permissions are properly stored in the tar file.
*/
@Bug
(
9397
)
public
void
testPermission
()
throws
Exception
{
if
(
Functions
.
isWindows
())
return
;
// can't test on Windows
File
tar
=
new
File
(
"test.tar"
);
File
zip
=
new
File
(
"test.zip"
);
FilePath
dir
=
new
FilePath
(
File
.
createTempFile
(
"test"
,
"dir"
));
try
{
dir
.
delete
();
dir
.
child
(
"subdir"
).
mkdirs
();
FilePath
f
=
dir
.
child
(
"a.txt"
);
f
.
touch
(
0
);
f
.
chmod
(
0755
);
f
=
dir
.
child
(
"subdir/b.txt"
);
f
.
touch
(
0
);
f
.
chmod
(
0644
);
int
dirMode
=
dir
.
child
(
"subdir"
).
mode
();
dir
.
tar
(
new
FileOutputStream
(
tar
),
"**/*"
);
dir
.
zip
(
new
FileOutputStream
(
zip
));
FilePath
e
=
dir
.
child
(
"extract"
);
e
.
mkdirs
();
// extract via the tar command
assertEquals
(
0
,
new
LocalLauncher
(
new
StreamTaskListener
(
System
.
out
)).
launch
().
cmds
(
"tar"
,
"xvf"
,
tar
.
getAbsolutePath
()).
pwd
(
e
).
join
());
assertEquals
(
0100755
,
e
.
child
(
"a.txt"
).
mode
());
assertEquals
(
dirMode
,
e
.
child
(
"subdir"
).
mode
());
assertEquals
(
0100644
,
e
.
child
(
"subdir/b.txt"
).
mode
());
// extract via the zip command
e
.
deleteContents
();
assertEquals
(
0
,
new
LocalLauncher
(
new
StreamTaskListener
(
System
.
out
)).
launch
().
cmds
(
"unzip"
,
zip
.
getAbsolutePath
()).
pwd
(
e
).
join
());
e
=
e
.
listDirectories
().
get
(
0
);
assertEquals
(
0100755
,
e
.
child
(
"a.txt"
).
mode
());
assertEquals
(
dirMode
,
e
.
child
(
"subdir"
).
mode
());
assertEquals
(
0100644
,
e
.
child
(
"subdir/b.txt"
).
mode
());
}
finally
{
tar
.
delete
();
zip
.
delete
();
dir
.
delete
();
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录