Skip to content

Commit

Permalink
Fallback to SoftFileLock if file lock fails
Browse files Browse the repository at this point in the history
  • Loading branch information
7x11x13 committed Aug 18, 2024
1 parent e499979 commit 6dde8e9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion scdl/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Python Soundcloud Music Downloader."""

__version__ = "v2.12.0"
__version__ = "v2.12.1"
15 changes: 12 additions & 3 deletions scdl/scdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@
from scdl import __version__, utils
from scdl.metadata_assembler import MetadataInfo, assemble_metadata

LockType: Type[filelock.BaseFileLock] = filelock.FileLock

mimetypes.init()

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -260,14 +262,21 @@ def clean_up_locks() -> None:

atexit.register(clean_up_locks)


def get_filelock(path: Union[pathlib.Path, str], timeout: int = 10) -> filelock.FileLock:
def get_filelock(path: Union[pathlib.Path, str], timeout: int = 10) -> filelock.BaseFileLock:
path = pathlib.Path(path)
path.parent.mkdir(parents=True, exist_ok=True)
path = path.resolve()
file_lock_dirs.append(path.parent)
lock_path = str(path) + ".scdl.lock"
return filelock.FileLock(lock_path, timeout=timeout)
return LockType(lock_path, timeout=timeout)


with tempfile.TemporaryDirectory() as tmp:
try:
with get_filelock(tmp + "/lock") as lock:
pass
except NotImplementedError:
LockType = filelock.SoftFileLock


def main() -> None:
Expand Down

0 comments on commit 6dde8e9

Please sign in to comment.