generateChecksum method

Future<String> generateChecksum(
  1. String artifactPath
)

Generates a checksum file in the same directory as artifactPath.

The checksum file will be named <filename>.sha256. Returns the absolute path to the generated checksum file.

Implementation

Future<String> generateChecksum(String artifactPath) async {
  final entityType = FileSystemEntity.typeSync(artifactPath);
  if (entityType == FileSystemEntityType.notFound) {
    throw ReleaseManagerException('Cannot generate checksum: Artifact not found at $artifactPath');
  }

  String hashValue;
  if (entityType == FileSystemEntityType.directory) {
    hashValue = await _hashDirectory(Directory(artifactPath));
  } else {
    hashValue = await _hashFile(File(artifactPath));
  }

  final filename = p.basename(artifactPath);
  final checksumFilePath = p.join(p.dirname(artifactPath), '$filename.sha256');
  final checksumFile = File(checksumFilePath);

  final generatedTime = DateFormat('yyyy-MM-dd HH:mm:ss').format(DateTime.now());

  final content = '''
$hashValue
$filename
$generatedTime
''';

  await checksumFile.writeAsString(content);

  return checksumFile.absolute.path;
}