-
Notifications
You must be signed in to change notification settings - Fork 177
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
Lwt_io.open_file: Unix.O_TRUNC is a dangerous default for output channel #570
Comments
Agreed. I'm not sure what the best way to address this is, though. |
I think only the docs should be updated, because removing O_TRUNC cold be a big breaking change for a such a small "improvement". |
Ok, docs included in the commit linked above. Hopefully, that is good enough to resolve this. Thinking about it more, it seems best to keep Lwt_io.with_file ~mode:Output "foo" (fun channel ->
Lwt_io.write ...) ...which are naively expected to leave That said, it is still true that |
I ran into this recently. I wonder if it would be reasonable to make |
I just searched packages that depend on Lwt in opam. At least the following packages would be affected by making this change: I'm not certain if its worth doing, but I would like to do it. |
If we only make val open_file :
?buffer:Lwt_bytes.t ->
flags:Unix.open_flag list ->
?perm:Unix.file_perm ->
mode:'a mode ->
file_name ->
'a channel Lwt.t the user would have to specify both Another option might be to switch from using the |
We decided to close this again. A better API can be made than the existing
So, it seems best to keep the flaws of |
@hcarty feedback on this early prototype is welcome: https://gitlab.com/raphael-proust/boloss |
I think O_TRUNC is a little bit dangerous default, because the output channel modifies the file's content by just opening it. For me it's feels like an unexpected side effect. This behavior is also not documented, which made it harder to find out why my file kept getting truncated.
The text was updated successfully, but these errors were encountered: