forked from platformio/platformio-core
Show error information when permissions are broken to PIO home dir
This commit is contained in:
@ -25,7 +25,6 @@ import requests
|
|||||||
from lockfile import LockFailed, LockFile
|
from lockfile import LockFailed, LockFile
|
||||||
|
|
||||||
from platformio import __version__, exception, util
|
from platformio import __version__, exception, util
|
||||||
from platformio.exception import InvalidSettingName, InvalidSettingValue
|
|
||||||
|
|
||||||
|
|
||||||
def projects_dir_validate(projects_dir):
|
def projects_dir_validate(projects_dir):
|
||||||
@ -106,11 +105,14 @@ class State(object):
|
|||||||
|
|
||||||
def __exit__(self, type_, value, traceback):
|
def __exit__(self, type_, value, traceback):
|
||||||
if self._prev_state != self._state:
|
if self._prev_state != self._state:
|
||||||
with open(self.path, "w") as fp:
|
try:
|
||||||
if "dev" in __version__:
|
with open(self.path, "w") as fp:
|
||||||
json.dump(self._state, fp, indent=4)
|
if "dev" in __version__:
|
||||||
else:
|
json.dump(self._state, fp, indent=4)
|
||||||
json.dump(self._state, fp)
|
else:
|
||||||
|
json.dump(self._state, fp)
|
||||||
|
except IOError:
|
||||||
|
raise exception.HomeDirPermissionsError(util.get_home_dir())
|
||||||
self._unlock_state_file()
|
self._unlock_state_file()
|
||||||
|
|
||||||
def _lock_state_file(self):
|
def _lock_state_file(self):
|
||||||
@ -276,7 +278,7 @@ def clean_cache():
|
|||||||
|
|
||||||
def sanitize_setting(name, value):
|
def sanitize_setting(name, value):
|
||||||
if name not in DEFAULT_SETTINGS:
|
if name not in DEFAULT_SETTINGS:
|
||||||
raise InvalidSettingName(name)
|
raise exception.InvalidSettingName(name)
|
||||||
|
|
||||||
defdata = DEFAULT_SETTINGS[name]
|
defdata = DEFAULT_SETTINGS[name]
|
||||||
try:
|
try:
|
||||||
@ -288,7 +290,7 @@ def sanitize_setting(name, value):
|
|||||||
elif isinstance(defdata['value'], int):
|
elif isinstance(defdata['value'], int):
|
||||||
value = int(value)
|
value = int(value)
|
||||||
except Exception:
|
except Exception:
|
||||||
raise InvalidSettingValue(value, name)
|
raise exception.InvalidSettingValue(value, name)
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
@ -367,5 +369,6 @@ def get_cid():
|
|||||||
uuid.UUID(
|
uuid.UUID(
|
||||||
bytes=hashlib.md5(str(_uid if _uid else uuid.getnode()))
|
bytes=hashlib.md5(str(_uid if _uid else uuid.getnode()))
|
||||||
.digest()))
|
.digest()))
|
||||||
set_state_item("cid", cid)
|
if "windows" in util.get_systype() or os.getuid() > 0:
|
||||||
|
set_state_item("cid", cid)
|
||||||
return cid
|
return cid
|
||||||
|
@ -223,6 +223,12 @@ class UpgradeError(PlatformioException):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
class HomeDirPermissionsError(PlatformioException):
|
||||||
|
|
||||||
|
MESSAGE = "You do not have permissions to PlatformIO home directory.\n"\
|
||||||
|
"Please remove `{0}` folder manually and repeat operation."
|
||||||
|
|
||||||
|
|
||||||
class CygwinEnvDetected(PlatformioException):
|
class CygwinEnvDetected(PlatformioException):
|
||||||
|
|
||||||
MESSAGE = "PlatformIO does not work within Cygwin environment. "\
|
MESSAGE = "PlatformIO does not work within Cygwin environment. "\
|
||||||
|
Reference in New Issue
Block a user