mirror of https://github.com/actions/setup-go.git
				
				
				
			remove empty cache folders to be able to create symlinks
Signed-off-by: Anton Troshin <anton@diagrid.io>
This commit is contained in:
		
							parent
							
								
									e91efc513b
								
							
						
					
					
						commit
						5b1dffca1b
					
				|  | @ -88402,28 +88402,29 @@ function cacheWindowsDir(extPath, tool, version, arch) { | ||||||
|         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_1.default.existsSync(cachePath.defaultPath)) { |                 // the symlink already exists, skip
 | ||||||
|                     core.info(`Default path ${cachePath.defaultPath} does not exist`); |                 const stats = fs_1.default.lstatSync(cachePath.defaultPath); | ||||||
|                     core.info(`Creating directory ${cachePath.defaultPath}`); |                 if (fs_1.default.existsSync(cachePath.defaultPath) && stats.isSymbolicLink()) { | ||||||
|                     fs_1.default.mkdirSync(cachePath.defaultPath, { recursive: true }); |                     core.info(`Directory ${cachePath.defaultPath} already linked. Skipping`); | ||||||
|                 } |  | ||||||
|                 if (!fs_1.default.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; |                     continue; | ||||||
|                 } |                 } | ||||||
|                 // check if the default path is a symlink
 |                 // the directory is empty, delete it to be able to create a symlink
 | ||||||
|                 const isSymlink = fs_1.default.lstatSync(cachePath.defaultPath).isSymbolicLink(); |                 if (stats.size == 0) { | ||||||
|                 if (isSymlink) { |                     fs_1.default.rmSync(cachePath.defaultPath, { recursive: true, force: true }); | ||||||
|                     core.info(`Default path is symlink ${cachePath.defaultPath} => ${fs_1.default.readlinkSync(cachePath.defaultPath)}`); |  | ||||||
|                 } |                 } | ||||||
|                 else { |                 else { | ||||||
|                     core.info(`Default path is not a symlink ${cachePath.defaultPath}`); |                     core.info(`Directory ${cachePath.defaultPath} is not empty. Skipping`); | ||||||
|                     fs_1.default.symlinkSync(cachePath.actualPath, cachePath.defaultPath, 'junction'); |                     continue; | ||||||
|                     core.info(`Created link ${cachePath.defaultPath} => ${cachePath.actualPath}`); |  | ||||||
|                 } |                 } | ||||||
|  |                 // create a parent directory where the link will be created
 | ||||||
|  |                 fs_1.default.mkdirSync(path.dirname(cachePath.defaultPath), { recursive: true }); | ||||||
|  |                 // create the target directory if it doesn't exist yet
 | ||||||
|  |                 if (!fs_1.default.existsSync(cachePath.actualPath)) { | ||||||
|  |                     core.info(`Actual path ${cachePath.actualPath} does not exist. Creating`); | ||||||
|  |                     fs_1.default.mkdirSync(cachePath.actualPath, { recursive: true }); | ||||||
|  |                 } | ||||||
|  |                 fs_1.default.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}`); | ||||||
|  |  | ||||||
|  | @ -237,9 +237,18 @@ async function cacheWindowsDir( | ||||||
|     core.info(`Trying to link ${cachePath.defaultPath} to ${cachePath.actualPath}`); |     core.info(`Trying to link ${cachePath.defaultPath} to ${cachePath.actualPath}`); | ||||||
|     try { |     try { | ||||||
|       // the symlink already exists, skip
 |       // the symlink already exists, skip
 | ||||||
|       if (fs.existsSync(cachePath.defaultPath) && fs.lstatSync(cachePath.defaultPath).isSymbolicLink()) { |       const stats = fs.lstatSync(cachePath.defaultPath); | ||||||
|  |       if (fs.existsSync(cachePath.defaultPath) && stats.isSymbolicLink()) { | ||||||
|  |         core.info(`Directory ${cachePath.defaultPath} already linked. Skipping`); | ||||||
|         continue |         continue | ||||||
|       } |       } | ||||||
|  |       // the directory is empty, delete it to be able to create a symlink
 | ||||||
|  |       if (stats.size == 0) { | ||||||
|  |         fs.rmSync(cachePath.defaultPath, {recursive: true, force: true}); | ||||||
|  |       } else { | ||||||
|  |         core.info(`Directory ${cachePath.defaultPath} is not empty. Skipping`); | ||||||
|  |         continue; | ||||||
|  |       } | ||||||
|       // create a parent directory where the link will be created
 |       // create a parent directory where the link will be created
 | ||||||
|       fs.mkdirSync(path.dirname(cachePath.defaultPath), {recursive: true}); |       fs.mkdirSync(path.dirname(cachePath.defaultPath), {recursive: true}); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	 Anton Troshin
						Anton Troshin