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

bug: moveSync doesn't preserve timestamp when moveAcrossDevice #992

Closed
zxcat opened this issue Jan 28, 2023 · 5 comments
Closed

bug: moveSync doesn't preserve timestamp when moveAcrossDevice #992

zxcat opened this issue Jan 28, 2023 · 5 comments

Comments

@zxcat
Copy link

zxcat commented Jan 28, 2023

it's just not implemented:

function moveAcrossDevice (src, dest, overwrite) {
const opts = {
overwrite,
errorOnExist: true
}
copySync(src, dest, opts)

so if you move something from one device to another then you'll lose timestamps (even with preserveTimestamps option).

versions
  • Operating System: macos 10.15.7
  • Node.js version: 14.19.2
  • fs-extra version: 11.1.0
@RyanZim
Copy link
Collaborator

RyanZim commented Jan 30, 2023

@zxcat Good catch! Any chance you could submit a PR?

@RyanZim
Copy link
Collaborator

RyanZim commented Feb 2, 2023

I'm sorry, I should have double-checked before commenting. I thought you were saying that moveSync didn't implement an document option that move did; I should have double-checked the docs. Only copy* supports preserveTimestamps; move does not. In that light, this is not a bug, this would be a feature request to add a preserveTimestamps option to the move* methods.

It feels like preserveTimestamps for move is much more of a niche use-case than for copy. @manidlou any thoughts here?

@zxcat
Copy link
Author

zxcat commented Feb 3, 2023

Well, my report was not detailed enough. You're right, both move and moveSync drop timestamps in some cases. I named it bug because of the following:

  1. Normal system mv preserves timestamp in any case: it just moves items with all its contents, including attributes.
  2. When moving "inside" one device, both move and moveSync work as expected: they preserve timestamp.
  3. When move from one device to another, move and moveSync kill timestamps, but normal mv preserve them. It's quite unexpected, because it's no more "moving" something, but "moving"+modifying attributes.

As about preserveTimestamps option: I just checked if it works with move to have a temporary workaround. It didn't. Anyway the proper way is to do normal move instead move+some modification.

As for PR: fastfix is to add preserveTimestamps: true to opts here (and in move.js):

function moveAcrossDevice (src, dest, overwrite) {
const opts = {
overwrite,
errorOnExist: true
}
copySync(src, dest, opts)

The proper way is to add tests too. I'm sorry, I cannot add tests now.

@KostiantynPopovych
Copy link
Contributor

Hi! I can update my PR with the suggested approach if you decide to go with it. Feel free to ping me!

@RyanZim
Copy link
Collaborator

RyanZim commented Feb 28, 2023

Sorry for the super slow response here. @zxcat Now I understand; yes, agreed, this is a bug. PR welcome to set preserveTimestamps: true for usage of copy*() in move*().

@RyanZim RyanZim closed this as completed in 0e7de32 Mar 6, 2023
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

3 participants