Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, I thought that this was basically the same as a
write
with the cursor starting at the end of the file? According to the manpage at least:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this is what I thought, too. If search for "bad file descriptor" in the cited post, you will see my experience with this issue.
I might have also been misunderstanding things.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I guess I may have been too. I thought this was setting the mode, as I mentioned here: http://www.reddit.com/r/rust/comments/391unl/a_simple_web_app_in_rust_part_2b/crzna4l which is consistent with the behavior Joel saw.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I think the append mode on files is definitely separate from this. I believe the confusion derives from the title of this PR (append doesn't imply write), but that just means that if you want to write to the file you also need to say
write(true)
. Perhaps that could be mentioned in these docs?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess I'm not sure of the right way to word it, you're suggesting dropping the 'cursor' bit, I guess? Because appending to a file is still writing to it...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The part I don't understand is:
I would claim that
append
is the exact same as the cursor starting at the end of the fileThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@steveklabnik if I understand what is going on, it seems like there must be some difference between writing and appending as a file operation, and this is what
cat
would be using in your example. This is news to me, if it is the case; is there a method in Rust somewhere that implements this append operation that I was missing?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The difference is that if O_APPEND is set, the kernel will atomically (except on NFS which is broken) do a seek() to the end of the file then the write. It doesn't only affect the initial position of the cursor, the cursor will jump back on each write. It is more than a common way to do log file, it is the only way to write log files without races.
Either way, append makes no sense if write isn't specified (the cursor behavior happens on write, so if you can't write...). In my opinion append should DEFINITELY imply write, as the current behavior only lead to errors. This is also what libc's fopen does. This shouldn't break existing code because code doing append without write is definitely not working.
Interestingly truncate also needs write (O_TRUNC; POSIX says behavior is undefined otherwise, which is bad), create doesn't.