diff --git a/dist/restore/index.js b/dist/restore/index.js index 7e66f6c69..144f83db7 100644 --- a/dist/restore/index.js +++ b/dist/restore/index.js @@ -664,11 +664,12 @@ function streamOutputUntilResolved(promise) { return promise; }); } -function locateCache(potentialCaches, caches) { +function locateCache(potentialCaches, cacheFiles) { for (const potentialCache of potentialCaches) { - for (const cache of caches) { - if (cache.indexOf(potentialCache) !== -1) { - return { cache, key: potentialCache }; + for (const cacheFile of cacheFiles) { + console.log({ cacheFile, potentialCache }); + if (cacheFile.indexOf(potentialCache) !== -1) { + return { cache: cacheFile, key: potentialCache }; } } } @@ -692,10 +693,10 @@ function restoreCache(paths, primaryKey, restoreKeys, options) { // 1. check if we find any dir that matches our keys from restoreKeys const mkdirPromise = execAsync(`mkdir -p ${cacheDir}`); yield streamOutputUntilResolved(mkdirPromise); - const caches = yield readDirAsync(cacheDir); - console.log({ caches }); + const cacheFiles = yield readDirAsync(cacheDir); + console.log({ caches: cacheFiles }); const potentialCaches = (restoreKeys || [primaryKey]).map(generateCacheName); - const result = locateCache(potentialCaches, caches); + const result = locateCache(potentialCaches, cacheFiles); if (typeof result !== "object") { return undefined; } diff --git a/dist/save/index.js b/dist/save/index.js index 893cab855..488d4bd41 100644 --- a/dist/save/index.js +++ b/dist/save/index.js @@ -756,11 +756,12 @@ function streamOutputUntilResolved(promise) { return promise; }); } -function locateCache(potentialCaches, caches) { +function locateCache(potentialCaches, cacheFiles) { for (const potentialCache of potentialCaches) { - for (const cache of caches) { - if (cache.indexOf(potentialCache) !== -1) { - return { cache, key: potentialCache }; + for (const cacheFile of cacheFiles) { + console.log({ cacheFile, potentialCache }); + if (cacheFile.indexOf(potentialCache) !== -1) { + return { cache: cacheFile, key: potentialCache }; } } } @@ -783,17 +784,19 @@ function restoreCache(paths, primaryKey, restoreKeys, options) { const cacheDir = path_1.join(`/media/cache/`, process.env.GITHUB_REPOSITORY || ""); // 1. check if we find any dir that matches our keys from restoreKeys const mkdirPromise = execAsync(`mkdir -p ${cacheDir}`); + // @todo order files by name/date yield streamOutputUntilResolved(mkdirPromise); - const caches = yield readDirAsync(cacheDir); - console.log({ caches }); + const cacheFiles = yield readDirAsync(cacheDir); + console.log({ caches: cacheFiles }); const potentialCaches = (restoreKeys || [primaryKey]).map(generateCacheName); - const result = locateCache(potentialCaches, caches); + const result = locateCache(potentialCaches, cacheFiles); if (typeof result !== "object") { return undefined; } const { key, cache } = result; const cachePath = path_1.join(cacheDir, cache); const cmd = `lz4 -d -v -c ${cachePath} | tar xf - -C ${path_1.dirname(paths[0])}`; + // --skip-old-files console.log({ cacheDir, cache, cachePath, key, cmd }); // 2. if we found one, rsync it back to the HD const createCacheDirPromise = execAsync(cmd); diff --git a/src/cache.ts b/src/cache.ts index bb2c50c6e..eb71e05de 100644 --- a/src/cache.ts +++ b/src/cache.ts @@ -73,12 +73,13 @@ async function streamOutputUntilResolved( function locateCache( potentialCaches, - caches + cacheFiles ): { cache: string; key: string } | boolean { for (const potentialCache of potentialCaches) { - for (const cache of caches) { - if (cache.indexOf(potentialCache) !== -1) { - return { cache, key: potentialCache }; + for (const cacheFile of cacheFiles) { + console.log({ cacheFile, potentialCache }); + if (cacheFile.indexOf(potentialCache) !== -1) { + return { cache: cacheFile, key: potentialCache }; } } } @@ -111,17 +112,19 @@ export async function restoreCache( const mkdirPromise = execAsync(`mkdir -p ${cacheDir}`); + // @todo order files by name/date + await streamOutputUntilResolved(mkdirPromise); - const caches = await readDirAsync(cacheDir); + const cacheFiles = await readDirAsync(cacheDir); - console.log({ caches }); + console.log({ caches: cacheFiles }); const potentialCaches = (restoreKeys || [primaryKey]).map( generateCacheName ); - const result = locateCache(potentialCaches, caches); + const result = locateCache(potentialCaches, cacheFiles); if (typeof result !== "object") { return undefined; @@ -133,6 +136,8 @@ export async function restoreCache( const cmd = `lz4 -d -v -c ${cachePath} | tar xf - -C ${dirname(paths[0])}`; + // --skip-old-files + console.log({ cacheDir, cache, cachePath, key, cmd }); // 2. if we found one, rsync it back to the HD