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 http from 'isomorphic-git/http/node';
|
||||
|
||||
import { isWriteable, pointsToLFS } from './util';
|
||||
import { isVacantAndWriteable, isWriteable, pointsToLFS } from './util';
|
||||
import downloadBlobFromPointer from './download';
|
||||
import { readPointer } from "./pointers";
|
||||
|
||||
|
@ -55,8 +55,9 @@ export default async function populateCache(workDir: string, ref: string = 'HEAD
|
|||
if (pointsToLFS(buff)) {
|
||||
const pointer = readPointer({ dir: workDir, content: buff });
|
||||
|
||||
// Don’t even start the download if LFS cache path is not accessible.
|
||||
if (await isWriteable(pointer.objectPath) === false)
|
||||
// Don’t even start the download if LFS cache path is not accessible,
|
||||
// or if it already exists
|
||||
if (await isVacantAndWriteable(pointer.objectPath) === false)
|
||||
return;
|
||||
|
||||
const content = await downloadBlobFromPointer(
|
||||
|
|
19
src/util.ts
19
src/util.ts
|
@ -20,12 +20,27 @@ export async function isWriteable(filepath: string): Promise<boolean> {
|
|||
await fs.access(filepath, fsConstants.W_OK);
|
||||
return true;
|
||||
} catch (e) {
|
||||
if ((e as { code: string }).code !== 'ENOENT') {
|
||||
if ((e as { code: string }).code === 'ENOENT') {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} else {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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 false;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue