Skip to content

Fix computeFileHash for cross-platform compatibility #11

@tsavo-at-pieces

Description

@tsavo-at-pieces

Overview

File: `lib/src/cli/utils/template_manifest.dart` lines 99-113

`computeFileHash()` shells out to `shasum` (macOS) then falls back to `sha256sum` (Linux). Neither command exists on Windows. The function silently returns an empty string on Windows.

Impact

On Windows:

  • Template version tracking hash is always `''`
  • `templateHash == installedHash` becomes `'' == ''` → always true
  • Templates never get updated after initial installation (stuck on first version)
  • OR all templates always show as "changed" depending on the comparison direction

Fix

Use Dart's `package:crypto` (already a transitive dependency) instead of shelling out:

import 'package:crypto/crypto.dart';
import 'dart:convert';

String computeFileHash(File file) {
  if (!file.existsSync()) return '';
  final bytes = file.readAsBytesSync();
  return sha256.convert(bytes).toString();
}

This is simpler, faster, and works on all platforms.

Acceptance Criteria

  • `computeFileHash` uses pure Dart crypto, no shell commands
  • Works on macOS, Linux, and Windows
  • Test added verifying hash computation

Metadata

Metadata

Labels

P1-highHigh priorityarea/cross-platformCross-platform support (macOS, Windows, Linux)bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions