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

Copying a file while maintaing the last modified date (and possibly creation date) #439

Closed
johot opened this issue Feb 8, 2024 · 2 comments

Comments

@johot
Copy link

johot commented Feb 8, 2024

Anyone know if this is possible or planned to be implemented in the future?

I am building a photo sorter application of sorts and everything has been going great except for one thing that is currently a major blocker for me.

When copying files I have to basically create a new file using .getFileHandle(name, { create: true }) and then write to that file using createWritable(...). This works and creates a copy of any file but the last modified date gets set to the current date which potentially destroys a crucial part of file metadata in the case of a photo.

Is there any current workaround to this or plans to add a fileHandle.copy(...) method or similair? I did see a move method actually exists that works almost like I want but I don't want to affect any original files.

Thank you for all your hard work with this API it brings so many new possibilities 👍

@a-sully
Copy link
Collaborator

a-sully commented Feb 16, 2024

Is there any current workaround to this

Not supported by this API, no :/ There is no way to explicitly set file metadata. Most discussions about extending support for file metadata have been read-only for now (see whatwg/fs#12)

I would recommend exploring workarounds you can do at the application level

plans to add a fileHandle.copy(...) method or similair

Not currently, though if a copy() method were to be added, my intuition is that most developers would expect the copied file would have a different creation time and last-modified time. For example:

touch original.txt
cp original.txt copy.txt
stat original.txt  # this will be different
stat copy.txt      # than this

@a-sully a-sully closed this as completed Feb 16, 2024
@johot
Copy link
Author

johot commented Feb 18, 2024

Thank you for your answer @a-sully .

You are correct that the above commands will actually change the last modified time. However on Windows for example this is not the default case. If using Linux etc and providing the cp -p (preserve) option the last modified date will also be preserved when copying a file.

I do understand that for many it doesn't matter if the last modified date gets changed but for my specific usecase its a dealbreaker (copying photos where the last modified time is the date the photo was taken and it has no EXIF metadata). The only workaround I could come up with would involve adding files to a zip file to preserve dates.

But I would also argue that having a copy method would make sense for other purposes the most important one being simplicity (and perhaps performance?).

My current plan is unfortunately to move over to Electron for my app which is a bit of a bummer but I do understand you guys have to prioritize. If this discussion ever comes up again feel free to think of this usecase :D

Thank you!

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

No branches or pull requests

2 participants