Skip to content

Commit e9473a0

Browse files
cailmdaleyclaude
andcommitted
fix(scripts): fail fast if NUMBER_LIST cannot be set; dead -e guard
Review hardening: set_config_number_list now verifies the key landed in the config copy and aborts otherwise — a config with no NUMBER_LIST line and no bare [FILE] header would previously install an unmodified copy and silently process every image. Also fix init_run_exclusive_canfar.sh's missing-ID guard, which tested an unset variable and never fired. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent c23ea84 commit e9473a0

4 files changed

Lines changed: 17 additions & 5 deletions

File tree

scripts/sh/init_run_exclusive_canfar.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ function set_config_number_list() {
160160
else
161161
perl -pe 's/^\[FILE\][ \t]*$/[FILE]\nNUMBER_LIST = '$number'/' "$config_orig" > "$config_tmp"
162162
fi
163+
if ! grep -q "^NUMBER_LIST = $number$" "$config_tmp"; then
164+
echo "set_config_number_list: failed to set NUMBER_LIST in $config_orig" >&2
165+
exit 1
166+
fi
163167
mv "$config_tmp" "$config_upd"
164168
}
165169

@@ -184,7 +188,7 @@ if [ "$job" == "-1" ]; then
184188
message "No job indicated, use option -j" $debug_out 2
185189
fi
186190

187-
if [ "$exclusive" == "-1" ]; then
191+
if [ "$ID" == "-1" ]; then
188192
message "No image ID indicated, use option -e" $debug_out 3
189193
fi
190194

scripts/sh/job_sp_canfar.bash

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,10 @@ function set_config_number_list() {
354354
else
355355
perl -pe 's/^\[FILE\][ \t]*$/[FILE]\nNUMBER_LIST = '$number'/' "$config_orig" > "$config_tmp"
356356
fi
357+
if ! grep -q "^NUMBER_LIST = $number$" "$config_tmp"; then
358+
echo "set_config_number_list: failed to set NUMBER_LIST in $config_orig" >&2
359+
exit 1
360+
fi
357361
mv "$config_tmp" "$config_upd"
358362
}
359363

scripts/sh/job_sp_canfar_v2.0.bash

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,10 @@ function set_config_number_list() {
262262
else
263263
perl -pe 's/^\[FILE\][ \t]*$/[FILE]\nNUMBER_LIST = '$number'/' "$config_orig" > "$config_tmp"
264264
fi
265+
if ! grep -q "^NUMBER_LIST = $number$" "$config_tmp"; then
266+
echo "set_config_number_list: failed to set NUMBER_LIST in $config_orig" >&2
267+
exit 1
268+
fi
265269
mv "$config_tmp" "$config_upd"
266270
}
267271

src/shapepipe/pipeline/file_handler.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,10 +1086,10 @@ def _format_process_list(
10861086
if isinstance(self._number_list, type(None)):
10871087
number_list = np.load(memory_map, mmap_mode="r")
10881088
else:
1089-
# NUMBER_LIST comes from the config on faith; intersect it
1090-
# with the numbers actually found on disk so that a wrong ID
1091-
# fails here, at start-up, rather than when a module first
1092-
# tries to open the (non-existent) files (#746).
1089+
# NUMBER_LIST comes from the config on faith; check every
1090+
# entry against the numbers actually found on disk so that a
1091+
# wrong ID fails here, at start-up, rather than when a module
1092+
# first tries to open the (non-existent) files (#746).
10931093
number_list = self._number_list
10941094
scanned = set(np.load(memory_map, mmap_mode="r"))
10951095
missing = [num for num in number_list if num not in scanned]

0 commit comments

Comments
 (0)