chore(populateCache): skip if blob already cached
This commit is contained in:
parent
023e7af0ba
commit
31fb997b69
2 changed files with 22 additions and 6 deletions
|
@ -4,7 +4,7 @@ import fs from 'fs/promises';
|
||||||
import git from 'isomorphic-git';
|
import git from 'isomorphic-git';
|
||||||
import http from 'isomorphic-git/http/node';
|
import http from 'isomorphic-git/http/node';
|
||||||
|
|
||||||
import { isWriteable, pointsToLFS } from './util';
|
import { isVacantAndWriteable, isWriteable, pointsToLFS } from './util';
|
||||||
import downloadBlobFromPointer from './download';
|
import downloadBlobFromPointer from './download';
|
||||||
import { readPointer } from "./pointers";
|
import { readPointer } from "./pointers";
|
||||||
|
|
||||||
|
@ -55,8 +55,9 @@ export default async function populateCache(workDir: string, ref: string = 'HEAD
|
||||||
if (pointsToLFS(buff)) {
|
if (pointsToLFS(buff)) {
|
||||||
const pointer = readPointer({ dir: workDir, content: buff });
|
const pointer = readPointer({ dir: workDir, content: buff });
|
||||||
|
|
||||||
// Don’t even start the download if LFS cache path is not accessible.
|
// Don’t even start the download if LFS cache path is not accessible,
|
||||||
if (await isWriteable(pointer.objectPath) === false)
|
// or if it already exists
|
||||||
|
if (await isVacantAndWriteable(pointer.objectPath) === false)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const content = await downloadBlobFromPointer(
|
const content = await downloadBlobFromPointer(
|
||||||
|
|
21
src/util.ts
21
src/util.ts
|
@ -20,12 +20,27 @@ export async function isWriteable(filepath: string): Promise<boolean> {
|
||||||
await fs.access(filepath, fsConstants.W_OK);
|
await fs.access(filepath, fsConstants.W_OK);
|
||||||
return true;
|
return true;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if ((e as { code: string }).code !== 'ENOENT') {
|
if ((e as { code: string }).code === 'ENOENT') {
|
||||||
return false;
|
return true;
|
||||||
} else {
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if given path is available for writing
|
||||||
|
* and not occupied.
|
||||||
|
*/
|
||||||
|
export async function isVacantAndWriteable(filepath: string): Promise<boolean> {
|
||||||
|
try {
|
||||||
|
await fs.access(filepath, fsConstants.W_OK);
|
||||||
|
} catch (e) {
|
||||||
|
if ((e as { code: string }).code === 'ENOENT') {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue