fs exclusive mode

54 views
Skip to first unread message

Mark Volkmann

unread,
Oct 22, 2014, 9:31:31 AM10/22/14
to nod...@googlegroups.com
The docs say ...
" 'ax' - Like 'a' but fails if path exists."
and a bit later ...
"The exclusive flag 'x' ensures that path is newly created."

What is the point is using the 'ax' mode if it can't append to an existing file?
It seems that the 'wx' mode would do the same thing.

--
R. Mark Volkmann
Object Computing, Inc.

Ben Noordhuis

unread,
Oct 22, 2014, 11:13:02 AM10/22/14
to nod...@googlegroups.com
Mode 'ax' (which is a shorthand for `O_APPEND | O_CREAT | O_EXCL |
O_WRONLY`, see `man 2 open`) is useful when there will be multiple
concurrent writers, like, say, different processes that write to a
single log file. Without the append flag, the processes would
overwrite each other's output.

Mark Volkmann

unread,
Oct 22, 2014, 11:44:57 AM10/22/14
to nod...@googlegroups.com
Thanks for explaining that! Doesn't your explanation mean that the documentation is wrong? From what you said, "ax" does NOT fail if path exists and does NOT ensure that path is newly created.


--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
To post to this group, send email to nod...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/CAHQurc8zhRSxsQ9uL_SAmQjci2p0BJPFPiO0j8BRaWnX4aT3Tw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Ben Noordhuis

unread,
Oct 22, 2014, 1:16:27 PM10/22/14
to nod...@googlegroups.com
On Wed, Oct 22, 2014 at 5:22 PM, Mark Volkmann
<r.mark....@gmail.com> wrote:
> Thanks for explaining that! Doesn't your explanation mean that the
> documentation is wrong? From what you said, "ax" does NOT fail if path
> exists and does NOT ensure that path is newly created.

No, the documentation is correct. If what you said was true, then
'ax' would be a synonym for 'a'.

'ax' creates and opens the file in append-only mode unless the file
exists. You use 'ax' when you would use 'wx' but also want
append-only semantics.

A typical use case is where a master process opens the log file with
'ax' and, if successful, starts workers that open the file with 'a'.
The 'ax' open mode ensures that the master can't race with other
master processes.
Reply all
Reply to author
Forward
0 new messages