Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
deno
提交
88d42f0b
D
deno
项目概览
张重言
/
deno
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
deno
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
88d42f0b
编写于
9月 12, 2018
作者:
M
Mani Maghsoudlou
提交者:
Ryan Dahl
9月 12, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Implement deno.rename() (#731)
上级
26081a32
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
118 addition
and
65 deletion
+118
-65
BUILD.gn
BUILD.gn
+2
-0
js/deno.ts
js/deno.ts
+6
-1
js/os.ts
js/os.ts
+0
-19
js/os_test.ts
js/os_test.ts
+0
-37
js/rename.ts
js/rename.ts
+42
-0
js/rename_test.ts
js/rename_test.ts
+60
-0
js/unit_tests.ts
js/unit_tests.ts
+1
-0
src/handlers.rs
src/handlers.rs
+5
-6
src/msg.fbs
src/msg.fbs
+2
-2
未找到文件。
BUILD.gn
浏览文件 @
88d42f0b
...
...
@@ -199,6 +199,7 @@ run_node("gen_declarations") {
"js/mkdir.ts",
"js/os.ts",
"js/read_file.ts",
"js/rename.ts",
"js/remove.ts",
"js/stat.ts",
"js/text_encoding.ts",
...
...
@@ -242,6 +243,7 @@ run_node("bundle") {
"js/os.ts",
"js/plugins.d.ts",
"js/read_file.ts",
"js/rename.ts",
"js/remove.ts",
"js/stat.ts",
"js/text_encoding.ts",
...
...
js/deno.ts
浏览文件 @
88d42f0b
// Copyright 2018 the Deno authors. All rights reserved. MIT license.
// Public deno module.
/// <amd-module name="deno"/>
export
{
env
,
exit
,
makeTempDirSync
,
renameSync
}
from
"
./os
"
;
export
{
env
,
exit
,
makeTempDirSync
}
from
"
./os
"
;
export
{
mkdirSync
,
mkdir
}
from
"
./mkdir
"
;
export
{
removeSync
,
remove
,
removeAllSync
,
removeAll
}
from
"
./remove
"
;
export
{
readFileSync
,
readFile
}
from
"
./read_file
"
;
export
{
renameSync
,
rename
}
from
"
./rename
"
;
export
{
FileInfo
,
statSync
,
lstatSync
,
stat
,
lstat
}
from
"
./stat
"
;
export
{
writeFileSync
,
writeFile
}
from
"
./write_file
"
;
export
{
ErrorKind
,
DenoError
}
from
"
./errors
"
;
...
...
js/os.ts
浏览文件 @
88d42f0b
...
...
@@ -164,22 +164,3 @@ export function env(): { [index: string]: string } {
// TypeScript cannot track assertion above, therefore not null assertion
return
createEnv
(
res
);
}
/**
* Renames (moves) oldpath to newpath.
* import { renameSync } from "deno";
* const oldpath = 'from/path';
* const newpath = 'to/path';
*
* renameSync(oldpath, newpath);
*/
export
function
renameSync
(
oldpath
:
string
,
newpath
:
string
):
void
{
const
builder
=
new
flatbuffers
.
Builder
();
const
_oldpath
=
builder
.
createString
(
oldpath
);
const
_newpath
=
builder
.
createString
(
newpath
);
fbs
.
RenameSync
.
startRenameSync
(
builder
);
fbs
.
RenameSync
.
addOldpath
(
builder
,
_oldpath
);
fbs
.
RenameSync
.
addNewpath
(
builder
,
_newpath
);
const
msg
=
fbs
.
RenameSync
.
endRenameSync
(
builder
);
sendSync
(
builder
,
fbs
.
Any
.
RenameSync
,
msg
);
}
js/os_test.ts
浏览文件 @
88d42f0b
...
...
@@ -60,40 +60,3 @@ test(function makeTempDirSyncPerm() {
assertEqual
(
err
.
kind
,
deno
.
ErrorKind
.
PermissionDenied
);
assertEqual
(
err
.
name
,
"
PermissionDenied
"
);
});
testPerm
({
write
:
true
},
function
renameSync
()
{
const
testDir
=
deno
.
makeTempDirSync
()
+
"
/test-rename
"
;
const
oldpath
=
testDir
+
"
/oldpath
"
;
const
newpath
=
testDir
+
"
/newpath
"
;
deno
.
mkdirSync
(
oldpath
);
deno
.
renameSync
(
oldpath
,
newpath
);
const
newPathInfo
=
deno
.
statSync
(
newpath
);
assert
(
newPathInfo
.
isDirectory
());
let
caughtErr
=
false
;
let
oldPathInfo
;
try
{
oldPathInfo
=
deno
.
statSync
(
oldpath
);
}
catch
(
err
)
{
caughtErr
=
true
;
assertEqual
(
err
.
kind
,
deno
.
ErrorKind
.
NotFound
);
assertEqual
(
err
.
name
,
"
NotFound
"
);
}
assert
(
caughtErr
);
assertEqual
(
oldPathInfo
,
undefined
);
});
test
(
function
renameSyncPerm
()
{
let
err
;
try
{
const
oldpath
=
"
/oldbaddir
"
;
const
newpath
=
"
/newbaddir
"
;
deno
.
renameSync
(
oldpath
,
newpath
);
}
catch
(
err_
)
{
err
=
err_
;
}
assertEqual
(
err
.
kind
,
deno
.
ErrorKind
.
PermissionDenied
);
assertEqual
(
err
.
name
,
"
PermissionDenied
"
);
});
js/rename.ts
0 → 100644
浏览文件 @
88d42f0b
// Copyright 2018 the Deno authors. All rights reserved. MIT license.
import
*
as
fbs
from
"
gen/msg_generated
"
;
import
{
flatbuffers
}
from
"
flatbuffers
"
;
import
*
as
dispatch
from
"
./dispatch
"
;
/**
* Synchronously renames (moves) oldpath to newpath. If newpath already exists
* and is not a directory, Rename replaces it. OS-specific restrictions may
* apply when oldpath and newpath are in different directories.
*
* import { renameSync } from "deno";
* renameSync("old/path", "new/path");
*/
export
function
renameSync
(
oldpath
:
string
,
newpath
:
string
):
void
{
dispatch
.
sendSync
(...
req
(
oldpath
,
newpath
));
}
/**
* Renames (moves) oldpath to newpath. If newpath already exists
* and is not a directory, Rename replaces it. OS-specific restrictions may
* apply when oldpath and newpath are in different directories.
*
* import { rename } from "deno";
* await rename("old/path", "new/path");
*/
export
async
function
rename
(
oldpath
:
string
,
newpath
:
string
):
Promise
<
void
>
{
await
dispatch
.
sendAsync
(...
req
(
oldpath
,
newpath
));
}
function
req
(
oldpath
:
string
,
newpath
:
string
):
[
flatbuffers
.
Builder
,
fbs
.
Any
,
flatbuffers
.
Offset
]
{
const
builder
=
new
flatbuffers
.
Builder
();
const
oldpath_
=
builder
.
createString
(
oldpath
);
const
newpath_
=
builder
.
createString
(
newpath
);
fbs
.
Rename
.
startRename
(
builder
);
fbs
.
Rename
.
addOldpath
(
builder
,
oldpath_
);
fbs
.
Rename
.
addNewpath
(
builder
,
newpath_
);
const
msg
=
fbs
.
Rename
.
endRename
(
builder
);
return
[
builder
,
fbs
.
Any
.
Rename
,
msg
];
}
js/rename_test.ts
0 → 100644
浏览文件 @
88d42f0b
// Copyright 2018 the Deno authors. All rights reserved. MIT license.
import
{
test
,
testPerm
,
assert
,
assertEqual
}
from
"
./test_util.ts
"
;
import
*
as
deno
from
"
deno
"
;
testPerm
({
write
:
true
},
function
renameSyncSuccess
()
{
const
testDir
=
deno
.
makeTempDirSync
()
+
"
/test-rename-sync
"
;
const
oldpath
=
testDir
+
"
/oldpath
"
;
const
newpath
=
testDir
+
"
/newpath
"
;
deno
.
mkdirSync
(
oldpath
);
deno
.
renameSync
(
oldpath
,
newpath
);
const
newPathInfo
=
deno
.
statSync
(
newpath
);
assert
(
newPathInfo
.
isDirectory
());
let
caughtErr
=
false
;
let
oldPathInfo
;
try
{
oldPathInfo
=
deno
.
statSync
(
oldpath
);
}
catch
(
e
)
{
caughtErr
=
true
;
assertEqual
(
e
.
kind
,
deno
.
ErrorKind
.
NotFound
);
}
assert
(
caughtErr
);
assertEqual
(
oldPathInfo
,
undefined
);
});
testPerm
({
write
:
false
},
function
renameSyncPerm
()
{
let
err
;
try
{
const
oldpath
=
"
/oldbaddir
"
;
const
newpath
=
"
/newbaddir
"
;
deno
.
renameSync
(
oldpath
,
newpath
);
}
catch
(
e
)
{
err
=
e
;
}
assertEqual
(
err
.
kind
,
deno
.
ErrorKind
.
PermissionDenied
);
assertEqual
(
err
.
name
,
"
PermissionDenied
"
);
});
testPerm
({
write
:
true
},
async
function
renameSuccess
()
{
const
testDir
=
deno
.
makeTempDirSync
()
+
"
/test-rename
"
;
const
oldpath
=
testDir
+
"
/oldpath
"
;
const
newpath
=
testDir
+
"
/newpath
"
;
deno
.
mkdirSync
(
oldpath
);
await
deno
.
rename
(
oldpath
,
newpath
);
const
newPathInfo
=
deno
.
statSync
(
newpath
);
assert
(
newPathInfo
.
isDirectory
());
let
caughtErr
=
false
;
let
oldPathInfo
;
try
{
oldPathInfo
=
deno
.
statSync
(
oldpath
);
}
catch
(
e
)
{
caughtErr
=
true
;
assertEqual
(
e
.
kind
,
deno
.
ErrorKind
.
NotFound
);
}
assert
(
caughtErr
);
assertEqual
(
oldPathInfo
,
undefined
);
});
js/unit_tests.ts
浏览文件 @
88d42f0b
...
...
@@ -9,3 +9,4 @@ import "./read_file_test.ts";
import
"
./write_file_test.ts
"
;
import
"
./mkdir_test.ts
"
;
import
"
./stat_test.ts
"
;
import
"
./rename_test.ts
"
;
src/handlers.rs
浏览文件 @
88d42f0b
...
...
@@ -55,7 +55,7 @@ pub extern "C" fn msg_from_js(d: *const DenoC, buf: deno_buf) {
msg
::
Any
::
Mkdir
=>
handle_mkdir
,
msg
::
Any
::
Remove
=>
handle_remove
,
msg
::
Any
::
ReadFile
=>
handle_read_file
,
msg
::
Any
::
Rename
Sync
=>
handle_rename_sync
,
msg
::
Any
::
Rename
=>
handle_rename
,
msg
::
Any
::
SetEnv
=>
handle_set_env
,
msg
::
Any
::
Stat
=>
handle_stat
,
msg
::
Any
::
WriteFile
=>
handle_write_file
,
...
...
@@ -633,15 +633,14 @@ fn handle_timer_clear(d: *const DenoC, base: &msg::Base) -> Box<Op> {
ok_future
(
None
)
}
fn
handle_rename
_sync
(
d
:
*
const
DenoC
,
base
:
&
msg
::
Base
)
->
Box
<
Op
>
{
fn
handle_rename
(
d
:
*
const
DenoC
,
base
:
&
msg
::
Base
)
->
Box
<
Op
>
{
let
deno
=
from_c
(
d
);
if
!
deno
.flags.allow_write
{
return
Box
::
new
(
futures
::
future
::
err
(
permission_denied
()
));
}
;
let
msg
=
base
.msg_as_rename
_sync
()
.unwrap
();
return
odd_future
(
permission_denied
(
));
}
let
msg
=
base
.msg_as_rename
()
.unwrap
();
let
oldpath
=
String
::
from
(
msg
.oldpath
()
.unwrap
());
let
newpath
=
String
::
from
(
msg
.newpath
()
.unwrap
());
// TODO use blocking()
Box
::
new
(
futures
::
future
::
result
(||
->
OpResult
{
debug!
(
"handle_rename {} {}"
,
oldpath
,
newpath
);
fs
::
rename
(
Path
::
new
(
&
oldpath
),
Path
::
new
(
&
newpath
))
?
;
...
...
src/msg.fbs
浏览文件 @
88d42f0b
...
...
@@ -19,7 +19,7 @@ union Any {
ReadFile,
ReadFileRes,
WriteFile,
Rename
Sync
,
Rename,
Stat,
StatRes,
SetEnv,
...
...
@@ -194,7 +194,7 @@ table WriteFile {
// perm specified by https://godoc.org/os#FileMode
}
table Rename
Sync
{
table Rename {
oldpath: string;
newpath: string;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录