Repository Public License
1// ORIX Convert — Packages/EngineScientific/Sources/HDF5Probe/main.swift2// Description: orix-hdf5-probe: opens one HDF5 / NetCDF-4 file in a process of its own and walks everything the3// engine reads before converting (tree, dimension scales, attributes, first and last blocks of every4// dataset). If the C library crashes or loops on a damaged or crafted file, it does so here, and the5// application refuses the file instead of dying. Prints ORIX-PROBE-OK and exits 0 on completion.6// Author: Simon-Pierre Boucher — contact@spboucher.ai7import Foundation8import EngineScientific910guard CommandLine.arguments.count >= 2 else {11 FileHandle.standardError.write(Data("usage: orix-hdf5-probe <file> [seconds] [status-file]\n".utf8))12 exit(64)13}14// Self-imposed deadline, in case the parent is gone: SIGALRM ends the process.15let seconds = CommandLine.arguments.count >= 3 ? UInt32(CommandLine.arguments[2]) ?? 60 : 6016alarm(max(1, seconds))17let summary = SciProbe.exercise(URL(fileURLWithPath: CommandLine.arguments[1]))18// The status file is the proof of completion the parent relies on (written whole, then moved into place).19if CommandLine.arguments.count >= 4 {20 let status = URL(fileURLWithPath: CommandLine.arguments[3])21 try? Data("ORIX-PROBE-OK \(summary)\n".utf8).write(to: status, options: .atomic)22}23print("ORIX-PROBE-OK \(summary)")24exit(0)25