From 76de0b10cb328a6f1ec13a543ac05e979d923e8c Mon Sep 17 00:00:00 2001 From: crunk Date: Mon, 4 Apr 2022 21:48:52 +0200 Subject: [PATCH] don't delete a folder that doesn't exist --- verse/adminpage.py | 6 ++++-- verse/distribusiselector.py | 9 ++++++--- verse/upload.py | 3 ++- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/verse/adminpage.py b/verse/adminpage.py index e2839b8..c310fde 100644 --- a/verse/adminpage.py +++ b/verse/adminpage.py @@ -107,9 +107,11 @@ def DeleteDistribusiFromDb(distribusi): def DeleteDistribusiFiles(distribusiname): userfolder = os.path.join("stash", distribusiname) - shutil.rmtree(userfolder) + if os.path.exists(userfolder): + shutil.rmtree(userfolder) cssfolder = os.path.join("themes/userthemes", distribusiname) - shutil.rmtree(cssfolder) + if os.path.exists(cssfolder): + shutil.rmtree(cssfolder) def AddDistribusisToForm(admindistribusiform): diff --git a/verse/distribusiselector.py b/verse/distribusiselector.py index b0ba987..788ec35 100644 --- a/verse/distribusiselector.py +++ b/verse/distribusiselector.py @@ -83,16 +83,19 @@ def DeleteDistribusi(distribusiname): db.session.delete(distribusi) db.session.commit() userfolder = os.path.join("stash", distribusi.distribusiname) - shutil.rmtree(userfolder) + if os.path.exists(userfolder): + shutil.rmtree(userfolder) cssfolder = os.path.join( "themes/userthemes", distribusi.distribusiname ) - shutil.rmtree(cssfolder) + if os.path.exists(cssfolder): + shutil.rmtree(cssfolder) if distribusi.publictheme is not None: publicthemefolder = os.path.join( "themes/publicthemes", distribusi.distribusiname ) - shutil.rmtree(publicthemefolder) + if os.path.exists(publicthemefolder): + shutil.rmtree(publicthemefolder) # SelectField error is list is a tuple?? why?? # selectorform.distribusis.errors.append("Distribusi deleted!") except (InvalidRequestError, DataError, InterfaceError, DatabaseError): diff --git a/verse/upload.py b/verse/upload.py index 4a7e1d3..5f12794 100644 --- a/verse/upload.py +++ b/verse/upload.py @@ -86,7 +86,8 @@ def UploadUpdatedFiles(uploadfolder): zipfile.save(os.path.join(uploadfolder, zipfilename)) newuserfolder = os.path.join("stash", distribusi.distribusiname) - shutil.rmtree(newuserfolder) + if os.path.exists(newuserfolder): + shutil.rmtree(newuserfolder) os.mkdir(newuserfolder) copyzipfile = os.path.join(uploadfolder, zipfilename)