summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamian Johnson <atagar@torproject.org>2018-10-18 12:12:44 -0700
committerDamian Johnson <atagar@torproject.org>2018-10-18 12:12:44 -0700
commitf72a45293f67d6e6b68d1ed5fdc9a427dde24a2f (patch)
tree476c6c221c342813dfab96f543d97db87ccf3c88
parent295257e21dfff0733ee1fd5a857ae88ee8c08b49 (diff)
Notify if nyx cache isn't writable
A couple of folks have had Nyx crash due to their cache being unwritable... https://trac.torproject.org/projects/tor/ticket/27938 I suspect this arises when running nyx multiple times as different users that share the same home directory. Rather than crashing, providing a notice and falling back to an in-memory cache. Nyx's startup will be a tad slower when this happens but for most users it probably won't even be noticeable.
-rw-r--r--nyx/__init__.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/nyx/__init__.py b/nyx/__init__.py
index 58b3b81..d5585a0 100644
--- a/nyx/__init__.py
+++ b/nyx/__init__.py
@@ -44,6 +44,7 @@ Tor curses monitoring application.
import contextlib
import distutils.spawn
+import getpass
import os
import platform
import sys
@@ -442,10 +443,14 @@ class Cache(object):
self._conn_lock = threading.RLock()
cache_path = nyx.data_directory('cache.sqlite')
+ if cache_path and os.path.isfile(cache_path) and not os.access(cache_path, os.W_OK):
+ stem.util.log.notice("Nyx's cache at %s is not writable by our user (%s). That's ok, but we'll have better performance if we can write to it." % (cache_path, getpass.getuser()))
+ cache_path = None
+
if cache_path:
try:
self._conn = sqlite3.connect(cache_path, check_same_thread = False)
- schema = self._conn.execute('SELECT version FROM schema').fetchone()[0]
+ schema = self._query('SELECT version FROM schema').fetchone()[0]
except:
schema = None