Skip to content

Commit 029ab37

Browse files
committed
Switch shutil.copy2 to shutil.copyfile
Existing file permissions were copied alongside the file itself, causing issues with overwrriting existing files even when in an temporary directory if user executing script did not have the appropriate permissions. This switches the `copy2` method used to `copyfile` which does not have this issue
1 parent af7a645 commit 029ab37

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

scripts/fix_rbc_release_tr.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ def _restore_tr(resampled: Path, source: Path) -> None:
244244
def _patch_head_bold(head_bold: Path, native_bold: Path, work_dir: Path) -> Path:
245245
work_dir.mkdir(parents=True, exist_ok=True)
246246
patched = work_dir / head_bold.name
247-
shutil.copy2(head_bold, patched)
247+
shutil.copyfile(head_bold, patched)
248248
_restore_tr(patched, native_bold)
249249
return patched
250250

@@ -394,11 +394,11 @@ def _export_metrics(
394394
zstd_dst = (
395395
out_func_dir / f"{stem_with_space}_reg-{reg_set}_desc-zstd_{metric}.nii.gz"
396396
)
397-
shutil.copy2(srcs["sm6"], sm6_dst)
398-
shutil.copy2(srcs["smZstd"], smzstd_dst)
397+
shutil.copyfile(srcs["sm6"], sm6_dst)
398+
shutil.copyfile(srcs["smZstd"], smzstd_dst)
399399
# ``zstd`` = z-scored raw (no smoothing); not in MetricsOutputs.
400400
zstd_src = compute_zscore(srcs["raw"], template_brain_mask)
401-
shutil.copy2(zstd_src, zstd_dst)
401+
shutil.copyfile(zstd_src, zstd_dst)
402402

403403
for atl in atlases:
404404
base = f"{stem_no_space}_atlas-{atl}_space-{run.space}_reg-{reg_set}"
@@ -408,7 +408,7 @@ def _export_metrics(
408408
# Transpose to ``(T, n_rois)`` to match AFNI's ``.1D`` and the release.
409409
ts_arr = np.loadtxt(metrics.timeseries[atl])
410410
np.savetxt(ts_dst, ts_arr.T, delimiter="\t")
411-
shutil.copy2(metrics.correlation_matrix[atl], pearson_dst)
411+
shutil.copyfile(metrics.correlation_matrix[atl], pearson_dst)
412412
_compute_partial_correlation(ts_dst, partial_dst)
413413

414414

@@ -479,13 +479,13 @@ def _process_run(
479479
f_low=bandpass[0],
480480
f_high=bandpass[1],
481481
)
482-
shutil.copy2(bp_result.regressed_bold, out_bold)
482+
shutil.copyfile(bp_result.regressed_bold, out_bold)
483483
cleaned_bold = bp_result.regressed_bold
484484

485485
bpf_reg = bandpass_regressor_file(
486486
reg_file, tr=tr, f_low=bandpass[0], f_high=bandpass[1]
487487
)
488-
shutil.copy2(bpf_reg, out_reg)
488+
shutil.copyfile(bpf_reg, out_reg)
489489
LOG.info(" wrote reg-%s -> %s", reg_set, out_bold.name)
490490

491491
if metrics_done:

0 commit comments

Comments
 (0)