Commit d3d950a2 authored by nanahira's avatar nanahira

check file exists before upload

parent 72206c32
Pipeline #5439 passed with stages
in 2 minutes and 56 seconds
...@@ -76,8 +76,11 @@ export class MirrorService extends ConsoleLogger { ...@@ -76,8 +76,11 @@ export class MirrorService extends ConsoleLogger {
} }
private async saveMirrorFromPath(archive: Archive) { private async saveMirrorFromPath(archive: Archive) {
if (!(await this.packageS3.fileExists(archive.archiveFullPath))) {
return [];
}
const uploadInfo: UploadInfo = { const uploadInfo: UploadInfo = {
url: this.packageS3.getCdnUrl(`${archive.path}.tar.zst`), url: this.packageS3.getCdnUrl(archive.archiveFullPath),
size: archive.size, size: archive.size,
}; };
return _.compact( return _.compact(
...@@ -128,11 +131,10 @@ export class MirrorService extends ConsoleLogger { ...@@ -128,11 +131,10 @@ export class MirrorService extends ConsoleLogger {
.distinctOn(['archive.path']) .distinctOn(['archive.path'])
.from(Archive, 'archive') .from(Archive, 'archive')
.where('archive.size <= :maximumMirroredSize', { maximumMirroredSize: this.maximumMirroredSize }); .where('archive.size <= :maximumMirroredSize', { maximumMirroredSize: this.maximumMirroredSize });
query query.andWhere(
.andWhere( `not exists ${query.subQuery().select('mirror.path').from(ArchiveMirror, 'mirror').where('archive.path = mirror.path').getQuery()}`
`not exists ${query.subQuery().select('mirror.path').from(ArchiveMirror, 'mirror').where('archive.path = mirror.path').getQuery()}` );
) //.take(100);
.take(100);
this.log(`Searching for archives to mirror`); this.log(`Searching for archives to mirror`);
const archives = await query.getMany(); const archives = await query.getMany();
if (!archives.length) { if (!archives.length) {
...@@ -141,7 +143,7 @@ export class MirrorService extends ConsoleLogger { ...@@ -141,7 +143,7 @@ export class MirrorService extends ConsoleLogger {
this.log(`Uploading ${archives.length} archives.`); this.log(`Uploading ${archives.length} archives.`);
const uploadResults = _.flatten(await Promise.all(archives.map((a) => this.saveMirrorFromPath(a)))); const uploadResults = _.flatten(await Promise.all(archives.map((a) => this.saveMirrorFromPath(a))));
if (!uploadResults) { if (!uploadResults) {
this.error(`All uploads failed, exiting.`); this.error(`Nothing uploaded, exiting.`);
return false; return false;
} }
this.log(`Saving ${uploadResults.length} mirror records.`); this.log(`Saving ${uploadResults.length} mirror records.`);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment