Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed test file name from .permission_test to UUID to make it thread safe #1110

Merged
merged 3 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ repos:
- id: black

- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
rev: 6.1.0
hooks:
- id: flake8

Expand Down
6 changes: 4 additions & 2 deletions echopype/utils/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import pathlib
import platform
import sys
import uuid
from pathlib import Path, WindowsPath
from typing import TYPE_CHECKING, Dict, Optional, Tuple, Union

Expand Down Expand Up @@ -313,11 +314,12 @@ def check_file_existence(file_path: "PathHint", storage_options: Dict[str, str]

def check_file_permissions(FILE_DIR):
try:
fname = "." + str(uuid.uuid4())
if isinstance(FILE_DIR, FSMap):
base_dir = os.path.dirname(FILE_DIR.root)
if not base_dir:
base_dir = FILE_DIR.root
TEST_FILE = os.path.join(base_dir, ".permission_test").replace("\\", "/")
TEST_FILE = os.path.join(base_dir, fname).replace("\\", "/")
with FILE_DIR.fs.open(TEST_FILE, "w") as f:
f.write("testing\n")
FILE_DIR.fs.delete(TEST_FILE)
Expand All @@ -328,7 +330,7 @@ def check_file_permissions(FILE_DIR):
if not FILE_DIR.exists():
logger.warning(f"{str(FILE_DIR)} does not exist. Attempting to create it.")
FILE_DIR.mkdir(exist_ok=True, parents=True)
TEST_FILE = FILE_DIR.joinpath(Path(".permission_test"))
TEST_FILE = FILE_DIR.joinpath(Path(fname))
TEST_FILE.write_text("testing\n")

# Do python version check since missing_ok is for python 3.9 and up
Expand Down