diff options
author | Patrick Totzke <patricktotzke@gmail.com> | 2013-06-23 20:19:28 +0100 |
---|---|---|
committer | Patrick Totzke <patricktotzke@gmail.com> | 2013-07-07 18:04:49 +0100 |
commit | 7d42329f9104847e9d1559877fdbc00cb0a53c35 (patch) | |
tree | a29ad46f1170e21c9df02c2a59c382b9ae81b1e3 /alot/db/utils.py | |
parent | 3b12a9f0cb9f3b4dbb6b1dd9dc8473276f2b17df (diff) |
add helper to check if path is below another
this is used in the Database manager
Diffstat (limited to 'alot/db/utils.py')
-rw-r--r-- | alot/db/utils.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/alot/db/utils.py b/alot/db/utils.py index 45ee0db8..db8de0de 100644 --- a/alot/db/utils.py +++ b/alot/db/utils.py @@ -390,3 +390,12 @@ def encode_header(key, value): else: value = Header(value) return value + +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 |