isModified method

Future<bool> isModified(
  1. String filePath
)

Implementation

Future<bool> isModified(String filePath) async {
  if (!context.config.cacheEnabled || !_initialized) return true;

  final file = File(p.join(context.directory, filePath));
  if (!await file.exists()) {
    // If it doesn't exist anymore, it's a modification (deletion)
    return true;
  }

  final stat = await file.stat();
  final lastModified = stat.modified.millisecondsSinceEpoch;

  // Quick check based on modification time
  if (_cache.containsKey(filePath)) {
    final cachedEntry = _cache[filePath] as Map<String, dynamic>;
    final cachedTime = cachedEntry['timestamp'] as int?;

    if (cachedTime != null && cachedTime == lastModified) {
      return false;
    }

    // If timestamp doesn't match, verify hash
    final currentHash = await _calculateHash(file);
    final cachedHash = cachedEntry['hash'] as String?;

    if (currentHash == cachedHash) {
      // Update timestamp in cache to avoid future hash calculations
      cachedEntry['timestamp'] = lastModified;
      return false;
    }
  }

  return true;
}