summaryrefslogtreecommitdiff
path: root/alot/db/manager.py
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2020-03-05 10:20:51 +0100
committerAnton Khirnov <anton@khirnov.net>2020-03-05 10:20:51 +0100
commit8a6ce8a29d8d61385c4222b9018b936e658cfb24 (patch)
tree01e2de98753dc181e5e31cb38fa8fa3da2d32194 /alot/db/manager.py
parent6e159d42ea4051b4997f55b06c3775c1ebab0f77 (diff)
db/utils: move is_subdir_of() to the single place it is used in
Diffstat (limited to 'alot/db/manager.py')
-rw-r--r--alot/db/manager.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/alot/db/manager.py b/alot/db/manager.py
index 4d1bb5b2..888e9404 100644
--- a/alot/db/manager.py
+++ b/alot/db/manager.py
@@ -18,9 +18,16 @@ from .errors import DatabaseLockedError
from .errors import DatabaseROError
from .errors import NonexistantObjectError
from .thread import Thread
-from .utils import is_subdir_of
from ..settings.const import settings
+def _is_subdir_of(subpath, superpath):
+ # make both absolute
+ superpath = os.path.realpath(superpath)
+ subpath = os.path.realpath(subpath)
+
+ # return true, if the common prefix of both is equal to directory
+ # e.g. /a/b/c/d.rst and directory is /a/b, the common prefix is /a/b
+ return os.path.commonprefix([subpath, superpath]) == superpath
class FillPipeProcess(multiprocessing.Process):
@@ -415,7 +422,7 @@ class DBManager:
if self.ro:
raise DatabaseROError()
- if not is_subdir_of(path, self.path):
+ if not _is_subdir_of(path, self.path):
msg = 'message path %s ' % path
msg += ' is not below notmuchs '
msg += 'root path (%s)' % self.path