mirror of
				https://github.com/Swatinem/rust-cache.git
				synced 2025-10-31 16:13:49 +00:00 
			
		
		
		
	force a cache
This commit is contained in:
		
							parent
							
								
									6095cc4363
								
							
						
					
					
						commit
						470b5b92f9
					
				
							
								
								
									
										42
									
								
								dist/restore/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										42
									
								
								dist/restore/index.js
									
									
									
									
										vendored
									
									
								
							| @ -87373,26 +87373,8 @@ async function run() { | ||||
|             lookupOnly, | ||||
|         }); | ||||
|         if (restoreKey) { | ||||
|             const match = restoreKey === key; | ||||
|             let match = restoreKey === key; | ||||
|             lib_core.info(`${lookupOnly ? "Found" : "Restored from"} cache key "${restoreKey}" full match: ${match}.`); | ||||
|             // Restore the incremental-restore.json file and write the mtimes to all the files in the list
 | ||||
|             if (config.incremental) { | ||||
|                 try { | ||||
|                     const restoreJson = external_path_default().join(config_CARGO_HOME, "incremental-restore.json"); | ||||
|                     const restoreString = await external_fs_default().promises.readFile(restoreJson, "utf8"); | ||||
|                     const restoreData = JSON.parse(restoreString); | ||||
|                     const incrementalKey = await cacheProvider.cache.restoreCache(restoreData.roots, config.incrementalKey, [config.restoreKey], { lookupOnly }); | ||||
|                     lib_core.debug(`restoring incremental builds from ${incrementalKey}`); | ||||
|                     for (const [file, mtime] of Object.entries(restoreData.times)) { | ||||
|                         lib_core.debug(`restoring ${file} with mtime ${mtime}`); | ||||
|                         await external_fs_default().promises.utimes(file, new Date(mtime), new Date(mtime)); | ||||
|                     } | ||||
|                 } | ||||
|                 catch (err) { | ||||
|                     lib_core.debug(`Could not restore incremental cache - ${err}`); | ||||
|                     lib_core.debug(`${err.stack}`); | ||||
|                 } | ||||
|             } | ||||
|             if (!match) { | ||||
|                 // pre-clean the target directory on cache mismatch
 | ||||
|                 for (const workspace of config.workspaces) { | ||||
| @ -87404,6 +87386,28 @@ async function run() { | ||||
|                 // We restored the cache but it is not a full match.
 | ||||
|                 config.saveState(); | ||||
|             } | ||||
|             // Restore the incremental-restore.json file and write the mtimes to all the files in the list
 | ||||
|             if (config.incremental) { | ||||
|                 try { | ||||
|                     const restoreJson = external_path_default().join(config_CARGO_HOME, "incremental-restore.json"); | ||||
|                     const restoreString = await external_fs_default().promises.readFile(restoreJson, "utf8"); | ||||
|                     const restoreData = JSON.parse(restoreString); | ||||
|                     if (restoreData.roots.length == 0) { | ||||
|                         throw new Error("No incremental roots found"); | ||||
|                     } | ||||
|                     const incrementalKey = await cacheProvider.cache.restoreCache(restoreData.roots, config.incrementalKey, [config.restoreKey], { lookupOnly }); | ||||
|                     lib_core.debug(`restoring incremental builds from ${incrementalKey}`); | ||||
|                     for (const [file, mtime] of Object.entries(restoreData.times)) { | ||||
|                         lib_core.debug(`restoring ${file} with mtime ${mtime}`); | ||||
|                         await external_fs_default().promises.utimes(file, new Date(mtime), new Date(mtime)); | ||||
|                     } | ||||
|                 } | ||||
|                 catch (err) { | ||||
|                     lib_core.debug(`Could not restore incremental cache - ${err}`); | ||||
|                     lib_core.debug(`${err.stack}`); | ||||
|                     match = false; | ||||
|                 } | ||||
|             } | ||||
|             setCacheHitOutput(match); | ||||
|         } | ||||
|         else { | ||||
|  | ||||
							
								
								
									
										27
									
								
								dist/save/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										27
									
								
								dist/save/index.js
									
									
									
									
										vendored
									
									
								
							| @ -87334,6 +87334,9 @@ async function rmRF(dirName) { | ||||
| ;// CONCATENATED MODULE: ./src/incremental.ts
 | ||||
| // import * as core from "@actions/core";
 | ||||
| // import * as io from "@actions/io";
 | ||||
| // import { CARGO_HOME } from "./config";
 | ||||
| // import { exists } from "./utils";
 | ||||
| // import { Packages } from "./workspace";
 | ||||
| 
 | ||||
| 
 | ||||
| async function saveMtimes(targetDirs) { | ||||
| @ -87480,30 +87483,6 @@ async function macOsWorkaround() { | ||||
|     } | ||||
|     catch { } | ||||
| } | ||||
| // async function saveIncrementalDirs(incrementalDir: string) {
 | ||||
| //   // Traverse the incremental folder recursively and collect the modified times in a map
 | ||||
| //   const modifiedTimes = new Map<string, number>();
 | ||||
| //   const fillModifiedTimes = async (dir: string) => {
 | ||||
| //     const dirEntries = await fs.promises.opendir(dir);
 | ||||
| //     for await (const dirent of dirEntries) {
 | ||||
| //       if (dirent.isDirectory()) {
 | ||||
| //         await fillModifiedTimes(path.join(dir, dirent.name));
 | ||||
| //       } else {
 | ||||
| //         const fileName = path.join(dir, dirent.name);
 | ||||
| //         const { mtime } = await fs.promises.stat(fileName);
 | ||||
| //         modifiedTimes.set(fileName, mtime.getTime());
 | ||||
| //       }
 | ||||
| //     }
 | ||||
| //   };
 | ||||
| //   await fillModifiedTimes(incrementalDir);
 | ||||
| //   // Write the modified times to the incremental folder
 | ||||
| //   core.debug(`writing incremental-restore.json for ${incrementalDir} files`);
 | ||||
| //   for (const file of modifiedTimes.keys()) {
 | ||||
| //     core.debug(`  ${file} -> ${modifiedTimes.get(file)}`);
 | ||||
| //   }
 | ||||
| //   const contents = JSON.stringify({ modifiedTimes });
 | ||||
| //   await fs.promises.writeFile(path.join(incrementalDir, "incremental-restore.json"), contents);
 | ||||
| // }
 | ||||
| 
 | ||||
| })(); | ||||
| 
 | ||||
|  | ||||
| @ -1,12 +1,12 @@ | ||||
| // import * as core from "@actions/core";
 | ||||
| // import * as io from "@actions/io";
 | ||||
| import fs from "fs"; | ||||
| import path from "path"; | ||||
| 
 | ||||
| // import { CARGO_HOME } from "./config";
 | ||||
| // import { exists } from "./utils";
 | ||||
| // import { Packages } from "./workspace";
 | ||||
| 
 | ||||
| import fs from "fs"; | ||||
| import path from "path"; | ||||
| 
 | ||||
| export type MtimeData = { | ||||
|   roots: Array<string>, | ||||
|   times: Map<string, number> | ||||
|  | ||||
| @ -49,9 +49,21 @@ async function run() { | ||||
|       lookupOnly, | ||||
|     }); | ||||
|     if (restoreKey) { | ||||
|       const match = restoreKey === key; | ||||
|       let match = restoreKey === key; | ||||
|       core.info(`${lookupOnly ? "Found" : "Restored from"} cache key "${restoreKey}" full match: ${match}.`); | ||||
| 
 | ||||
|       if (!match) { | ||||
|         // pre-clean the target directory on cache mismatch
 | ||||
|         for (const workspace of config.workspaces) { | ||||
|           try { | ||||
|             await cleanTargetDir(workspace.target, [], true); | ||||
|           } catch { } | ||||
|         } | ||||
| 
 | ||||
|         // We restored the cache but it is not a full match.
 | ||||
|         config.saveState(); | ||||
|       } | ||||
| 
 | ||||
|       // Restore the incremental-restore.json file and write the mtimes to all the files in the list
 | ||||
|       if (config.incremental) { | ||||
|         try { | ||||
| @ -59,6 +71,10 @@ async function run() { | ||||
|           const restoreString = await fs.promises.readFile(restoreJson, "utf8"); | ||||
|           const restoreData: MtimeData = JSON.parse(restoreString); | ||||
| 
 | ||||
|           if (restoreData.roots.length == 0) { | ||||
|             throw new Error("No incremental roots found"); | ||||
|           } | ||||
| 
 | ||||
|           const incrementalKey = await cacheProvider.cache.restoreCache(restoreData.roots, config.incrementalKey, [config.restoreKey], { lookupOnly }); | ||||
|           core.debug(`restoring incremental builds from ${incrementalKey}`); | ||||
| 
 | ||||
| @ -70,21 +86,10 @@ async function run() { | ||||
|         } catch (err) { | ||||
|           core.debug(`Could not restore incremental cache - ${err}`); | ||||
|           core.debug(`${(err as any).stack}`); | ||||
|           match = false; | ||||
|         } | ||||
|       } | ||||
| 
 | ||||
|       if (!match) { | ||||
|         // pre-clean the target directory on cache mismatch
 | ||||
|         for (const workspace of config.workspaces) { | ||||
|           try { | ||||
|             await cleanTargetDir(workspace.target, [], true); | ||||
|           } catch { } | ||||
|         } | ||||
| 
 | ||||
|         // We restored the cache but it is not a full match.
 | ||||
|         config.saveState(); | ||||
|       } | ||||
| 
 | ||||
|       setCacheHitOutput(match); | ||||
|     } else { | ||||
|       core.info(`No cache found for ${config.cacheKey} - this key was found ${restoreKey}`); | ||||
|  | ||||
							
								
								
									
										28
									
								
								src/save.ts
									
									
									
									
									
								
							
							
						
						
									
										28
									
								
								src/save.ts
									
									
									
									
									
								
							| @ -120,31 +120,3 @@ async function macOsWorkaround() { | ||||
|     await exec.exec("sudo", ["/usr/sbin/purge"], { silent: true }); | ||||
|   } catch { } | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| // async function saveIncrementalDirs(incrementalDir: string) {
 | ||||
| //   // Traverse the incremental folder recursively and collect the modified times in a map
 | ||||
| //   const modifiedTimes = new Map<string, number>();
 | ||||
| //   const fillModifiedTimes = async (dir: string) => {
 | ||||
| //     const dirEntries = await fs.promises.opendir(dir);
 | ||||
| //     for await (const dirent of dirEntries) {
 | ||||
| //       if (dirent.isDirectory()) {
 | ||||
| //         await fillModifiedTimes(path.join(dir, dirent.name));
 | ||||
| //       } else {
 | ||||
| //         const fileName = path.join(dir, dirent.name);
 | ||||
| //         const { mtime } = await fs.promises.stat(fileName);
 | ||||
| //         modifiedTimes.set(fileName, mtime.getTime());
 | ||||
| //       }
 | ||||
| //     }
 | ||||
| //   };
 | ||||
| //   await fillModifiedTimes(incrementalDir);
 | ||||
| 
 | ||||
| //   // Write the modified times to the incremental folder
 | ||||
| //   core.debug(`writing incremental-restore.json for ${incrementalDir} files`);
 | ||||
| //   for (const file of modifiedTimes.keys()) {
 | ||||
| //     core.debug(`  ${file} -> ${modifiedTimes.get(file)}`);
 | ||||
| //   }
 | ||||
| //   const contents = JSON.stringify({ modifiedTimes });
 | ||||
| //   await fs.promises.writeFile(path.join(incrementalDir, "incremental-restore.json"), contents);
 | ||||
| 
 | ||||
| // }
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user