diff --git a/HISTORY.rst b/HISTORY.rst index 7ed0658639..d18ee3180e 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -4,6 +4,13 @@ Release History PlatformIO 2.0 -------------- +2.3.3 (2015-09-??) +~~~~~~~~~~~~~~~~~~ + +* Fixed broken lock file for "appstate" storage + (`issue #288 `_) + + 2.3.2 (2015-09-10) ~~~~~~~~~~~~~~~~~~ diff --git a/platformio/__init__.py b/platformio/__init__.py index 90f3918563..5772010f40 100644 --- a/platformio/__init__.py +++ b/platformio/__init__.py @@ -1,7 +1,7 @@ # Copyright (C) Ivan Kravets # See LICENSE for details. -VERSION = (2, 3, 2) +VERSION = (2, 3, "3.dev0") __version__ = ".".join([str(s) for s in VERSION]) __title__ = "platformio" diff --git a/platformio/app.py b/platformio/app.py index 6a6f7ee81e..8690ed21da 100644 --- a/platformio/app.py +++ b/platformio/app.py @@ -3,7 +3,8 @@ import json from os import environ, getenv -from os.path import isfile, join +from os.path import getmtime, isfile, join +from time import time from lockfile import LockFile @@ -68,9 +69,8 @@ def __init__(self, path=None): def __enter__(self): try: + self._lock_state_file() if isfile(self.path): - self._lock = LockFile(self.path) - self._lock.acquire() with open(self.path, "r") as fp: self._state = json.load(fp) except ValueError: @@ -85,6 +85,18 @@ def __exit__(self, type_, value, traceback): json.dump(self._state, fp, indent=4) else: json.dump(self._state, fp) + self._unlock_state_file() + + def _lock_state_file(self): + self._lock = LockFile(self.path) + + if (self._lock.is_locked() and + (time() - getmtime(self._lock.lock_file)) > 10): + self._lock.break_lock() + + self._lock.acquire() + + def _unlock_state_file(self): if self._lock: self._lock.release()