cleanGlobalTargets method
Cleans a list of global cache targets.
Implementation
Future<CleanResult> cleanGlobalTargets(List<CacheTarget> targets) async {
final deletedPaths = <String>[];
final failedPaths = <String, String>{};
int reclaimedSize = 0;
for (final target in targets) {
// Validate that it's a global target
if (!target.isGlobal) {
failedPaths[target.path] = 'Not a global cache target';
continue;
}
// Validate deletion safety
final validationError = SafetyUtils.validateDeletion(
target,
target.path, // For global targets, use the target path itself as root
);
if (validationError != null) {
failedPaths[target.path] = validationError;
continue;
}
// Attempt deletion
final success = await _deleteTarget(target);
if (success) {
deletedPaths.add(target.path);
reclaimedSize += target.size;
} else {
failedPaths[target.path] = 'Failed to delete';
}
}
return CleanResult(
deletedPaths: deletedPaths,
failedPaths: failedPaths,
reclaimedSize: reclaimedSize,
);
}