Skip to content

Commit

Permalink
Simple implementation of chmod(path, mode)
Browse files Browse the repository at this point in the history
currently only integer modes, can do string modes like +x later
fixes #7574

Conflicts:
	src/jl_uv.c
  • Loading branch information
tkelman authored and staticfloat committed Nov 23, 2014
1 parent ac11aad commit 9fac21b
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 3 deletions.
1 change: 1 addition & 0 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,7 @@ export

# filesystem operations
cd,
chmod,
cp,
ctime,
download,
Expand Down
6 changes: 6 additions & 0 deletions base/fs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export File,
rename,
sendfile,
symlink,
chmod,
JL_O_WRONLY,
JL_O_RDONLY,
JL_O_RDWR,
Expand Down Expand Up @@ -160,6 +161,11 @@ end
@windowsxp_only symlink(p::String, np::String) =
error("WindowsXP does not support soft symlinks")

function chmod(p::String, mode::Integer)
err = ccall(:jl_fs_chmod, Int32, (Ptr{Uint8}, Cint), p, mode)
uv_error("chmod",err)
end

function write(f::File, buf::Ptr{Uint8}, len::Integer, offset::Integer=-1)
if !f.open
error("file is not open")
Expand Down
5 changes: 5 additions & 0 deletions doc/stdlib/base.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5383,6 +5383,11 @@ System
This function raises an error under operating systems that do not support
soft symbolic links, such as Windows XP.

.. function:: chmod(path, mode)

Change the permissions mode of ``path`` to ``mode``. Only integer ``mode``s
(e.g. 0o777) are currently supported.
.. function:: getpid() -> Int32
Get julia's process ID.
Expand Down
8 changes: 8 additions & 0 deletions src/jl_uv.c
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,14 @@ DLLEXPORT int jl_fs_symlink(char *path, char *new_path, int flags)
return ret;
}

DLLEXPORT int jl_fs_chmod(char *path, int mode)
{
uv_fs_t req;
int ret = uv_fs_chmod(jl_io_loop, &req, path, mode, NULL);
uv_fs_req_cleanup(&req);
return ret;
}

DLLEXPORT int jl_fs_write(int handle, char *data, size_t len, int64_t offset)
{
uv_fs_t req;
Expand Down
5 changes: 2 additions & 3 deletions test/file.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ end
@test !islink(file)
@test isreadable(file)
@test iswritable(file)
# Here's something else that might be UNIX-specific?
run(`chmod -w $file`)
chmod(file, filemode(file) & 0o7555)
@test !iswritable(file)
run(`chmod +w $file`)
chmod(file, filemode(file) | 0o222)
@test !isexecutable(file)
@test filesize(file) == 0
# On windows the filesize of a folder is the accumulation of all the contained
Expand Down

0 comments on commit 9fac21b

Please sign in to comment.