Skip to content

Commit

Permalink
Merge pull request #782 from MasterDuke17/add_chown_op
Browse files Browse the repository at this point in the history
  • Loading branch information
MasterDuke17 authored Nov 3, 2022
2 parents ccf2d60 + 6667545 commit 2e7924c
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 1 deletion.
7 changes: 7 additions & 0 deletions docs/ops.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ The opcodes are grouped into the following categories:

[chdir](#chdir) |
[chmod](#chmod) |
[chown](#chown) |
[closedir](#closedir) |
[copy](#copy) |
[cwd](#cwd) |
Expand Down Expand Up @@ -1519,6 +1520,12 @@ Change the working directory to the given path.
Change the permissions of `$path` to the posix style permissions of `$mode`.
Returns 0 on success, throws an exception on failure.

## chown
* `chown(str $path, int $uid, int $gid --> int)`

Change the owner or group of the path.
Throws an exception on failure.

## closedir
* `closedir(Handle $)`

Expand Down
1 change: 1 addition & 0 deletions src/vm/js/Operations.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,7 @@ class QAST::OperationsJS {
add_simple_op('mkdir', $T_VOID, [$T_STR, $T_INT], :side_effects);

add_simple_op('chmod', $T_VOID, [$T_STR, $T_INT], :side_effects);
add_simple_op('chown', $T_VOID, [$T_STR, $T_INT, $T_INT], :side_effects);

add_simple_op('getenvhash', $T_OBJ, [], :side_effects);
add_simple_op('getsignals', $T_OBJ, [], :side_effects, :takes_hll);
Expand Down
4 changes: 4 additions & 0 deletions src/vm/js/nqp-runtime/io.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,10 @@ op.chmod = function(path, mode) {
return fs.chmodSync(path, mode);
};

op.chown = function(path, uid, gid) {
return fs.chownSync(path, uid, gid);
};

op.sleep = function(seconds) {
sleep.usleep(Math.floor(seconds * 1000000));
return seconds;
Expand Down
1 change: 1 addition & 0 deletions src/vm/jvm/QAST/Compiler.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -2270,6 +2270,7 @@ QAST::OperationsJAST.map_classlib_core_op('filenofh', $TYPE_OPS, 'filenofh', [$R
QAST::OperationsJAST.map_classlib_core_op('setbuffersizefh', $TYPE_OPS, 'setbuffersizefh', [$RT_OBJ, $RT_INT], $RT_OBJ, :tc);

QAST::OperationsJAST.map_classlib_core_op('chmod', $TYPE_OPS, 'chmod', [$RT_STR, $RT_INT], $RT_INT, :tc);
QAST::OperationsJAST.map_classlib_core_op('chown', $TYPE_OPS, 'chown', [$RT_STR, $RT_INT, $RT_INT], $RT_INT, :tc);
QAST::OperationsJAST.map_classlib_core_op('unlink', $TYPE_OPS, 'unlink', [$RT_STR], $RT_INT, :tc);
QAST::OperationsJAST.map_classlib_core_op('rmdir', $TYPE_OPS, 'rmdir', [$RT_STR], $RT_INT, :tc);
QAST::OperationsJAST.map_classlib_core_op('cwd', $TYPE_OPS, 'cwd', [], $RT_STR);
Expand Down
13 changes: 13 additions & 0 deletions src/vm/jvm/runtime/org/raku/nqp/runtime/Ops.java
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,19 @@ public static long chmod(String path, long mode, ThreadContext tc) {
return 0;
}

public static long chown(String path, long uid, long gid, ThreadContext tc) {
Path path_o;
try {
path_o = Paths.get(path);
Files.setAttribute(path_o, "unix:uid", uid);

This comment has been minimized.

Copy link
@ugexe

ugexe Nov 14, 2022

Contributor

Do these work on windows?

Files.setAttribute(path_o, "unix:gid", gid);
}
catch (Exception e) {
die_s(IOExceptionMessages.message(e), tc);
}
return 0;
}

public static long unlink(String path, ThreadContext tc) {
Path path_o = Paths.get(path);
if (Files.isDirectory(path_o)) {
Expand Down
1 change: 1 addition & 0 deletions src/vm/moar/QAST/QASTOperationsMAST.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -3197,6 +3197,7 @@ my constant SIMPLE_OP_MAPPINGS_RESULT_ZERO := nqp::list_s(
'bindsock', 'bind_sk',
'setbuffersizefh', 'setbuffersize_fh',
'chmod', 'chmod_f',
'chown', 'chown_f',
'unlink', 'delete_f',
'rmdir', 'rmdir',
'chdir', 'chdir',
Expand Down
2 changes: 1 addition & 1 deletion tools/templates/MOAR_REVISION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2022.07-16-g3ae8a31c1
2022.07-18-gd22223381

0 comments on commit 2e7924c

Please sign in to comment.