Skip to content

Commit

Permalink
add more logging
Browse files Browse the repository at this point in the history
  • Loading branch information
axe312ger committed May 28, 2021
1 parent ac169f2 commit 9c0d267
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 21 deletions.
15 changes: 8 additions & 7 deletions dist/restore/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}
}
}
Expand All @@ -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;
}
Expand Down
17 changes: 10 additions & 7 deletions dist/save/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}
}
}
Expand All @@ -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);
Expand Down
19 changes: 12 additions & 7 deletions src/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}
}
}
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down

0 comments on commit 9c0d267

Please sign in to comment.