Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
163fe694
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
3
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_jdk
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
163fe694
编写于
1月 19, 2015
作者:
S
sherman
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8064601: Improve jar file handling
Reviewed-by: alanb, ahgross
上级
926a5baf
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
71 addition
and
15 deletion
+71
-15
src/share/classes/sun/tools/jar/Main.java
src/share/classes/sun/tools/jar/Main.java
+69
-14
src/share/classes/sun/tools/jar/resources/jar.properties
src/share/classes/sun/tools/jar/resources/jar.properties
+2
-1
未找到文件。
src/share/classes/sun/tools/jar/Main.java
浏览文件 @
163fe694
...
...
@@ -74,8 +74,10 @@ class Main {
* Mflag: DO NOT generate a manifest file (just ZIP)
* iflag: generate jar index
* nflag: Perform jar normalization at the end
* pflag: preserve/don't strip leading slash and .. component from file name
*
*/
boolean
cflag
,
uflag
,
xflag
,
tflag
,
vflag
,
flag0
,
Mflag
,
iflag
,
nflag
;
boolean
cflag
,
uflag
,
xflag
,
tflag
,
vflag
,
flag0
,
Mflag
,
iflag
,
nflag
,
pflag
;
static
final
String
MANIFEST_DIR
=
"META-INF/"
;
static
final
String
VERSION
=
"1.0"
;
...
...
@@ -187,6 +189,7 @@ class Main {
addMainClass
(
manifest
,
ename
);
}
}
expand
(
null
,
files
,
false
);
OutputStream
out
;
if
(
fname
!=
null
)
{
out
=
new
FileOutputStream
(
fname
);
...
...
@@ -208,13 +211,12 @@ class Main {
tmpfile
=
createTemporaryFile
(
tmpbase
,
".jar"
);
out
=
new
FileOutputStream
(
tmpfile
);
}
expand
(
null
,
files
,
false
);
create
(
new
BufferedOutputStream
(
out
,
4096
),
manifest
);
if
(
in
!=
null
)
{
in
.
close
();
}
out
.
close
();
if
(
nflag
)
{
if
(
nflag
)
{
JarFile
jarFile
=
null
;
File
packFile
=
null
;
JarOutputStream
jos
=
null
;
...
...
@@ -291,7 +293,7 @@ class Main {
list
(
fname
,
files
);
}
else
{
InputStream
in
=
new
FileInputStream
(
FileDescriptor
.
in
);
try
{
try
{
list
(
new
BufferedInputStream
(
in
),
files
);
}
finally
{
in
.
close
();
...
...
@@ -410,6 +412,9 @@ class Main {
case
'e'
:
ename
=
args
[
count
++];
break
;
case
'P'
:
pflag
=
true
;
break
;
default
:
error
(
formatMsg
(
"error.illegal.option"
,
String
.
valueOf
(
flags
.
charAt
(
i
))));
...
...
@@ -662,7 +667,6 @@ class Main {
return
updateOk
;
}
private
void
addIndex
(
JarIndex
index
,
ZipOutputStream
zos
)
throws
IOException
{
...
...
@@ -699,6 +703,47 @@ class Main {
return
true
;
}
private
static
final
boolean
isWinDriveLetter
(
char
c
)
{
return
((
c
>=
'a'
)
&&
(
c
<=
'z'
))
||
((
c
>=
'A'
)
&&
(
c
<=
'Z'
));
}
private
String
safeName
(
String
name
)
{
if
(!
pflag
)
{
int
len
=
name
.
length
();
int
i
=
name
.
lastIndexOf
(
"../"
);
if
(
i
==
-
1
)
{
i
=
0
;
}
else
{
i
+=
3
;
// strip any dot-dot components
}
if
(
File
.
separatorChar
==
'\\'
)
{
// the spec requests no drive letter. skip if
// the entry name has one.
while
(
i
<
len
)
{
int
off
=
i
;
if
(
i
+
1
<
len
&&
name
.
charAt
(
i
+
1
)
==
':'
&&
isWinDriveLetter
(
name
.
charAt
(
i
)))
{
i
+=
2
;
}
while
(
i
<
len
&&
name
.
charAt
(
i
)
==
'/'
)
{
i
++;
}
if
(
i
==
off
)
{
break
;
}
}
}
else
{
while
(
i
<
len
&&
name
.
charAt
(
i
)
==
'/'
)
{
i
++;
}
}
if
(
i
!=
0
)
{
name
=
name
.
substring
(
i
);
}
}
return
name
;
}
private
String
entryName
(
String
name
)
{
name
=
name
.
replace
(
File
.
separatorChar
,
'/'
);
...
...
@@ -710,10 +755,10 @@ class Main {
}
}
name
=
name
.
substring
(
matchPath
.
length
());
if
(
name
.
startsWith
(
"/"
))
{
name
=
name
.
substring
(
1
);
}
else
if
(
name
.
startsWith
(
"./"
))
{
name
=
safeName
(
name
);
// the old implementaton doesn't remove
// "./" if it was led by "/" (?)
if
(
name
.
startsWith
(
"./"
))
{
name
=
name
.
substring
(
2
);
}
return
name
;
...
...
@@ -913,8 +958,11 @@ class Main {
for
(
ZipEntry
ze
:
zes
)
{
long
lastModified
=
ze
.
getTime
();
if
(
lastModified
!=
-
1
)
{
File
f
=
new
File
(
ze
.
getName
().
replace
(
'/'
,
File
.
separatorChar
));
f
.
setLastModified
(
lastModified
);
String
name
=
safeName
(
ze
.
getName
().
replace
(
File
.
separatorChar
,
'/'
));
if
(
name
.
length
()
!=
0
)
{
File
f
=
new
File
(
name
.
replace
(
'/'
,
File
.
separatorChar
));
f
.
setLastModified
(
lastModified
);
}
}
}
}
...
...
@@ -958,7 +1006,6 @@ class Main {
Enumeration
<?
extends
ZipEntry
>
zes
=
zf
.
entries
();
while
(
zes
.
hasMoreElements
())
{
ZipEntry
e
=
zes
.
nextElement
();
InputStream
is
;
if
(
files
==
null
)
{
dirs
.
add
(
extractFile
(
zf
.
getInputStream
(
e
),
e
));
}
else
{
...
...
@@ -982,8 +1029,16 @@ class Main {
*/
ZipEntry
extractFile
(
InputStream
is
,
ZipEntry
e
)
throws
IOException
{
ZipEntry
rc
=
null
;
String
name
=
e
.
getName
();
File
f
=
new
File
(
e
.
getName
().
replace
(
'/'
,
File
.
separatorChar
));
// The spec requres all slashes MUST be forward '/', it is possible
// an offending zip/jar entry may uses the backwards slash in its
// name. It might cause problem on Windows platform as it skips
// our "safe" check for leading slahs and dot-dot. So replace them
// with '/'.
String
name
=
safeName
(
e
.
getName
().
replace
(
File
.
separatorChar
,
'/'
));
if
(
name
.
length
()
==
0
)
{
return
rc
;
// leading '/' or 'dot-dot' only path
}
File
f
=
new
File
(
name
.
replace
(
'/'
,
File
.
separatorChar
));
if
(
e
.
isDirectory
())
{
if
(
f
.
exists
())
{
if
(!
f
.
isDirectory
())
{
...
...
src/share/classes/sun/tools/jar/resources/jar.properties
浏览文件 @
163fe694
...
...
@@ -68,7 +68,7 @@ out.size=\
(in = {0}) (out= {1})
usage
=
\
Usage: jar {ctxui}[vfmn0Me] [jar-file] [manifest-file] [entry-point] [-C dir] files ...
\n\
Usage: jar {ctxui}[vfmn0
P
Me] [jar-file] [manifest-file] [entry-point] [-C dir] files ...
\n\
Options:
\n\
\ \
-c create new archive
\n\
\ \
-t list table of contents for archive
\n\
...
...
@@ -81,6 +81,7 @@ Options:\n\
\ \
-e specify application entry point for stand-alone application
\n\
\ \
bundled into an executable jar file
\n\
\ \
-0 store only; use no ZIP compression
\n\
\ \
-P preserve leading '/' (absolute path) and ".." (parent directory) components from file names
\n\
\ \
-M do not create a manifest file for the entries
\n\
\ \
-i generate index information for the specified jar files
\n\
\ \
-C change to the specified directory and include the following file
\n\
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录