1
0
Fork 0
mirror of https://github.com/actions/setup-go synced 2024-12-23 06:42:41 +00:00
Signed-off-by: Anton Troshin <anton@diagrid.io>
This commit is contained in:
Anton Troshin 2024-11-19 19:27:12 -06:00
parent e3c077dd6d
commit e91efc513b
No known key found for this signature in database
GPG key ID: 9F8A96ACA9EB6363

View file

@ -236,29 +236,20 @@ async function cacheWindowsDir(
for (const cachePath of actualCacheDirectoryPaths) { for (const cachePath of actualCacheDirectoryPaths) {
core.info(`Trying to link ${cachePath.defaultPath} to ${cachePath.actualPath}`); core.info(`Trying to link ${cachePath.defaultPath} to ${cachePath.actualPath}`);
try { try {
if (!fs.existsSync(cachePath.defaultPath)) { // the symlink already exists, skip
core.info(`Default path ${cachePath.defaultPath} does not exist`); if (fs.existsSync(cachePath.defaultPath) && fs.lstatSync(cachePath.defaultPath).isSymbolicLink()) {
core.info(`Creating directory ${cachePath.defaultPath}`); continue
fs.mkdirSync(cachePath.defaultPath, {recursive: true});
}
if (!fs.existsSync(cachePath.actualPath)) {
core.info(`Actual path ${cachePath.actualPath} does not exist. Safe to create symlink`);
} else {
core.info(`Actual path ${cachePath.actualPath} already exists. Skipping symlink creation`);
continue;
} }
// create a parent directory where the link will be created
fs.mkdirSync(path.dirname(cachePath.defaultPath), {recursive: true});
// check if the default path is a symlink // create the target directory if it doesn't exist yet
const isSymlink = fs.lstatSync(cachePath.defaultPath).isSymbolicLink(); if (!fs.existsSync(cachePath.actualPath)) {
if (isSymlink) { core.info(`Actual path ${cachePath.actualPath} does not exist. Creating`);
core.info(`Default path is symlink ${cachePath.defaultPath} => ${fs.readlinkSync(cachePath.defaultPath)}`); fs.mkdirSync(cachePath.actualPath, {recursive: true});
} else {
core.info(`Default path is not a symlink ${cachePath.defaultPath}`);
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}`);
} catch (err) { } catch (err) {
core.info(`Failed to link ${cachePath.defaultPath} to ${cachePath.actualPath}`); core.info(`Failed to link ${cachePath.defaultPath} to ${cachePath.actualPath}`);
core.info('Error: ' + err); core.info('Error: ' + err);