Skip to content

Commit 6a913d7

Browse files
committed
Fix uv_fs_copyfile callback handling
1 parent e2a871e commit 6a913d7

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/fs.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -776,10 +776,18 @@ mrb_uv_fs_copyfile(mrb_state *mrb, mrb_value self)
776776
mrb_int flags = 0;
777777
mrb_value proc, ret;
778778
mrb_uv_req_t *req;
779+
int res;
779780

780781
mrb_get_args(mrb, "&zz|i", &proc, &old_path, &new_path, &flags);
781782
req = mrb_uv_req_current(mrb, proc, &ret);
782-
mrb_uv_req_check_error(mrb, req, uv_fs_copyfile(mrb_uv_current_loop(mrb), &req->req.fs, old_path, new_path, flags, NULL));
783+
res = uv_fs_copyfile(
784+
mrb_uv_current_loop(mrb), &req->req.fs, old_path, new_path, flags,
785+
mrb_nil_p(req->block)? NULL : _uv_fs_cb);
786+
if (mrb_nil_p(req->block)) {
787+
mrb_uv_req_clear(req);
788+
return mrb_uv_create_status(mrb, res);
789+
}
790+
mrb_uv_req_check_error(mrb, req, res);
783791
return ret;
784792
}
785793

test/callback.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def assert_uv(name, &block)
138138
f.close
139139

140140
# async version
141-
UV::FS.copyfile 'foo-bar/foo.txt', 'foo-bar/bar.txt' do |v|
141+
UV::FS.copyfile('foo-bar/foo.txt', 'foo-bar/bar.txt') do |v|
142142
assert_equal "test\n", UV::FS.open('foo-bar/bar.txt', UV::FS::O_RDONLY, UV::FS::S_IREAD).read(5)
143143
remove_uv_test_tmpfile
144144
end

0 commit comments

Comments
 (0)