Skip to content

Fix slow cache restore on Windows #515

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
wrap with try, debugging errors
Signed-off-by: Anton Troshin <anton@diagrid.io>
  • Loading branch information
antontroshin committed Nov 19, 2024
commit c8eefa5dde1822ec9819c2ffc4b7a539749ec980
38 changes: 22 additions & 16 deletions src/installer.ts
Original file line number Diff line number Diff line change
@@ -235,22 +235,28 @@ async function cacheWindowsDir(
// iterate through actual cache directory paths and make links if necessary
for (const cachePath of actualCacheDirectoryPaths) {
core.info(`Trying to link ${cachePath.defaultPath} to ${cachePath.actualPath}`);
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
const symlinkTarget = fs.readlinkSync(cachePath.defaultPath);
core.info(`Symlink target: ${symlinkTarget}`);
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}`
);
try {
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`);
}

// check if the default path is a symlink
const isSymlink = fs.lstatSync(cachePath.defaultPath).isSymbolicLink();
if (isSymlink) {
core.info(`Default path is symlink ${cachePath.defaultPath} => ${fs.readlinkSync(cachePath.defaultPath)}`);
} 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}`
);
}
} catch (err) {
core.info(`Failed to link ${cachePath.defaultPath} to ${cachePath.actualPath}`);
core.info('Error: ' + err);
}
}