Skip to content

Commit 6a7be99

Browse files
sam-githubbnoordhuis
authored andcommitted
doc: fs.open, fix flag/mode confusion, etc.
Flags and modes aren't the same, symlinks are followed in all of the path but the last component, docs should say something about what the mode argument is for and when its used, fs.openSync should point to the function that contains the docs for its args, as fs.writeSync does.
1 parent bea9dfa commit 6a7be99

1 file changed

Lines changed: 14 additions & 10 deletions

File tree

doc/api/fs.markdown

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ An exception occurs if the file does not exist.
296296

297297
This is primarily useful for opening files on NFS mounts as it allows you to
298298
skip the potentially stale local cache. It has a very real impact on I/O
299-
performance so don't use this mode unless you need it.
299+
performance so don't use this flag unless you need it.
300300

301301
Note that this doesn't turn `fs.open()` into a synchronous blocking call.
302302
If that's what you want then you should be using `fs.openSync()`
@@ -307,36 +307,40 @@ An exception occurs if the file does not exist.
307307
* `'w'` - Open file for writing.
308308
The file is created (if it does not exist) or truncated (if it exists).
309309

310-
* `'wx'` - Like `'w'` but opens the file in exclusive mode.
310+
* `'wx'` - Like `'w'` but fails if `path` exists.
311311

312312
* `'w+'` - Open file for reading and writing.
313313
The file is created (if it does not exist) or truncated (if it exists).
314314

315-
* `'wx+'` - Like `'w+'` but opens the file in exclusive mode.
315+
* `'wx+'` - Like `'w+'` but fails if `path` exists.
316316

317317
* `'a'` - Open file for appending.
318318
The file is created if it does not exist.
319319

320-
* `'ax'` - Like `'a'` but opens the file in exclusive mode.
320+
* `'ax'` - Like `'a'` but fails if `path` exists.
321321

322322
* `'a+'` - Open file for reading and appending.
323323
The file is created if it does not exist.
324324

325-
* `'ax+'` - Like `'a+'` but opens the file in exclusive mode.
325+
* `'ax+'` - Like `'a+'` but fails if `path` exists.
326326

327-
`mode` defaults to `0666`. The callback gets two arguments `(err, fd)`.
327+
`mode` sets the file mode (permission and sticky bits), but only if the file was
328+
created. It defaults to `0666`, readable and writeable.
328329

329-
Exclusive mode (`O_EXCL`) ensures that `path` is newly created. `fs.open()`
330-
fails if a file by that name already exists. On POSIX systems, symlinks are
331-
not followed. Exclusive mode may or may not work with network file systems.
330+
The callback gets two arguments `(err, fd)`.
331+
332+
The exclusive flag `'x'` (`O_EXCL` flag in open(2)) ensures that `path` is newly
333+
created. On POSIX systems, `path` is considered to exist even if it is a symlink
334+
to a non-existent file. The exclusive flag may or may not work with network file
335+
systems.
332336

333337
On Linux, positional writes don't work when the file is opened in append mode.
334338
The kernel ignores the position argument and always appends the data to
335339
the end of the file.
336340

337341
## fs.openSync(path, flags, [mode])
338342

339-
Synchronous open(2).
343+
Synchronous version of `fs.open()`.
340344

341345
## fs.utimes(path, atime, mtime, callback)
342346
## fs.utimesSync(path, atime, mtime)

0 commit comments

Comments
 (0)