toolkit
toolkit copied to clipboard
io.mkdirP throws "EPERM: operation not permitted" for root directories on Windows
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:\:
for a job step:
...
- uses: actions/download-artifact@v3
with:
name: chromium
path: C:\
...
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.
ping @cory-miller @vmjoseph @thboop Can you or someone else have a look on this?
Do we have any updates on this?