Skip to content

Commit f8be2af

Browse files
JKBTeque5
authored andcommitted
implement NCD detection; fix file deletion on Windows
1 parent b6161e8 commit f8be2af

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

sigmf/sigmffile.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,12 @@ def set_data_file(self, data_file=None, data_buffer=None, skip_checksum=False, o
558558
self._memmap = raveled.reshape(mapped_reshape)
559559
self.shape = self._memmap.shape if (self._return_type is None) else self._memmap.shape[:-1]
560560

561+
if self.data_file is not None:
562+
file_name = path.split(self.data_file)[1]
563+
ext = path.splitext(file_name)[1]
564+
if ext.lower() != SIGMF_DATASET_EXT:
565+
self.set_global_field(SigMFFile.DATASET_KEY, file_name)
566+
561567
if skip_checksum:
562568
return None
563569
return self.calculate_hash()
@@ -937,7 +943,7 @@ def get_dataset_filename_from_metadata(meta_fn, metadata=None):
937943
3. None (may be a metadata only distribution)
938944
"""
939945
compliant_filename = get_sigmf_filenames(meta_fn)["data_fn"]
940-
noncompliant_filename = metadata["global"].get("core:dataset", None)
946+
noncompliant_filename = metadata["global"].get(SigMFFile.DATASET_KEY, None)
941947

942948
if path.isfile(compliant_filename):
943949
if noncompliant_filename:

tests/test_ncd.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ def test_load_ncd(self, subdir: str) -> None:
4747
# create metadata file
4848
ncd_metadata = copy.deepcopy(TEST_METADATA)
4949
meta = SigMFFile(metadata=ncd_metadata, data_file=data_path)
50-
# tell SigMF that the data is noncompliant
51-
meta.set_global_field(SigMFFile.DATASET_KEY, data_path.name)
5250
meta.validate()
5351
meta.tofile(meta_path)
5452

@@ -57,7 +55,11 @@ def test_load_ncd(self, subdir: str) -> None:
5755
self.assertTrue(np.array_equal(TEST_FLOAT32_DATA, meta_loopback.read_samples()))
5856
self.assertTrue(np.array_equal(TEST_FLOAT32_DATA, meta_loopback[:]))
5957

60-
# delete the non-conforming dataset and ensure error is raised due to missing dataset
58+
# delete the non-conforming dataset and ensure error is raised due to missing dataset;
59+
# in Windows the SigMFFile instances need to be garbage collected first,
60+
# otherwise the np.memmap instances (stored in self._memmap) block the deletion
61+
meta = None
62+
meta_loopback = None
6163
os.remove(data_path)
6264
with self.assertRaises(SigMFFileError):
6365
_ = fromfile(meta_path)

0 commit comments

Comments
 (0)