toolkit icon indicating copy to clipboard operation
toolkit copied to clipboard

io.mkdirP throws "EPERM: operation not permitted" for root directories on Windows

Open tusharsnx opened this issue 2 years ago • 2 comments

Describe the bug io.mkdirP throws EPERM: operation not permitted error for root directories (e.g. C:\) on Windows even if it already exists.

In the node's official docs:

On Windows, using fs.mkdir() on the root directory even with recursion will result in an error

With fs.mkdir which mkdirP uses for its impl, the EPERM error is expected when path is root directory even if it exists on Windows. Most of the third party actions which uses @actions/io does not account for this behaviour and calls mkdirP unconditionally without checking/handling the error. This is also the case with @actions/io, @actions/cache, @actions/artifact, @actions/tool-cache.

mkdirP should behave consistently across platforms.

To Reproduce Steps to reproduce the behavior: Running below snippet would lead to error:

const io = require("@actions/io")
await io.mkdirP("C:\\")

Expected behavior mkdirP shouldn't throw if path already exists (this is already true for Linux).

Screenshots using "actions/download-artifact" (which internally uses io.mkdirP) fails to run when path is C:\, or D:\:

Screenshot 2023-05-14 213225

for a job step:

...
- uses: actions/download-artifact@v3
  with:
    name: chromium
    path: C:\
...

tusharsnx avatar May 14 '23 16:05 tusharsnx

Seems like #444 (#781) broke io.mkdirP, particularly with the removal of these lines.

fs.stat'ing throws no error when the drive exists. So the default: case would've gracefully handled all EPERM errors in these cases.

image

ping @cory-miller @vmjoseph @thboop Can you or someone else have a look on this?

tusharsnx avatar May 17 '23 08:05 tusharsnx

Do we have any updates on this?

tusharsnx avatar May 16 '24 08:05 tusharsnx