Skip to content

Commit

Permalink
Merge 9144880 into 3847228
Browse files Browse the repository at this point in the history
  • Loading branch information
alichtman committed May 11, 2019
2 parents 3847228 + 9144880 commit 6c83377
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions shallow_backup/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,18 @@ def safe_mkdir(directory):

def mkdir_overwrite(path):
"""
Makes a new directory, destroying the one at the path if it exits.
Makes a new directory, destroying the contents of the dir at path, if it exits.
Ensures .git and .gitignore files inside of directory are not delected.
"""
if os.path.isdir(path):
rmtree(path)
os.makedirs(path)
for dirpath, dirs, files in os.walk(path):
# Delete files
[os.remove(os.path.join(dirpath, name)) for name in files if name != ".gitignore"]

# Delete directories
[rmtree(os.path.join(dirpath, name)) for name in dirs if name != ".git"]
else:
os.makedirs(path)


def mkdir_warn_overwrite(path):
Expand Down

0 comments on commit 6c83377

Please sign in to comment.