Skip to content

Commit b07c356

Browse files
committed
[js] Implement stuff needed to get test 19 to pass again.
Implement nqp::rename, nqp::copy. Make nqp::unlink fail quietly when it's target doesn't exit.
1 parent 3a09f86 commit b07c356

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/vm/js/Operations.nqp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,8 @@ class QAST::OperationsJS {
458458
add_simple_op('isttyfh', $T_INT, [$T_OBJ]);
459459
add_simple_op('setinputlinesep', $T_OBJ, [$T_OBJ, $T_STR], :sideffects);
460460
add_simple_op('setinputlineseps', $T_OBJ, [$T_OBJ, $T_OBJ], :sideffects);
461+
add_simple_op('copy', $T_VOID, [$T_STR, $T_STR], :sideffects);
462+
add_simple_op('rename', $T_VOID, [$T_STR, $T_STR], :sideffects);
461463

462464
add_simple_op('bootarray', $T_OBJ, []);
463465

src/vm/js/nqp-runtime/io.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,13 @@ op.sayfh = function(fh, content) {
321321
};
322322

323323
op.unlink = function(filename) {
324-
fs.unlinkSync(filename);
324+
try {
325+
fs.unlinkSync(filename);
326+
} catch (e) {
327+
if (e.code !== 'ENOENT') {
328+
throw e;
329+
}
330+
}
325331
};
326332

327333
op.link = function(srcpath, dstpath) {
@@ -461,3 +467,11 @@ op.sleep = function(seconds) {
461467
sleep.usleep(Math.floor(seconds * 1000000));
462468
return seconds;
463469
};
470+
471+
op.copy = function(source, target) {
472+
fs.writeFileSync(target, fs.readFileSync(source));
473+
};
474+
475+
op.rename = function(oldPath, newPath) {
476+
fs.renameSync(oldPath, newPath);
477+
};

0 commit comments

Comments
 (0)