Skip to content

Inconsistent error codes across platforms when writing to read-only (444) files #16596

Closed
@pitaj

Description

@pitaj
  • Version: 8.8.1
  • Platform: tested on these systems
    • Linux peter-XPS-15 4.13.0-16-generic #19-Ubuntu SMP Wed Oct 11 18:35:14 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
    • Windows 10 64bit (version 1709)
  • Subsystem: fs

Attempting to write to a read-only file will result in:

  • an EACCES error on Linux systems
  • an EPERM error on Windows systems

Is this expected behavior? If so, it should be documented as such. The only mention of EPERM is with relation to hidden files.

Windows error message

Linux error message

You can reproduce this by executing the following snippet on machines of the two different platforms.

const fs = require('fs');
const path = require('path');

const code = '444';
const filename = '00000';
const content = 'abcdefghijklmnopqrstuvwxyz';
const filePath = path.join(__dirname, filename);

// set up a read-only file
fs.writeFileSync(filePath, content);
fs.chmodSync(filePath, '444');

fs.writeFile(filePath, content, function (err) {
  throw err;
});

https://gist.github.com/pitaj/047faae18463835a8b7697e2964a341e

Metadata

Metadata

Assignees

No one assigned

    Labels

    fsIssues and PRs related to the fs subsystem / file system.libuvIssues and PRs related to the libuv dependency or the uv binding.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions