From 8a6ce8a29d8d61385c4222b9018b936e658cfb24 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Thu, 5 Mar 2020 10:20:51 +0100 Subject: db/utils: move is_subdir_of() to the single place it is used in --- alot/db/manager.py | 11 +++++++++-- 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 -- cgit v1.2.3