@@ -971,15 +971,18 @@ impl OpenOptions {
971
971
/// Note that setting `.write(true).append(true)` has the same effect as
972
972
/// setting only `.append(true)`.
973
973
///
974
- /// For most filesystems, the operating system guarantees that all writes are
975
- /// atomic: no writes get mangled because another process writes at the same
976
- /// time.
977
- ///
978
- /// One maybe obvious note when using append-mode: make sure that all data
979
- /// that belongs together is written to the file in one operation. This
980
- /// can be done by concatenating strings before passing them to [`write()`],
981
- /// or using a buffered writer (with a buffer of adequate size),
982
- /// and calling [`flush()`] when the message is complete.
974
+ /// Append mode guarantees that writes will be positioned at the current end of file,
975
+ /// even when there are other processes or threads appending to the same file. This is
976
+ /// unlike <code>[seek]\([SeekFrom]::[End]\(0))</code>` followed by `write()`, which
977
+ /// has a race between seeking and writing during which another writer can write, with
978
+ /// our `write()` overwriting their data.
979
+ ///
980
+ /// Keep in mind that atomicity of `write()` in append mode is less useful than it
981
+ /// appears at first. A successful `write()` is allowed to write only part of the
982
+ /// given data, so even if you're careful to provide the whole message in a single
983
+ /// call to `write()`, there is no guarantee that it will written out in full. Unless
984
+ /// the data to append consists of a single byte, you can't append atomically without
985
+ /// external locking.
983
986
///
984
987
/// If a file is opened with both read and append access, beware that after
985
988
/// opening, and after every write, the position for reading may be set at the
@@ -995,6 +998,7 @@ impl OpenOptions {
995
998
/// [`flush()`]: Write::flush "io::Write::flush"
996
999
/// [seek]: Seek::seek "io::Seek::seek"
997
1000
/// [Current]: SeekFrom::Current "io::SeekFrom::Current"
1001
+ /// [End]: SeekFrom::End "io::SeekFrom::End"
998
1002
///
999
1003
/// # Examples
1000
1004
///
0 commit comments