Validate volume name in volume disk usage call (#2107)

Signed-off-by: Kathryn Baldauf <k_baldauf@apple.com>
This commit is contained in:
Kathryn Baldauf
2026-08-10 13:42:16 -07:00
committed by GitHub
parent 497465635a
commit ff5aa8a03b
@@ -174,8 +174,7 @@ public actor VolumesService {
)
}
let volumePath = self.volumePath(for: name)
return FileManager.default.allocatedSize(of: URL(fileURLWithPath: volumePath))
return try await self._volumeDiskUsage(name)
}
/// Calculate disk usage for volumes
@@ -403,4 +402,12 @@ public actor VolumesService {
return volume
}
private func _volumeDiskUsage(_ name: String) async throws -> UInt64 {
guard VolumeStorage.isValidVolumeName(name) else {
throw VolumeError.invalidVolumeName("invalid volume name '\(name)': must match \(VolumeStorage.volumeNamePattern)")
}
let volumePath = self.volumePath(for: name)
return FileManager.default.allocatedSize(of: URL(fileURLWithPath: volumePath))
}
}