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

Use Lstat instead of Stat? #3

Closed
deitch opened this issue Oct 24, 2018 · 7 comments
Closed

Use Lstat instead of Stat? #3

deitch opened this issue Oct 24, 2018 · 7 comments

Comments

@deitch
Copy link

deitch commented Oct 24, 2018

Any thoughts on using os.Lstat instead of os.Stat? Stat tries to follow symlinks, giving the information about the target, as opposed to the file itself. This means:

  • you miss info about the link
  • if the target doesn't exist, error

Or maybe have it as an option?

@djherbis
Copy link
Owner

What about using times.Get after os.Lstat?

fi, _ := os.Lstat("myfile")
times.Get(fi)

That being said, adding Lstat directly as well sounds like a reasonable ask to me too.

@deitch
Copy link
Author

deitch commented Oct 24, 2018

Drat. I missed that in the docs. (facepalm)

Thanks @djherbis

@djherbis
Copy link
Owner

One thing to note, times.Get returns only those times that can be obtained by reading the FileInfo object.

times.Stat is allowed to do 'extra work' to fetch more times if possible.
I've only used this for Windows ctime so far, but if you're looking for that we'd need to add times.Lstat.

@deitch
Copy link
Author

deitch commented Oct 24, 2018

Ah, it is specifically ctime and atime that I am looking for.

For now, I am ok with just those 2 and just on linux and darwin, so I build my own 2 files. In doing so, I stumbled across your excellent library.

@djherbis
Copy link
Owner

Yeah ctime should work with Get for linux and darwin, only Windows requires an extra syscall to grab it.

I'll add an Lstat method later to make it the same as Stat.

@djherbis
Copy link
Owner

As a heads up, I added support for times.Lstat a week ago, but I'm waiting on approval to push it.

@deitch
Copy link
Author

deitch commented Nov 15, 2018

Works like a charm. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants