lunarmodules / Penlight

A set of pure Lua libraries focusing on input data handling (such as reading configuration files), functional programming (such as map, reduce, placeholder expressions,etc), and OS path management. Much of the functionality is inspired by the Python standard libraries.
https://lunarmodules.github.io/Penlight/
MIT License
1.9k stars 238 forks source link

Consider implementing `cp` / `mv` via FFI #458

Open RaitoBezarius opened 8 months ago

RaitoBezarius commented 8 months ago

Hi there, foremost, thank you for your library, I am using your library for file manipulations and I just noticed that it fallbacks to cp / mv on UNIX systems, unfortunately, I don't have those binaries on the target system, therefore, I'm kind of stuck to perform the move operation.

Would you consider using FFI to perform atomic renames or copy here?

alerque commented 8 months ago

Did you try os.rename() for move? I'm not sure why we'd re-implement that.

For copy you can already read and write files right?

Also note the FFI only applies to LuaJIT, so even adding an implementation that way may not cover your use case.

If there is some reason to provide a real implementation the more likely candidate would be to add this to LFS, not Penlight.

RaitoBezarius commented 8 months ago

Did you try os.rename() for move? I'm not sure why we'd re-implement that.

This only works on the same filesystem? Not across filesystem, does it?

For copy you can already read and write files right?

Yes, but this is not realistic for large files and small memory size.

Also note the FFI only applies to LuaJIT, so even adding an implementation that way may not cover your use case.

If there is some reason to provide a real implementation the more likely candidate would be to add this to LFS, not Penlight.

Got it.