How to use the @cumulus/ingest/granule.moveGranuleFile function in @cumulus/ingest

To help you get started, we’ve selected a few @cumulus/ingest examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nasa / cumulus / tasks / move-granules / index.js View on Github external
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
    })));
}