From 3d7bfe08084b81cc1d96a42a00f3fca3c700021d Mon Sep 17 00:00:00 2001 From: ehennestad Date: Fri, 18 Sep 2026 05:00:18 +0200 Subject: [PATCH 1/2] fix(stack): initialize binary files on Linux Binary.initializeFile only assigned status inside an ispc/ismac branch, so on Linux the variable was never defined and `if status` threw "Unrecognized function or variable 'status'". Every code path that creates a new .raw file failed on Linux, which surfaced in CI as five CropTest errors with the identifier NANSEN:Stack:Crop:FileNotCreated. Default status to the fallback path and only override it on Windows, where fsutil preallocates the file. Also check the fopen handle before writing, so a folder that does not exist or is not writable reports the reason instead of failing on an invalid file id, and close the file through onCleanup so it is released if fwrite errors. Co-Authored-By: Claude Opus 5 --- code/datatypes/+nansen/+stack/+virtual/Binary.m | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/code/datatypes/+nansen/+stack/+virtual/Binary.m b/code/datatypes/+nansen/+stack/+virtual/Binary.m index 7e89cef1..5a4a6d36 100644 --- a/code/datatypes/+nansen/+stack/+virtual/Binary.m +++ b/code/datatypes/+nansen/+stack/+virtual/Binary.m @@ -360,16 +360,25 @@ function initializeFile(filePath, arraySize, arrayClass) numBytes = nansen.stack.ImageStack.getImageDataByteSize(... arraySize, arrayClass); + % On Windows, fsutil preallocates the file without writing + % its contents. Every other platform, and a failed fsutil + % call, falls back to writing a sparse file with fwrite. + status = 1; if ispc [status, ~] = system(sprintf('cmd /C fsutil file createnew %s %i', filePath, numBytes)); - elseif ismac - status = 1; end if status % Backup solution - fileId = fopen(filePath, 'w'); + [fileId, errorMessage] = fopen(filePath, 'w'); + if fileId == -1 + error('NANSEN:Stack:Binary:FileNotCreated', ... + ['Could not create the binary file "%s": %s. ', ... + 'Check that the folder exists and is writable.'], ... + filePath, errorMessage) + end + fileCleanup = onCleanup(@() fclose(fileId)); fwrite(fileId, 0, 'uint8', numBytes-1); % 4th arg: skip - fclose(fileId); + clear fileCleanup % Close the file before it is mapped end else From c11f49b58a0d86642cd6d39341ef1a22be914662 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 18 Sep 2026 03:04:39 +0000 Subject: [PATCH 2/2] Update GitHub badges [skip ci] --- .github/badges/tests.svg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/badges/tests.svg b/.github/badges/tests.svg index 007b7eff..fd00e9b1 100644 --- a/.github/badges/tests.svg +++ b/.github/badges/tests.svg @@ -1 +1 @@ -tests: 333 passedtests333 passed +tests: 369 passedtests369 passed