Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const s3ObjAlreadyExists = await s3ObjectExists(target);
log.debug(`file ${target.Key} exists in ${target.Bucket}: ${s3ObjAlreadyExists}`);
const options = (bucketsConfig.type(file.bucket).match('public')) ? { ACL: 'public-read' } : null;
let versionedFiles = [];
if (s3ObjAlreadyExists) {
if (markDuplicates) fileMoved.duplicate_found = true;
// returns renamed files for 'version', otherwise empty array
versionedFiles = await handleDuplicateFile({
source,
target,
copyOptions: options,
duplicateHandling
});
} else {
await moveGranuleFile(source, target, options);
}
// return both file moved and renamed files
return [fileMoved]
.concat(versionedFiles.map((f) => ({
bucket: f.Bucket,
name: path.basename(f.Key),
filename: buildS3Uri(f.Bucket, f.Key),
filepath: f.Key,
size: f.size,
url_path: file.url_path
})));
}