From 6dee6d2276ac4f0b33a60a6fe74a845a5547105b Mon Sep 17 00:00:00 2001 From: Rhebhanu Date: Tue, 19 Nov 2024 22:14:34 -0500 Subject: [PATCH 1/2] Adding error checking to options.py if directory does not exist --- platformio/project/options.py | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/platformio/project/options.py b/platformio/project/options.py index d0a4b0e8e9..1393db54cf 100644 --- a/platformio/project/options.py +++ b/platformio/project/options.py @@ -14,13 +14,16 @@ # pylint: disable=redefined-builtin, too-many-arguments +import logging import os from collections import OrderedDict +from posixpath import expanduser import click from platformio import fs from platformio.compat import IS_WINDOWS +from test_core_dir import PackageException, VCSBaseException class ConfigOption: # pylint: disable=too-many-instance-attributes,too-many-positional-arguments @@ -91,13 +94,29 @@ def validate_dir(path): def get_default_core_dir(): - path = os.path.join(fs.expanduser("~"), ".platformio") + # Default to ~/.platformio + path = os.path.join(expanduser("~"), ".platformio") + + # Handle Windows-specific directory fallback if IS_WINDOWS: win_core_dir = os.path.splitdrive(path)[0] + "\\.platformio" - if os.path.isdir(win_core_dir): - return win_core_dir - return path + # Use Windows root directory only if it exists and is writable + if os.path.isdir(win_core_dir) and os.access(win_core_dir, os.W_OK): + path = win_core_dir + + # Ensure the directory exists, but handle invalid symlink creation + if not os.path.exists(path): + try: + os.makedirs(path, exist_ok=True) + except OSError as e: + logging.error(f"Library Manager: Installing symlink: {path}") + raise PackageException(f"Can not create a symbolic link for `{path}`, not a directory") from e + if not os.path.isdir(path): + logging.error(f"Library Manager: Installing symlink: {path}") + raise VCSBaseException(f"VCS: Unknown repository type symlink: {path}") + + return path ProjectOptions = OrderedDict( [ @@ -823,4 +842,4 @@ def get_default_core_dir(): def get_config_options_schema(): - return [opt.as_dict() for opt in ProjectOptions.values()] + return [opt.as_dict() for opt in ProjectOptions.values()] \ No newline at end of file From de74124f732b6ad8bafa83e1b9fc8d62445f5f5e Mon Sep 17 00:00:00 2001 From: Rhea Bhanushali <96189130+Rhebhanu@users.noreply.github.com> Date: Tue, 19 Nov 2024 22:35:06 -0500 Subject: [PATCH 2/2] Update options.py --- platformio/project/options.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/platformio/project/options.py b/platformio/project/options.py index 1393db54cf..42c896ceed 100644 --- a/platformio/project/options.py +++ b/platformio/project/options.py @@ -109,11 +109,11 @@ def get_default_core_dir(): try: os.makedirs(path, exist_ok=True) except OSError as e: - logging.error(f"Library Manager: Installing symlink: {path}") + logging.error("Library Manager: Installing symlink: %s", path) raise PackageException(f"Can not create a symbolic link for `{path}`, not a directory") from e if not os.path.isdir(path): - logging.error(f"Library Manager: Installing symlink: {path}") + logging.error("Library Manager: Installing symlink: %s", path) raise VCSBaseException(f"VCS: Unknown repository type symlink: {path}") return path @@ -842,4 +842,4 @@ def get_default_core_dir(): def get_config_options_schema(): - return [opt.as_dict() for opt in ProjectOptions.values()] \ No newline at end of file + return [opt.as_dict() for opt in ProjectOptions.values()]