restoreFromBackup method

ValidationResult restoreFromBackup(
  1. Map<String, String> backupMap
)

Restores files from their backup copies.

Restores previously backed up files to their original locations.

Parameters:

  • backupMap: Map of original paths to backup paths

Returns a ValidationResult indicating success or failure.

Implementation

ValidationResult restoreFromBackup(Map<String, String> backupMap) {
  final errors = <ValidationError>[];

  for (final entry in backupMap.entries) {
    final originalPath = entry.key;
    final backupPath = entry.value;

    try {
      if (exists(backupPath)) {
        copy(backupPath, originalPath);
        delete(backupPath); // Clean up backup file
      }
    } catch (e) {
      errors.add(ValidationError(
        message: 'Failed to restore $originalPath from backup: $e',
        type: ValidationErrorType.fileSystem,
      ));
    }
  }

  if (errors.isNotEmpty) {
    return ValidationResult.failure(errors: errors);
  }

  return ValidationResult.success();
}