From 893d6d7c07a506524997fb8e65988dbe4790fa9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20M=C3=BCller?= Date: Wed, 17 Apr 2024 12:26:03 +0200 Subject: [PATCH] fix: avoid possible name clashes when storing logs in DC output file --- CHANGELOG | 1 + mpl_data_cast/mod_recipes/rcp_rtdc.py | 15 ++++++++++++--- pyproject.toml | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 2546654..007b118 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,6 @@ 0.6.3 - fix: cleanup temporary directories on startup (#29) + - fix: avoid possible name clashes when storing logs in DC output file - enh: warn user when source and target directory are identical (#28) 0.6.2 - setup: bump dclab from 0.55.7 to 0.57.0 diff --git a/mpl_data_cast/mod_recipes/rcp_rtdc.py b/mpl_data_cast/mod_recipes/rcp_rtdc.py index a8a336f..93333d9 100644 --- a/mpl_data_cast/mod_recipes/rcp_rtdc.py +++ b/mpl_data_cast/mod_recipes/rcp_rtdc.py @@ -19,9 +19,18 @@ def convert_dataset(self, path_list, temp_path, **kwargs): if len(path_list) > 1: with dclab.RTDCWriter(temp_path, compression_kwargs=cmp_kw) as hw: for pp in path_list[1:]: - lines = pp.read_text().split("\n") - lines = [ll.rstrip() for ll in lines] - hw.store_log(pp.name, lines) + while True: + # avoid name clashes + ii = 0 + log_name = pp.name + f"-{ii}" if ii else pp.name + if log_name in hw.h5file.get("logs", {}): + ii += 1 + continue + # write the log file + lines = pp.read_text().split("\n") + lines = [ll.rstrip() for ll in lines] + hw.store_log(log_name, lines) + break def get_raw_data_iterator(self): """Get list of .rtdc files including associated files""" diff --git a/pyproject.toml b/pyproject.toml index 86abb6e..1321b71 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,7 +24,7 @@ classifiers = [ license = {text = "GPL v3"} dependencies = [ "click>=8", - "dclab>=0.57.0", + "dclab>=0.58.2", "h5py>=3.8.0", "hdf5plugin", # compression "numpy>=1.21", # CVE-2021-33430