Skip to content

[BUG] log cleanup procedure runs when logs-max=0 and throws error on permissions but not missing directory #6270

@jmealo

Description

@jmealo

Is there an existing issue for this?

  • I have searched the existing issues

This issue exists in the latest npm version

  • I am using the latest npm

Current Behavior

When running npm with logs_max=0 npm still attempts to run the log cleanup routine. This routine attempts to scandir. If this is happening in CI where npm is being invoked as root this causes a permission error and warning to be output for every npm run command:

[2023-03-10T19:21:39.786Z] npm WARN logfile Error: EACCES: permission denied, scandir '/root/.npm/_logs'
[2023-03-10T19:21:39.786Z] npm WARN logfile  error cleaning log files [Error: EACCES: permission denied, scandir '/root/.npm/_logs'] {
[2023-03-10T19:21:39.786Z] npm WARN logfile   errno: -13,
[2023-03-10T19:21:39.786Z] npm WARN logfile   code: 'EACCES',
[2023-03-10T19:21:39.786Z] npm WARN logfile   syscall: 'scandir',
[2023-03-10T19:21:39.786Z] npm WARN logfile   path: '/root/.npm/_logs'
[2023-03-10T19:21:39.786Z] npm WARN logfile }

What's odd though, is if the directory is non-existent, no warning is printed.

Expected Behavior

The cleanup routine not to run when logs_max=0.
To not have warnings for every npm run command in CI :)

Steps To Reproduce

  1. Using official Node docker images
  2. Running as a user that doesn't have permission to write to the logs directory (try running as the root user)
  3. Run any npm run command with logs-max=0 in the .npmrc or NPM_CONFIG_LOGS_MAX= on the env
  4. The cleanup routine will still attempt to run and will print a warning

Environment

  • npm: 8.19.2
  • Node.js: v18.12.1
  • OS Name: MacOS
  • System Model Name: MacBook Pro (14-inch, 2021) [Apple M1 Pro]
  • npm config:
always-auth = false 
engine-strict = true
logs-max = 0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bugthing that needs fixingNeeds Triageneeds review for next stepsRelease 8.xwork is associated with a specific npm 8 release

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions