Skip to content

Commit

Permalink
avoid file ownership requirement in touch (#28819)
Browse files Browse the repository at this point in the history
Using `futimes` and passing NULL for the `times` parameter sets the current and access file times, but does not require file ownwership.

From man page:
> If times is NULL, the access and modification times are set to the current time. The caller must be the owner of the file, have permission to write the file, or be the superuser.
(cherry picked from commit 3b3a163)
  • Loading branch information
tanmaykm authored and JeffBezanson committed Jun 6, 2019
1 parent 58db74d commit 51495d3
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions base/file.jl
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,13 @@ We can see the [`mtime`](@ref) has been modified by `touch`.
function touch(path::AbstractString)
f = open(path, JL_O_WRONLY | JL_O_CREAT, 0o0666)
try
t = time()
futime(f,t,t)
if Sys.isunix()
ret = ccall(:futimes, Cint, (Cint, Ptr{Cvoid}), fd(f), C_NULL)
systemerror(:futimes, ret != 0, extrainfo=path)
else
t = time()
futime(f,t,t)
end
finally
close(f)
end
Expand Down

0 comments on commit 51495d3

Please sign in to comment.