Closed piegamesde closed 3 years ago
Discussion on the python side: https://github.com/magic-wormhole/magic-wormhole/issues/370
I'd be willing to implement this. To check to see if I understand it correctly: We want to check if the file already exists. If it does, we query the user whether they would like to write over the existing file or not. If they do, we write over the existing file. If they don't, we get a new filename from stdin and start the check loop over again?
@brightly-salty I'm sure that's is what @piegamesde is looking for. I think a safer way to go about overwriting a file is to first check if the file sizes are the same and if they are, they must be different files even if they are named similarly (and the latter would not be necessary) but if the files sizes match it would be thorough check for and compare the values of the first and the last 4 kb hashes of the files. And if the all those checks match out, warn the user about overwriting dissimilar files.
@kamva9697 Okay, how would I check the first and last 4 kb hashes of the files? And I warn if they're different or if they're the same?
Okay, my description was a bit under-specified. I'm open to different solutions, but I had the following in mind:
with the following potential variations in mind:
I never thought about comparing file contents though. Also note that in the protocol the sequence is:
Therefore, we can't know the file's content at the point in time where we ask the user.
I think we can just check the full file hash right? While receiving we can do a checksum while writing, we could even reuse the buffer like the optimization in cargo.
We don't want to override random existing files on the receiver's host system, so we should check against that. The easiest way to do this is to simply check and bail out.
https://github.com/magic-wormhole/magic-wormhole.rs/blob/2b6605631d574f8556944d19837a25908e42eb60/src/transfer.rs#L329-L333
However, I'd prefer the CLI to ask me whether I want to override the file or not. Erroring out means that the transfer fails and the sender will have to re-send it and to retransmit a new code, which is annoying.