Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal: os: add Lchtimes to change only a symlink's times without following it #30487

Closed
Isolus opened this issue Feb 28, 2019 · 9 comments
Closed
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. Proposal
Milestone

Comments

@Isolus
Copy link

Isolus commented Feb 28, 2019

Looks like there's no way to change access and modification times of a symlink.
We only have os.Chtimes which follows the symlink.

Since there is os.Chown and os.Lchown to change the uid and gid, I think there should also be Lchtimes. The implementation can be similar to the one of os.Chtimes. (E. g. on linux only the flag AT_SYMLINK_NOFOLLOW has to be added.)

@odeke-em odeke-em changed the title os: add Lchtimes proposal: os: add Lchtimes Feb 28, 2019
@gopherbot gopherbot added this to the Proposal milestone Feb 28, 2019
@odeke-em odeke-em changed the title proposal: os: add Lchtimes proposal: os: add Lchtimes to change only a symlink's times without following it Feb 28, 2019
@odeke-em
Copy link
Member

Thank you for the feature request @Isolus and welcome to the Go project!

There exists lutimes on Darwin since 2006, and same for Linux https://linux.die.net/man/3/lutimes but it is missing on many platforms as per https://www.gnu.org/software/gnulib/manual/html_node/lutimes.html so perhaps we'll have to do something else as you've suggested.

I've tagged this as a proposal and it'll get reviewed over the cycle by others and myself too but for starters I shall kindly page @kevinburke @rsc @ianlancetaylor

@ianlancetaylor
Copy link
Contributor

I think that a specialized operation like this, one that is not available at all on many systems, belongs in the golang.org/x/sys/unix package, not the os package.

@Isolus
Copy link
Author

Isolus commented Mar 1, 2019

But isn't it a little unintuitive that Lstat (the no follow companion) to Stat is included in the os package. Therefore I can retrieve the times with the os package, but I can't write them?

I'm currently adding tar archiver functionality to an application and everything but a Lchtimes (or Lutimes) function for symlink handling (i. e. Lchmod and Lstat) is there (in the standard library). So my first thought was that this function was just forgotten.

@ianlancetaylor
Copy link
Contributor

It's a little unintuitive that there are operating systems that provide lstat but not lutimes. But we can't pretend that that is not the case.

@bcmills bcmills added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Mar 1, 2019
@bcmills
Copy link
Contributor

bcmills commented Mar 1, 2019

CC @bradfitz @tklauser for the relationship to x/sys/unix

@tklauser
Copy link
Member

tklauser commented Mar 2, 2019

I agree with Ian that we should not pretend to support lutimes where it is not supported. Rather we should add it to x/sys/unix where supported - either via SYS_LUTIMES as on some darwin or by wrapping utimensat e.g. on Linux and the BSDs.

@gopherbot
Copy link

Change https://golang.org/cl/164662 mentions this issue: unix: add Lutimes

gopherbot pushed a commit to golang/sys that referenced this issue Mar 5, 2019
Add Lutimes wrapping UtimesNanoAt.

Updates golang/go#30487

Change-Id: Ic5bb3b4d88be5806522eaef9bd9b8b0f5c1c8f42
Reviewed-on: https://go-review.googlesource.com/c/sys/+/164662
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
@rsc
Copy link
Contributor

rsc commented Mar 6, 2019

I see this was merged into x/sys/unix. That seems like the right place to stop. Package os is for generally portable things (despite our imperfect execution of that plan), and this is a very special case.

@rsc rsc closed this as completed Mar 6, 2019
@guonaihong
Copy link

Great, just need this function to implement the touch -h option.

@golang golang locked and limited conversation to collaborators Apr 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. Proposal
Projects
None yet
Development

No branches or pull requests

8 participants