[nostalgia/scripts/pybb] Fix directory removal

This commit is contained in:
Gary Talent 2021-02-20 20:03:54 -06:00
parent 671acc68c4
commit 127e3f6df0

View File

@ -1,6 +1,8 @@
#! /usr/bin/env python3 #! /usr/bin/env python3
import os import os
import shutil
import stat
import sys import sys
def mkdir(path): def mkdir(path):
@ -8,8 +10,12 @@ def mkdir(path):
os.mkdir(path) os.mkdir(path)
def rm(path): def rm(path):
if os.path.exists(path) or os.path.islink(path): if (os.path.exists(path) or os.path.islink(path)) and not os.path.isdir(path):
os.chmod(path, stat.S_IWRITE)
os.remove(path) os.remove(path)
elif os.path.isdir(path):
os.chmod(path, stat.S_IWRITE)
shutil.rmtree(path)
if sys.argv[1] == 'mkdir': if sys.argv[1] == 'mkdir':
mkdir(sys.argv[2]) mkdir(sys.argv[2])