From 3b3a16362b84c7f64b40e11dd6a296fa7a636c75 Mon Sep 17 00:00:00 2001 From: Tanmay Mohapatra Date: Sat, 29 Sep 2018 01:47:22 +0530 Subject: [PATCH] avoid file ownership requirement in touch (#28819) 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. --- base/file.jl | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/base/file.jl b/base/file.jl index da966d37f0e49..64135e559e17b 100644 --- a/base/file.jl +++ b/base/file.jl @@ -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