Skip to content

Commit edabb77

Browse files
voudinphoval
authored andcommitted
fix: windows replace access denied error to EPERM
fix evanw#3783 evanw#4017 On Windows, accessing a folder without read permissions results in an "access denied" error instead of EPERM. To ensure consistency across platforms, this error is now replaced with EPERM.
1 parent 4475787 commit edabb77

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

internal/fs/fs_real.go

+7
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,13 @@ func (fs *realFS) canonicalizeError(err error) error {
395395
err = syscall.ENOENT
396396
}
397397

398+
// On Windows, attempting to access a folder without read permissions
399+
// results in an "Access denied." error instead of EPERM.
400+
// To ensure consistency, this error is replaced with EPERM.
401+
if fs.fp.isWindows && os.IsPermission(err) {
402+
err = syscall.EPERM
403+
}
404+
398405
// Windows returns ENOTDIR here even though nothing we've done yet has asked
399406
// for a directory. This really means ENOENT on Windows. Return ENOENT here
400407
// so callers that check for ENOENT will successfully detect this file as

0 commit comments

Comments
 (0)