diff options
author | Anton Khirnov <anton@khirnov.net> | 2020-03-05 10:20:51 +0100 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2020-03-05 10:20:51 +0100 |
commit | 8a6ce8a29d8d61385c4222b9018b936e658cfb24 (patch) | |
tree | 01e2de98753dc181e5e31cb38fa8fa3da2d32194 | |
parent | 6e159d42ea4051b4997f55b06c3775c1ebab0f77 (diff) |
db/utils: move is_subdir_of() to the single place it is used in
-rw-r--r-- | alot/db/manager.py | 11 | ||||
-rw-r--r-- | alot/db/utils.py | 11 |
2 files changed, 9 insertions, 13 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 diff --git a/alot/db/utils.py b/alot/db/utils.py index a2101e9d..99684afd 100644 --- a/alot/db/utils.py +++ b/alot/db/utils.py @@ -26,14 +26,3 @@ def formataddr(pair): elif ',' in name: name = "\"" + name + "\"" return "{0} <{1}>".format(name, address) - - - -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 |