Skip to content

Commit

Permalink
Further improve 'cleanup' error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
chvancooten committed Mar 1, 2023
1 parent 63dfed9 commit 8cce05e
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions NimPlant.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,15 +252,26 @@ def compile_nim(binary_type, xor_key, debug=False):
print("Cleaning up...")

try:
os.remove("server/nimplant.db")
# Clean up files
for filepath in ["server/nimplant.db"]:
if os.path.exists(filepath) and os.path.isfile(filepath):
os.remove(filepath)

# Clean up directories
for dirpath in [
"server/downloads",
"server/logs",
"server/uploads",
]:
if os.path.exists(dirpath) and os.path.isdir(dirpath):
rmtree(dirpath)

print("Cleaned up NimPlant server files!")
except OSError:
pass
print(
"ERROR: Could not clean up all NimPlant server files. Do you have the right privileges?"
)

rmtree("server/downloads", ignore_errors=True)
rmtree("server/logs", ignore_errors=True)
rmtree("server/uploads", ignore_errors=True)

print("Cleaned up NimPlant server files!")
else:
print("Aborting...")

Expand Down

0 comments on commit 8cce05e

Please sign in to comment.