Skip to content

Changes ownership to $USER on update. #11

Closed
@jimbojw

Description

@jimbojw

write-file-atomic changes the ownership of the file it's writing to the current user, even if no chown option is set.

Steps to reproduce:

# Install write-file-atomic.
$ npm install write-file-atomic@1.1.4

# Create example script that writes to a new file with no other options.
$ echo 'require("write-file-atomic")("hello.txt", "hello!\n", ()=>0)' > example.js

# Run script as current user.
$ node example.js

# Observe that the owner/group is current user (expected).
$ ls -al hello.txt
-rw-rw-r-- 1 jimbo jimbo 6 May 12 05:45 hello.txt

# Re-run the example script as root.
$ sudo node example.js

# Expect owner/group unchanged, observe that it's now root.
$ ls -al hello.txt
-rw-r--r-- 1 root root 7 May 12 05:50 hello.txt

Note: If you installed node via nvm, then running sudo node example.js probably won't work due to path issues. You can overcome this and still run as sudo by overriding the PATH var:

$ sudo PATH=$PATH bash -c 'node example.js'

Tested on Ubuntu 14.04 with Node v6.1.0.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions