GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Inconsistent error codes across platforms when writing to read-only (444) files · Issue #16596 · nodejs/node

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

New issue
Copy link
New issue
Copy link
Closed
Closed
Inconsistent error codes across platforms when writing to read-only (444) files#16596
Copy link
Labels
fsIssues and PRs related to file-system APIs and the fs module.Issues and PRs related to file-system APIs and the fs module.libuvIssues and PRs related to the libuv dependency or the uv binding.Issues and PRs related to the libuv dependency or the uv binding.

Description

@pitaj
pitaj
opened on Oct 29, 2017
Issue body actions
  • 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

Activity

  1. mscdex
    added
    fsIssues and PRs related to file-system APIs and the fs module.Issues and PRs related to file-system APIs and the fs module.
    on Oct 30, 2017
  2. gireeshpunathil commented on Oct 30, 2017

    @gireeshpunathil
    gireeshpunathil
    on Oct 30, 2017
    Member
    More actions

    In Linux and MAC where I tested, I see no issues with the error - it is just a reflection of the low level error came from the system, and it is prudent to keep them as such for clarity and ease on diagnosis.

    #ls -lrt 00000
    -r--r--r--  1 gireesh  staff  26 Oct 30 12:15 00000
    #cat w.c
    
    #include <stdio.h>
    #include <fcntl.h>
    #include <errno.h>
    #include <stdlib.h>
    
    int main() {
      int fd = open("./00000", O_RDWR);
      if(fd == -1) {
        fprintf(stderr, "error: %d\n", errno);
        exit(1);
      }
    }
    #cc w.c
    #./a.out
    error: 13
    #
    

    And this perfectly makes sense:
    #define EACCES 13 /* Permission denied */

    In windows also I see EACCES is present and better represent the error at hand, however, looks like it took a different route and ended up in EPERM.

    /cc @nodejs/platform-windows

  3. pitaj commented on Oct 30, 2017

    @pitaj
    pitaj
    on Oct 30, 2017
    Author
    More actions

    Just to clarify, I don't see any issues with the error codes currently used, the only problem I have is that they are inconsistent between Linux and Windows.

  4. gireeshpunathil commented on Oct 30, 2017

    @gireeshpunathil
    gireeshpunathil
    on Oct 30, 2017
    Member
    More actions

    sure, but I see an issue with EPERM . Excerpts from Windows manual:

    EACCES
    Permission denied. The file's permission setting does not allow the specified access. This error signifies that an attempt was made to access a file (or, in some cases, a directory) in a way that is incompatible with the file's attributes.
    
    #define EPERM [operation not permitted]  
    

    So for the current context, EACCES is the most apt one. So it is worth looking into it to see whether EPERM is coming from Win32 system itself, or from some wrappers, and in either case, the rational of doing so.

  5. gireeshpunathil commented on Oct 30, 2017

    @gireeshpunathil
    gireeshpunathil
    on Oct 30, 2017
    Member
    More actions

    and, that may probably also lead to an answer why this disparity

  6. seishun commented on Oct 31, 2017

    @seishun
    seishun
    on Oct 31, 2017
    Contributor
    More actions

    PR to fix this: libuv/libuv#1612

    Reacted by Gireesh Punathil
  7. santigimeno
    added a commit that references this issue on Dec 2, 2017

    win: map ERROR_ACCESS_DENIED to UV_EACCES

    70d61b6
  8. maclover7
    added
    libuvIssues and PRs related to the libuv dependency or the uv binding.Issues and PRs related to the libuv dependency or the uv binding.
    on Dec 25, 2017
  9. jasnell
    closed this as completedin 70d61b6on Feb 27, 2018
  10. seishun commented on Feb 27, 2018

    @seishun
    seishun
    on Feb 27, 2018
    Contributor
    More actions

    Why was this autoclosed?

  11. seishun
    reopened this on Feb 27, 2018
  12. addaleax commented on Feb 27, 2018

    @addaleax
    addaleax
    on Feb 27, 2018
    Member
    More actions

    @seishun GitHub does that when a commit with a Fixes: tag lands in the main branch of a repo and the commiter has write access to the repo to which the issue refers (the commit doesn’t have to be in the same repo as the bug)

    Reacted by Benjamin Gruenbaum
  13. gireeshpunathil commented on Mar 30, 2018

    @gireeshpunathil
    gireeshpunathil
    on Mar 30, 2018
    Member
    More actions

    @seishun - should this remain open?

  14. seishun commented on Mar 30, 2018

    @seishun
    seishun
    on Mar 30, 2018
    Contributor
    More actions

    This should remain open until libuv is upgraded to 2.x.

  15. jasnell commented on Jun 19, 2020

    @jasnell
    jasnell
    on Jun 19, 2020
    Member
    More actions

    Given that it's not clear if and when (if ever) libuv will move to 2.x, and given that there's been zero activity on this in over 2 years, I recommend closing as there's no action we can reasonably take here.

  16. santigimeno commented on Nov 14, 2022

    @santigimeno
    santigimeno
    on Nov 14, 2022
    Member
    More actions

    Already fixed:

    • deps: upgrade to libuv 1.43.0 #41398
    • Correct the error type of fs.writeFile with read-only mode #38607
  17. santigimeno
    closed this as completedon Nov 14, 2022
  18. BadIdeaException
    added a commit that references this issue on May 5, 2026

    fix: writability check on Windows

    4ba7742
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    fsIssues and PRs related to file-system APIs and the fs module.Issues and PRs related to file-system APIs and the fs module.libuvIssues and PRs related to the libuv dependency or the uv binding.Issues 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

      You are visitor 01402520 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.