From 0dc6404f6a8765723e9068eab8d6b32ae25456ce Mon Sep 17 00:00:00 2001 From: Anton Troshin Date: Tue, 19 Nov 2024 11:50:35 -0600 Subject: [PATCH] add check for existing symlink Signed-off-by: Anton Troshin --- src/installer.ts | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/installer.ts b/src/installer.ts index 66d4c95..1fada71 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -223,7 +223,7 @@ async function cacheWindowsDir( } core.info(`Found Cache Directory Paths: ${cacheDirectoryPaths}`); - + // replace cache directory path with actual cache directory path const actualCacheDirectoryPaths = cacheDirectoryPaths.map(path => { return { @@ -232,17 +232,24 @@ async function cacheWindowsDir( }; }); - // iterate through actual cache directory paths and make links + // iterate through actual cache directory paths and make links if necessary for (const cachePath of actualCacheDirectoryPaths) { if (!fs.existsSync(cachePath.actualPath)) { core.info(`Creating directory ${cachePath.actualPath}`); fs.mkdirSync(path.dirname(cachePath.actualPath), {recursive: true}); + } else { + core.info(`Directory ${cachePath.actualPath} already exists`); + // make sure the link is pointing to the actual cache directory + let symlinkTarget = fs.readlinkSync(cachePath.defaultPath); + if (symlinkTarget !== "") { + core.info(`Found link ${cachePath.defaultPath} => ${symlinkTarget}`); + } else { + fs.symlinkSync(cachePath.actualPath, cachePath.defaultPath, 'junction'); + core.info( + `Created link ${cachePath.defaultPath} => ${cachePath.actualPath}` + ); + } } - - fs.symlinkSync(cachePath.actualPath, cachePath.defaultPath, 'junction'); - core.info( - `Created link ${cachePath.defaultPath} => ${cachePath.actualPath}` - ); } // make outer code to continue using toolcache as if it were installed on c: