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 { ...@@ -217,7 +217,7 @@ export class PackagerService extends ConsoleLogger {
const hash = await this.appService.lookForExistingArchiveHash(archiveTask.path); const hash = await this.appService.lookForExistingArchiveHash(archiveTask.path);
if (hash) { if (hash) {
archive.hash = hash; archive.hash = hash;
archive.size = existing.Size; archive.size = existing.ContentLength;
this.log(`Archive ${archiveName} exists, skipping.`); this.log(`Archive ${archiveName} exists, skipping.`);
return archive; return archive;
} }
...@@ -235,7 +235,7 @@ export class PackagerService extends ConsoleLogger { ...@@ -235,7 +235,7 @@ export class PackagerService extends ConsoleLogger {
const hash = await this.appService.lookForExistingArchiveHash(archiveTask.path); const hash = await this.appService.lookForExistingArchiveHash(archiveTask.path);
if (hash) { if (hash) {
archive.hash = hash; archive.hash = hash;
archive.size = existing.Size; archive.size = existing.ContentLength;
this.log(`Archive ${archiveName} exists, skipping.`); this.log(`Archive ${archiveName} exists, skipping.`);
return archive; return archive;
} }
...@@ -274,7 +274,7 @@ export class PackagerService extends ConsoleLogger { ...@@ -274,7 +274,7 @@ export class PackagerService extends ConsoleLogger {
let tmpFilename: string; let tmpFilename: string;
try { try {
if (files.length > 1000) { /* if (files.length > 1000) {
this.warn(`Too many files in archive ${archiveName}, using tmp file.`); this.warn(`Too many files in archive ${archiveName}, using tmp file.`);
// minio would skew the stream if it's too slow // minio would skew the stream if it's too slow
...@@ -290,7 +290,7 @@ export class PackagerService extends ConsoleLogger { ...@@ -290,7 +290,7 @@ export class PackagerService extends ConsoleLogger {
}); });
// open the tmp file as a new stream // open the tmp file as a new stream
uploadStream = fs.createReadStream(tmpFilename); uploadStream = fs.createReadStream(tmpFilename);
} }*/
const uploadPromise = this.s3.uploadStream(archiveName, uploadStream, { const uploadPromise = this.s3.uploadStream(archiveName, uploadStream, {
ContentType: 'application/tar+zstd', ContentType: 'application/tar+zstd',
......
...@@ -3,6 +3,7 @@ import { ConfigService } from '@nestjs/config'; ...@@ -3,6 +3,7 @@ import { ConfigService } from '@nestjs/config';
import { import {
_Object, _Object,
DeleteObjectsCommand, DeleteObjectsCommand,
HeadObjectCommand,
ListObjectsCommand, ListObjectsCommand,
PutObjectCommand, PutObjectCommand,
PutObjectCommandInput, PutObjectCommandInput,
...@@ -75,9 +76,20 @@ export class S3Service extends ConsoleLogger { ...@@ -75,9 +76,20 @@ export class S3Service extends ConsoleLogger {
} }
async fileExists(path: string) { async fileExists(path: string) {
const objects = await this.listObjects(path); // const objects = await this.listObjects(path);
// this.log(objects); // 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) { 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