Skip to content

Commit

Permalink
fix: update permission check filename to be UUID to make it thread sa…
Browse files Browse the repository at this point in the history
…fe (#1110)

* [pre-commit.ci] pre-commit autoupdate (#1109)

updates:
- [github.com/PyCQA/flake8: 6.0.0 → 6.1.0](PyCQA/flake8@6.0.0...6.1.0)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* Changed test file name to UUID

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
Sohambutala and pre-commit-ci[bot] authored Aug 3, 2023
1 parent e0e84f0 commit 4250acf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
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 @@ -314,11 +315,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 @@ -329,7 +331,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

0 comments on commit 4250acf

Please sign in to comment.