Skip to content

Commit 3915a39

Browse files
committed
Add legacy dir cleanup on start
1 parent f2ebd88 commit 3915a39

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

BlocksScreen/devices/storage/udisks2.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import logging
33
import os
44
import pathlib
5+
import shutil
56
import typing
67
from collections.abc import Coroutine
78
import unicodedata
@@ -163,6 +164,7 @@ def __init__(self, parent: QtCore.QObject, gcodes_dir: str) -> None:
163164
self.listener_running: bool = False
164165
self.controlled_devs: dict[str, Device] = {}
165166
self._cleanup_broken_symlinks()
167+
self._cleanup_legacy_dir()
166168

167169
@property
168170
def active(self) -> bool:
@@ -563,3 +565,13 @@ def _resolve_symlinks(
563565
# This `path` resolves to the `mount_path`
564566
return True
565567
return False
568+
569+
def _cleanup_legacy_dir(self) -> None:
570+
"""Removes legacy directory that contained symlinks
571+
for all mounted USB devices on the machine
572+
"""
573+
legacy_dir = self.gcodes_path.joinpath("USB")
574+
if legacy_dir.is_dir() and not (
575+
legacy_dir.is_symlink() or legacy_dir.is_file()
576+
):
577+
shutil.rmtree(legacy_dir)

0 commit comments

Comments
 (0)