mirror of
https://github.com/platformio/platformio-core.git
synced 2025-07-30 01:57:13 +02:00
Fix "LockFailed: failed to create appstate.json.lock" error for Windows
This commit is contained in:
@ -17,6 +17,7 @@ PlatformIO 2.0
|
|||||||
(`pull #333 <https://github.com/platformio/platformio/pull/333>`_)
|
(`pull #333 <https://github.com/platformio/platformio/pull/333>`_)
|
||||||
* Fixed configuration for LowPowerLab MoteinoMEGA board
|
* Fixed configuration for LowPowerLab MoteinoMEGA board
|
||||||
(`issue #335 <https://github.com/platformio/platformio/issues/335>`_)
|
(`issue #335 <https://github.com/platformio/platformio/issues/335>`_)
|
||||||
|
* Fixed "LockFailed: failed to create appstate.json.lock" error for Windows
|
||||||
|
|
||||||
2.3.5 (2015-11-18)
|
2.3.5 (2015-11-18)
|
||||||
~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
VERSION = (2, 3, "6.dev0")
|
VERSION = (2, 3, "6.dev1")
|
||||||
__version__ = ".".join([str(s) for s in VERSION])
|
__version__ = ".".join([str(s) for s in VERSION])
|
||||||
|
|
||||||
__title__ = "platformio"
|
__title__ = "platformio"
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
from copy import deepcopy
|
||||||
from os import environ, getenv
|
from os import environ, getenv
|
||||||
from os.path import getmtime, isfile, join
|
from os.path import getmtime, isfile, join
|
||||||
from time import time
|
from time import time
|
||||||
@ -23,6 +24,7 @@ from platformio import __version__
|
|||||||
from platformio.exception import InvalidSettingName, InvalidSettingValue
|
from platformio.exception import InvalidSettingName, InvalidSettingValue
|
||||||
from platformio.util import get_home_dir, is_ci
|
from platformio.util import get_home_dir, is_ci
|
||||||
|
|
||||||
|
|
||||||
DEFAULT_SETTINGS = {
|
DEFAULT_SETTINGS = {
|
||||||
"check_platformio_interval": {
|
"check_platformio_interval": {
|
||||||
"description": "Check for the new PlatformIO interval (days)",
|
"description": "Check for the new PlatformIO interval (days)",
|
||||||
@ -70,13 +72,14 @@ SESSION_VARS = {
|
|||||||
|
|
||||||
class State(object):
|
class State(object):
|
||||||
|
|
||||||
def __init__(self, path=None):
|
def __init__(self, path=None, lock=False):
|
||||||
self.path = path
|
self.path = path
|
||||||
|
self.lock = lock
|
||||||
if not self.path:
|
if not self.path:
|
||||||
self.path = join(get_home_dir(), "appstate.json")
|
self.path = join(get_home_dir(), "appstate.json")
|
||||||
self._state = {}
|
self._state = {}
|
||||||
self._prev_state = {}
|
self._prev_state = {}
|
||||||
self._lock = None
|
self._lockfile = None
|
||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
try:
|
try:
|
||||||
@ -86,7 +89,7 @@ class State(object):
|
|||||||
self._state = json.load(fp)
|
self._state = json.load(fp)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
self._state = {}
|
self._state = {}
|
||||||
self._prev_state = self._state.copy()
|
self._prev_state = deepcopy(self._state)
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
def __exit__(self, type_, value, traceback):
|
def __exit__(self, type_, value, traceback):
|
||||||
@ -99,17 +102,19 @@ class State(object):
|
|||||||
self._unlock_state_file()
|
self._unlock_state_file()
|
||||||
|
|
||||||
def _lock_state_file(self):
|
def _lock_state_file(self):
|
||||||
self._lock = LockFile(self.path)
|
if not self.lock:
|
||||||
|
return
|
||||||
|
self._lockfile = LockFile(self.path)
|
||||||
|
|
||||||
if (self._lock.is_locked() and
|
if (self._lockfile.is_locked() and
|
||||||
(time() - getmtime(self._lock.lock_file)) > 10):
|
(time() - getmtime(self._lockfile.lock_file)) > 10):
|
||||||
self._lock.break_lock()
|
self._lockfile.break_lock()
|
||||||
|
|
||||||
self._lock.acquire()
|
self._lockfile.acquire()
|
||||||
|
|
||||||
def _unlock_state_file(self):
|
def _unlock_state_file(self):
|
||||||
if self._lock:
|
if self._lockfile:
|
||||||
self._lock.release()
|
self._lockfile.release()
|
||||||
|
|
||||||
|
|
||||||
def sanitize_setting(name, value):
|
def sanitize_setting(name, value):
|
||||||
@ -136,7 +141,7 @@ def get_state_item(name, default=None):
|
|||||||
|
|
||||||
|
|
||||||
def set_state_item(name, value):
|
def set_state_item(name, value):
|
||||||
with State() as data:
|
with State(lock=True) as data:
|
||||||
data[name] = value
|
data[name] = value
|
||||||
|
|
||||||
|
|
||||||
@ -159,14 +164,14 @@ def get_setting(name):
|
|||||||
|
|
||||||
|
|
||||||
def set_setting(name, value):
|
def set_setting(name, value):
|
||||||
with State() as data:
|
with State(lock=True) as data:
|
||||||
if "settings" not in data:
|
if "settings" not in data:
|
||||||
data['settings'] = {}
|
data['settings'] = {}
|
||||||
data['settings'][name] = sanitize_setting(name, value)
|
data['settings'][name] = sanitize_setting(name, value)
|
||||||
|
|
||||||
|
|
||||||
def reset_settings():
|
def reset_settings():
|
||||||
with State() as data:
|
with State(lock=True) as data:
|
||||||
if "settings" in data:
|
if "settings" in data:
|
||||||
del data['settings']
|
del data['settings']
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user