From d783911420d5c474e49daa00eb7cec2dfea304f4 Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Tue, 2 Jul 2019 23:58:37 +0200 Subject: [PATCH] refuse to remove key dirs for #174 --- dotdrop/utils.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/dotdrop/utils.py b/dotdrop/utils.py index 8f0dad7..6825bd6 100644 --- a/dotdrop/utils.py +++ b/dotdrop/utils.py @@ -19,6 +19,13 @@ from dotdrop.logger import Logger LOG = Logger() STAR = '*' +# files dotdrop refuses to remove +DONOTDELETE = [ + os.path.expanduser('~'), + os.path.expanduser('~/.config'), +] +NOREMOVE = [os.path.normpath(p) for p in DONOTDELETE] + def run(cmd, raw=True, debug=False, checkerr=False): """run a command (expects a list)""" @@ -89,6 +96,10 @@ def remove(path): """remove a file/directory/symlink""" if not os.path.lexists(path): raise OSError("File not found: {}".format(path)) + if os.path.normpath(os.path.expanduser(path)) in NOREMOVE: + err = 'Dotdrop refuses to remove {}'.format(path) + LOG.err(err) + raise OSError(err) if os.path.islink(path) or os.path.isfile(path): os.unlink(path) elif os.path.isdir(path):