Skip to content

Commit

Permalink
Add: followlinks option in safe_rmdir function.
Browse files Browse the repository at this point in the history
  • Loading branch information
Labbeti committed Jan 23, 2024
1 parent 73d8333 commit 1aa30d7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
12 changes: 6 additions & 6 deletions src/aac_datasets/datasets/wavcaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ class WavCaps(AACDataset[WavCapsItem]):
HuggingFace source : https://huggingface.co/datasets/cvssp/WavCaps
This dataset contains 4 training subsets, extracted from different sources:
- AudioSet strongly labeled (as)
- BBC Sound Effects (bbc)
- FreeSound (fsd)
- SoundBible (sb)
- AudioSet strongly labeled without AudioCaps (as_noac)
- FreeSound without Clotho (fsd_nocl)
- AudioSet strongly labeled ("audioset")
- BBC Sound Effects ("bbc")
- FreeSound ("freesound")
- SoundBible ("soundbible")
- AudioSet strongly labeled without AudioCaps ("audioset_no_audiocaps")
- FreeSound without Clotho ("freesound_no_clotho")
.. warning::
WavCaps download is experimental ; it requires a lot of disk space and can take very long time to download and extract, so you might expect errors.
Expand Down
21 changes: 14 additions & 7 deletions src/aac_datasets/utils/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,31 @@ def safe_rmdir(
root: Union[str, Path],
rm_root: bool = True,
error_on_non_empty_dir: bool = True,
followlinks: bool = False,
) -> List[str]:
"""Remove all empty sub-directories.
:param root: Root directory path.
:param rm_root: If True, remove the root directory too. defaults to True.
:param error_on_non_empty_dir: If True, raises a RuntimeError if a subdirectory contains at least 1 file. Otherwise it will leave non-empty directories. defaults to True.
:param followlinks: Indicates whether or not symbolic links shound be followed. defaults to False.
:returns: The list of directories paths deleted.
"""
deleted = []
for dpath, dnames, fnames in os.walk(root, topdown=False):
to_delete = []

for dpath, dnames, fnames in os.walk(root, topdown=False, followlinks=followlinks):
if not rm_root and dpath == root:
continue
elif len(dnames) == 0 and len(fnames) == 0:
os.rmdir(dpath)
deleted.append(dpath)
elif len(fnames) == 0 and len(dnames) == 0:
to_delete.append(dpath)
elif error_on_non_empty_dir:
raise RuntimeError(f"Cannot remove non-empty dir {dpath}.")
return deleted
print(f"{to_delete=}")
raise RuntimeError(f"Cannot remove non-empty directory {dpath}.")

for dpath in to_delete:
os.rmdir(dpath)

return to_delete


def hash_file(
Expand Down

0 comments on commit 1aa30d7

Please sign in to comment.