Improve permissions check

This commit is contained in:
monosans
2024-02-01 14:52:29 +03:00
parent a1f971db21
commit 328834eb03
2 changed files with 7 additions and 6 deletions
+4 -3
View File
@@ -5,6 +5,7 @@ import enum
import json
import logging
import math
import os
import sys
from pathlib import Path
from typing import (
@@ -30,7 +31,7 @@ from .http import get_response_text
from .null_context import NullContext
from .parsers import parse_ipv4
from .typing_compat import Any, Literal, Self
from .utils import IS_DOCKER, check_writable
from .utils import IS_DOCKER, check_access
if TYPE_CHECKING:
from .proxy import Proxy
@@ -272,8 +273,8 @@ class Settings:
)
_, _, (check_website_type, real_ip) = await asyncio.gather(
check_writable(output_path),
check_writable(cache.DIR),
check_access(output_path, mode=os.W_OK | os.X_OK),
check_access(cache.DIR, mode=os.R_OK | os.W_OK | os.X_OK),
_get_check_website_type_and_real_ip(
check_website=cfg["check_website"], session=session
),
+3 -3
View File
@@ -20,7 +20,7 @@ def bytes_decode(value: bytes, /) -> str:
return str(charset_normalizer.from_bytes(value)[0])
async def check_writable(path: Union[Path, str], /) -> None:
if not await aiofiles.os.access(path, os.W_OK):
msg = f"{path} is not writable"
async def check_access(path: Union[Path, str], /, *, mode: int) -> None:
if not await aiofiles.os.access(path, mode):
msg = f"{path} is not accessible"
raise ValueError(msg)