1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-04 19:09:44 +00:00

refuse to remove key dirs for #174

This commit is contained in:
deadc0de6
2019-07-02 23:58:37 +02:00
parent 49275d371d
commit d783911420

View File

@@ -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):