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

Adding error checking to options.py if directory does not exist #5024

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
27 changes: 23 additions & 4 deletions platformio/project/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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("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("Library Manager: Installing symlink: %s", path)
raise VCSBaseException(f"VCS: Unknown repository type symlink: {path}")

return path

ProjectOptions = OrderedDict(
[
Expand Down