Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
a493688b
V
vscode
项目概览
xxadev
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
a493688b
编写于
8月 22, 2018
作者:
B
Benjamin Pasero
提交者:
GitHub
8月 22, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Debt: avoid promise.cancel in zip.ts (#56656)
* avoid promise.cancel * use token properly
上级
e0a68266
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
96 addition
and
58 deletion
+96
-58
src/vs/base/node/extfs.ts
src/vs/base/node/extfs.ts
+7
-1
src/vs/base/node/zip.ts
src/vs/base/node/zip.ts
+71
-55
src/vs/base/test/node/extfs/extfs.test.ts
src/vs/base/test/node/extfs/extfs.test.ts
+18
-2
未找到文件。
src/vs/base/node/extfs.ts
浏览文件 @
a493688b
...
...
@@ -15,6 +15,7 @@ import * as uuid from 'vs/base/common/uuid';
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
encode
,
encodeStream
}
from
'
vs/base/node/encoding
'
;
import
*
as
flow
from
'
vs/base/node/flow
'
;
import
{
CancellationToken
}
from
'
vs/base/common/cancellation
'
;
const
loop
=
flow
.
loop
;
...
...
@@ -129,7 +130,7 @@ function doCopyFile(source: string, target: string, mode: number, callback: (err
reader
.
pipe
(
writer
);
}
export
function
mkdirp
(
path
:
string
,
mode
?:
number
):
TPromise
<
boolean
>
{
export
function
mkdirp
(
path
:
string
,
mode
?:
number
,
token
?:
CancellationToken
):
TPromise
<
boolean
>
{
const
mkdir
=
()
=>
{
return
nfcall
(
fs
.
mkdir
,
path
,
mode
).
then
(
null
,
(
mkdirErr
:
NodeJS
.
ErrnoException
)
=>
{
...
...
@@ -160,6 +161,11 @@ export function mkdirp(path: string, mode?: number): TPromise<boolean> {
// recursively mkdir
return
mkdir
().
then
(
null
,
(
err
:
NodeJS
.
ErrnoException
)
=>
{
// Respect cancellation
if
(
token
&&
token
.
isCancellationRequested
)
{
return
TPromise
.
as
(
false
);
}
// ENOENT: a parent folder does not exist yet, continue
// to create the parent folder and then try again.
if
(
err
.
code
===
'
ENOENT
'
)
{
...
...
src/vs/base/node/zip.ts
浏览文件 @
a493688b
...
...
@@ -7,12 +7,14 @@ import * as nls from 'vs/nls';
import
*
as
path
from
'
path
'
;
import
{
createWriteStream
,
WriteStream
}
from
'
fs
'
;
import
{
Readable
}
from
'
stream
'
;
import
{
nfcall
,
ninvoke
,
SimpleThrottler
}
from
'
vs/base/common/async
'
;
import
{
nfcall
,
ninvoke
,
SimpleThrottler
,
createCancelablePromise
,
CancelablePromise
}
from
'
vs/base/common/async
'
;
import
{
mkdirp
,
rimraf
}
from
'
vs/base/node/pfs
'
;
import
{
TPromise
}
from
'
vs/base/common/winjs.base
'
;
import
{
open
as
_openZip
,
Entry
,
ZipFile
}
from
'
yauzl
'
;
import
*
as
yazl
from
'
yazl
'
;
import
{
ILogService
}
from
'
vs/platform/log/common/log
'
;
import
{
CancellationToken
}
from
'
vs/base/common/cancellation
'
;
import
{
once
}
from
'
vs/base/common/event
'
;
export
interface
IExtractOptions
{
overwrite
?:
boolean
;
...
...
@@ -70,7 +72,7 @@ function toExtractError(err: Error): ExtractError {
return
new
ExtractError
(
type
,
err
);
}
function
extractEntry
(
stream
:
Readable
,
fileName
:
string
,
mode
:
number
,
targetPath
:
string
,
options
:
IOptions
):
TPromise
<
void
>
{
function
extractEntry
(
stream
:
Readable
,
fileName
:
string
,
mode
:
number
,
targetPath
:
string
,
options
:
IOptions
,
token
:
CancellationToken
):
TPromise
<
void
>
{
const
dirName
=
path
.
dirname
(
fileName
);
const
targetDirName
=
path
.
join
(
targetPath
,
dirName
);
if
(
targetDirName
.
indexOf
(
targetPath
)
!==
0
)
{
...
...
@@ -79,35 +81,53 @@ function extractEntry(stream: Readable, fileName: string, mode: number, targetPa
const
targetFileName
=
path
.
join
(
targetPath
,
fileName
);
let
istream
:
WriteStream
;
return
mkdirp
(
targetDirName
).
then
(()
=>
new
TPromise
((
c
,
e
)
=>
{
once
(
token
.
onCancellationRequested
)(()
=>
{
if
(
istream
)
{
istream
.
close
();
}
});
return
mkdirp
(
targetDirName
,
void
0
,
token
).
then
(()
=>
new
TPromise
((
c
,
e
)
=>
{
if
(
token
.
isCancellationRequested
)
{
return
;
}
istream
=
createWriteStream
(
targetFileName
,
{
mode
});
istream
.
once
(
'
close
'
,
()
=>
c
(
null
));
istream
.
once
(
'
error
'
,
e
);
stream
.
once
(
'
error
'
,
e
);
stream
.
pipe
(
istream
);
},
()
=>
{
if
(
istream
)
{
istream
.
close
();
}
}));
}
function
extractZip
(
zipfile
:
ZipFile
,
targetPath
:
string
,
options
:
IOptions
,
logService
:
ILogService
):
TPromise
<
void
>
{
let
isCanceled
=
false
;
let
last
=
TPromise
.
wrap
<
any
>
(
null
);
function
extractZip
(
zipfile
:
ZipFile
,
targetPath
:
string
,
options
:
IOptions
,
logService
:
ILogService
):
CancelablePromise
<
void
>
{
let
last
=
createCancelablePromise
(()
=>
Promise
.
resolve
(
null
));
let
extractedEntriesCount
=
0
;
return
createCancelablePromise
(
token
=>
{
once
(
token
.
onCancellationRequested
)(()
=>
{
logService
.
debug
(
targetPath
,
'
Cancelled.
'
);
last
.
cancel
();
zipfile
.
close
();
});
return
new
TPromise
((
c
,
e
)
=>
{
const
throttler
=
new
SimpleThrottler
();
const
readNextEntry
=
()
=>
{
const
readNextEntry
=
(
token
:
CancellationToken
)
=>
{
if
(
token
.
isCancellationRequested
)
{
return
;
}
extractedEntriesCount
++
;
zipfile
.
readEntry
();
};
zipfile
.
once
(
'
error
'
,
e
);
zipfile
.
once
(
'
close
'
,
()
=>
last
.
then
(()
=>
{
if
(
isCancel
ed
||
zipfile
.
entryCount
===
extractedEntriesCount
)
{
if
(
token
.
isCancellationRequest
ed
||
zipfile
.
entryCount
===
extractedEntriesCount
)
{
c
(
null
);
}
else
{
e
(
new
ExtractError
(
'
Incomplete
'
,
new
Error
(
nls
.
localize
(
'
incompleteExtract
'
,
"
Incomplete. Found {0} of {1} entries
"
,
extractedEntriesCount
,
zipfile
.
entryCount
))));
...
...
@@ -116,12 +136,12 @@ function extractZip(zipfile: ZipFile, targetPath: string, options: IOptions, log
zipfile
.
readEntry
();
zipfile
.
on
(
'
entry
'
,
(
entry
:
Entry
)
=>
{
if
(
isCancel
ed
)
{
if
(
token
.
isCancellationRequest
ed
)
{
return
;
}
if
(
!
options
.
sourcePathRegex
.
test
(
entry
.
fileName
))
{
readNextEntry
(
);
readNextEntry
(
token
);
return
;
}
...
...
@@ -130,21 +150,17 @@ function extractZip(zipfile: ZipFile, targetPath: string, options: IOptions, log
// directory file names end with '/'
if
(
/
\/
$/
.
test
(
fileName
))
{
const
targetFileName
=
path
.
join
(
targetPath
,
fileName
);
last
=
mkdirp
(
targetFileName
).
then
(()
=>
readNextEntry
(
));
last
=
createCancelablePromise
(
token
=>
mkdirp
(
targetFileName
,
void
0
,
token
).
then
(()
=>
readNextEntry
(
token
)
));
return
;
}
const
stream
=
ninvoke
(
zipfile
,
zipfile
.
openReadStream
,
entry
);
const
mode
=
modeFromEntry
(
entry
);
last
=
throttler
.
queue
(()
=>
stream
.
then
(
stream
=>
extractEntry
(
stream
,
fileName
,
mode
,
targetPath
,
options
).
then
(()
=>
readNextEntry
())));
last
=
createCancelablePromise
(
token
=>
throttler
.
queue
(()
=>
stream
.
then
(
stream
=>
extractEntry
(
stream
,
fileName
,
mode
,
targetPath
,
options
,
token
).
then
(()
=>
readNextEntry
(
token
)))));
});
});
});
},
()
=>
{
logService
.
debug
(
targetPath
,
'
Cancelled.
'
);
isCanceled
=
true
;
last
.
cancel
();
zipfile
.
close
();
}).
then
(
null
,
err
=>
TPromise
.
wrapError
(
toExtractError
(
err
)));
}
function
openZip
(
zipFile
:
string
,
lazy
:
boolean
=
false
):
TPromise
<
ZipFile
>
{
...
...
src/vs/base/test/node/extfs/extfs.test.ts
浏览文件 @
a493688b
...
...
@@ -15,8 +15,7 @@ import { isLinux, isWindows } from 'vs/base/common/platform';
import
*
as
uuid
from
'
vs/base/common/uuid
'
;
import
*
as
extfs
from
'
vs/base/node/extfs
'
;
import
{
getPathFromAmdModule
}
from
'
vs/base/common/amd
'
;
import
{
CancellationTokenSource
}
from
'
vs/base/common/cancellation
'
;
const
ignore
=
()
=>
{
};
...
...
@@ -564,4 +563,21 @@ suite('Extfs', () => {
extfs
.
del
(
parentDir
,
os
.
tmpdir
(),
done
,
ignore
);
});
});
test
(
'
mkdirp cancellation
'
,
(
done
)
=>
{
const
id
=
uuid
.
generateUuid
();
const
parentDir
=
path
.
join
(
os
.
tmpdir
(),
'
vsctests
'
,
id
);
const
newDir
=
path
.
join
(
parentDir
,
'
extfs
'
,
id
);
const
source
=
new
CancellationTokenSource
();
const
mkdirpPromise
=
extfs
.
mkdirp
(
newDir
,
493
,
source
.
token
);
source
.
cancel
();
return
mkdirpPromise
.
then
(
res
=>
{
assert
.
equal
(
res
,
false
);
extfs
.
del
(
parentDir
,
os
.
tmpdir
(),
done
,
ignore
);
});
});
});
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录