Commit 9984d2f3 authored by nanahira's avatar nanahira

use HeadObjectCommand for existing check

parent 3f76fec1
Pipeline #25386 passed with stages
in 2 minutes and 17 seconds
......@@ -217,7 +217,7 @@ export class PackagerService extends ConsoleLogger {
const hash = await this.appService.lookForExistingArchiveHash(archiveTask.path);
if (hash) {
archive.hash = hash;
archive.size = existing.Size;
archive.size = existing.ContentLength;
this.log(`Archive ${archiveName} exists, skipping.`);
return archive;
}
......@@ -235,7 +235,7 @@ export class PackagerService extends ConsoleLogger {
const hash = await this.appService.lookForExistingArchiveHash(archiveTask.path);
if (hash) {
archive.hash = hash;
archive.size = existing.Size;
archive.size = existing.ContentLength;
this.log(`Archive ${archiveName} exists, skipping.`);
return archive;
}
......@@ -274,7 +274,7 @@ export class PackagerService extends ConsoleLogger {
let tmpFilename: string;
try {
if (files.length > 1000) {
/* if (files.length > 1000) {
this.warn(`Too many files in archive ${archiveName}, using tmp file.`);
// minio would skew the stream if it's too slow
......@@ -290,7 +290,7 @@ export class PackagerService extends ConsoleLogger {
});
// open the tmp file as a new stream
uploadStream = fs.createReadStream(tmpFilename);
}
}*/
const uploadPromise = this.s3.uploadStream(archiveName, uploadStream, {
ContentType: 'application/tar+zstd',
......
......@@ -3,6 +3,7 @@ import { ConfigService } from '@nestjs/config';
import {
_Object,
DeleteObjectsCommand,
HeadObjectCommand,
ListObjectsCommand,
PutObjectCommand,
PutObjectCommandInput,
......@@ -75,9 +76,20 @@ export class S3Service extends ConsoleLogger {
}
async fileExists(path: string) {
const objects = await this.listObjects(path);
// const objects = await this.listObjects(path);
// this.log(objects);
return objects.Contents ? objects.Contents.find((obj) => obj.Key === this.getPathWithPrefix(path)) : null;
// return objects.Contents ? objects.Contents.find((obj) => obj.Key === this.getPathWithPrefix(path)) : null;
try {
const res = await this.s3.send(
new HeadObjectCommand({
Bucket: this.bucket,
Key: this.getPathWithPrefix(path),
})
);
return res;
} catch (e) {
return;
}
}
private getPathWithPrefix(filename: string) {
......
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