Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix writable path check in diagnose #512

Merged
merged 1 commit into from
Nov 24, 2021
Merged

Fix writable path check in diagnose #512

merged 1 commit into from
Nov 24, 2021

Conversation

tombruijn
Copy link
Member

The fs.accessSync in the isWriteableFile function only checked if
the path was readable with fs.constants.R_OK. Not if it was writable
with fs.constants.W_OK.

  • F_OK: Flag indicating that the file is visible to the calling
    process. This is useful for determining if a file exists, but says
    nothing about rwx permissions. Default if no mode is specified.
  • R_OK: Flag indicating that the file can be read by the calling
    process.
  • W_OK: Flag indicating that the file can be written by the calling
    process.
  • X_OK: Flag indicating that the file can be executed by the
    calling process. This has no effect on Windows (will behave like
    fs.constants.F_OK).

Source: https://nodejs.org/api/fs.html#file-access-constants

I've also renamed the function to isWriteable because it doesn't only
check files, but also directories.

The `fs.accessSync` in the `isWriteableFile` function only checked if
the path was readable with `fs.constants.R_OK`. Not if it was writable
with `fs.constants.W_OK`.

> - `F_OK`: Flag indicating that the file is visible to the calling
>    process. This is useful for determining if a file exists, but says
>    nothing about rwx permissions. Default if no mode is specified.
> - `R_OK`: Flag indicating that the file can be read by the calling
>    process.
> - `W_OK`: Flag indicating that the file can be written by the calling
>    process.
> - `X_OK`: Flag indicating that the file can be executed by the
>    calling process. This has no effect on Windows (will behave like
>    fs.constants.F_OK).

Source: https://nodejs.org/api/fs.html#file-access-constants

I've also renamed the function to `isWriteable` because it doesn't only
check files, but also directories.
@tombruijn tombruijn added the bug label Nov 23, 2021
@tombruijn tombruijn self-assigned this Nov 23, 2021
@tombruijn tombruijn marked this pull request as ready for review November 23, 2021 15:13
Copy link
Member

@luismiramirez luismiramirez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦🏼 I swear my brain was making me see a W instead of a R

@tombruijn tombruijn merged commit 3d6d23b into main Nov 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants