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

File System (fs) is lacking bindings for lutimes(3) #16695

Closed
System-Arch opened this issue Nov 2, 2017 · 12 comments
Closed

File System (fs) is lacking bindings for lutimes(3) #16695

System-Arch opened this issue Nov 2, 2017 · 12 comments
Labels
feature request Issues that request new features to be added to Node.js. fs Issues and PRs related to the fs subsystem / file system.

Comments

@System-Arch
Copy link

System-Arch commented Nov 2, 2017

  • Version: ALL
  • Platform: Linux, Mac, other UNIX
  • Subsystem: File System (fs)

File System (fs) is lacking bindings for lutimes(3), and thus it is very difficult to modify the metadata for a symbolic link from within a Node.js application. This C Library function has been implemented in glibc since version 2.6, which is over 10 years old, and has likely been available on the Mac for even longer, given its origins in BSD UNIX. The behavior on Windows could simply be to call utimes(2).

This omission seems like an oversight given the support for symbolic link-aware functions including: lstat, lchmod, and lchown. Additionally, its peer function futimes(3) is also already supported.

@mscdex mscdex added feature request Issues that request new features to be added to Node.js. fs Issues and PRs related to the fs subsystem / file system. labels Nov 2, 2017
@gireeshpunathil
Copy link
Member

@System-Arch - I am interested to know the use case for lutimes. Agree that decades of existence in the C runtime provides sufficient relevance, but getting / setting time attributes of a symbolic link (in contrast to a physical file that holds business data) looks like a (file) sys-admin's use case to me, not much for general purpose programs. Thoughts?

@bnoordhuis
Copy link
Member

nodejs/node-v0.x-archive#2142 - almost six years old to the day. :-)

This omission seems like an oversight given the support for symbolic link-aware functions including: lstat, lchmod, and lchown.

Note that the last two are only available on BSD-like systems (although they could be implemented on Linux now - kernel support used to be an issue.)

If you're on a BSD-like system, you can already do this:

const fs = require('fs');
const { O_WRONLY, O_SYMLINK } = fs.constants;
const fd = fs.openSync(filename, O_WRONLY | O_SYMLINK);
fs.futimesSync(fd, atime, mtime);

That is in fact how fs.lchmod() and fs.lchown() are implemented.

@chris--young
Copy link

I'd like to work on this if people want it to be added.

@System-Arch
Copy link
Author

@gireeshpunathil - I am developing an "update installer" that makes extensive use of time stamps (and other info) to determine which files have or need to be updated (i.e., to achieve idempotency). Symbolic links threw a wrinkle into this plan, but using fs.lstat in place of fs.stat took care of most of the issues along with using fs.symlink in place of fs.copyFile. The one real difficulty was trying to set the time stamps of the symbolic links as fs.utimes works great for files but does not handle symlinks. Having fs.lutimes would address this issue and preserve the simplicity of my overall approach. I was able to prove out the concept by making a system call to "touch -h" but this is platform dependent (e.g., Mac doesn't accept @ style times like Linux does) and clearly not very elegant. Thanks.

@System-Arch
Copy link
Author

@bnoordhuis - My application does not require fs.lchmod() or fs.lchown(), so I was probably over zealous in citing those in my analysis. I did try the fs.open() with O_SYMLINK approach but it did not appear to work on Linux (not too surprising since it is not BSD). lutimes(3) does appear to be portable across both Linux and Mac OSX at the C run-time library API level. Thanks.

@System-Arch
Copy link
Author

@chris--young - Thanks for volunteering. It would be great to see this missing functionality added. Thanks.

@bnoordhuis
Copy link
Member

@chris--young It needs to be added to libuv first. It's trivial for Unices (see uv_fs_futime() in src/unix/fs.c) but it should also do something reasonable on Windows, if at all possible.

@chris--young
Copy link

@bnoordhuis awesome, I’ll start there.

@System-Arch
Copy link
Author

@bnoordhuis @chris--young - To my surprise. it looks like libuv does actually support symbolic links in win/fs.c::fs__stat_impl(), so presumably a similar approach can be used to provide full support for lutimes on Windows. Thanks.

@refack
Copy link
Contributor

refack commented Nov 11, 2018

Put into https://github.com/nodejs/node/projects/13 backlog

@refack refack closed this as completed Nov 11, 2018
@arcanis
Copy link
Contributor

arcanis commented Dec 25, 2019

This binding being missing makes it difficult (impossible?) to make perfect copy algorithms, which in turns make it very difficult to generate deterministic archives (in the sense that the same operations will end up with the same checksum).

@gengjiawen
Copy link
Member

PR by @arcanis #33399

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Issues that request new features to be added to Node.js. fs Issues and PRs related to the fs subsystem / file system.
Projects
None yet
Development

No branches or pull requests

8 participants