mirror of
https://github.com/actions/toolkit.git
synced 2026-08-20 00:00:14 +02:00
Update based on testing to add trailing back slash to all results
This commit is contained in:
+12
-11
@@ -19,22 +19,23 @@ export const {
|
|||||||
export const IS_WINDOWS = process.platform === 'win32'
|
export const IS_WINDOWS = process.platform === 'win32'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Custom implementation of readlink to ensure Windows directory symlinks
|
* Custom implementation of readlink to ensure Windows junctions
|
||||||
* maintain trailing backslash for backward compatibility with Node.js < 24
|
* maintain trailing backslash for backward compatibility with Node.js < 24
|
||||||
|
*
|
||||||
|
* In Node.js 20, Windows junctions (directory symlinks) always returned paths
|
||||||
|
* with trailing backslashes. Node.js 24 removed this behavior, which breaks
|
||||||
|
* code that relied on this format for path operations.
|
||||||
|
*
|
||||||
|
* This implementation restores the Node 20 behavior by adding a trailing
|
||||||
|
* backslash to all junction results on Windows.
|
||||||
*/
|
*/
|
||||||
export async function readlink(fsPath: string): Promise<string> {
|
export async function readlink(fsPath: string): Promise<string> {
|
||||||
const result = await fs.promises.readlink(fsPath)
|
const result = await fs.promises.readlink(fsPath)
|
||||||
|
|
||||||
// Only on Windows, ensure directory symlinks end with a backslash
|
// On Windows, restore Node 20 behavior: add trailing backslash to all results
|
||||||
if (IS_WINDOWS) {
|
// since junctions on Windows are always directory links
|
||||||
try {
|
if (IS_WINDOWS && !result.endsWith('\\')) {
|
||||||
const stats = await fs.promises.lstat(result)
|
return `${result}\\`
|
||||||
if (stats.isDirectory() && !result.endsWith('\\')) {
|
|
||||||
return `${result}\\`
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
// If we can't access the target, just return the original result
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|||||||
Reference in New Issue
Block a user