don't delete a folder that doesn't exist

This commit is contained in:
crunk 2022-04-04 21:48:52 +02:00
parent b75c221c6b
commit 76de0b10cb
3 changed files with 12 additions and 6 deletions

View File

@ -107,8 +107,10 @@ def DeleteDistribusiFromDb(distribusi):
def DeleteDistribusiFiles(distribusiname):
userfolder = os.path.join("stash", distribusiname)
if os.path.exists(userfolder):
shutil.rmtree(userfolder)
cssfolder = os.path.join("themes/userthemes", distribusiname)
if os.path.exists(cssfolder):
shutil.rmtree(cssfolder)

View File

@ -83,15 +83,18 @@ def DeleteDistribusi(distribusiname):
db.session.delete(distribusi)
db.session.commit()
userfolder = os.path.join("stash", distribusi.distribusiname)
if os.path.exists(userfolder):
shutil.rmtree(userfolder)
cssfolder = os.path.join(
"themes/userthemes", distribusi.distribusiname
)
if os.path.exists(cssfolder):
shutil.rmtree(cssfolder)
if distribusi.publictheme is not None:
publicthemefolder = os.path.join(
"themes/publicthemes", distribusi.distribusiname
)
if os.path.exists(publicthemefolder):
shutil.rmtree(publicthemefolder)
# SelectField error is list is a tuple?? why??
# selectorform.distribusis.errors.append("Distribusi deleted!")

View File

@ -86,6 +86,7 @@ def UploadUpdatedFiles(uploadfolder):
zipfile.save(os.path.join(uploadfolder, zipfilename))
newuserfolder = os.path.join("stash", distribusi.distribusiname)
if os.path.exists(newuserfolder):
shutil.rmtree(newuserfolder)
os.mkdir(newuserfolder)