From 53fc839cae60f424f9a0d7961bee1eba68228b6c Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 20 Oct 2019 13:43:59 +0100 Subject: [PATCH] Add exception handling for index --- inbox.py | 24 +++++++++++++++--------- posts.py | 5 +---- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/inbox.py b/inbox.py index 2a6b7b221..fc3d11d9f 100644 --- a/inbox.py +++ b/inbox.py @@ -1516,16 +1516,22 @@ def inboxUpdateIndex(baseDir: str,handle: str,destinationFilename: str,debug: bo if '/'+boxname+'/' in destinationFilename: destinationFilename=destinationFilename.split('/'+boxname+'/')[1] if os.path.isfile(indexFilename): - with open(indexFilename, 'r+') as indexFile: - content = indexFile.read() - indexFile.seek(0, 0) - indexFile.write(destinationFilename+'\n'+content) - return True + try: + with open(indexFilename, 'r+') as indexFile: + content = indexFile.read() + indexFile.seek(0, 0) + indexFile.write(destinationFilename+'\n'+content) + return True + except Exception as e: + print('Failed to write entry to index '+str(e)) else: - indexFile=open(indexFilename,'w+') - if indexFile: - indexFile.write(destinationFilename+'\n') - indexFile.close() + try: + indexFile=open(indexFilename,'w+') + if indexFile: + indexFile.write(destinationFilename+'\n') + indexFile.close() + except Exception as e: + print('Failed to write initial entry to index '+str(e)) return False diff --git a/posts.py b/posts.py index 2c5833337..b6010b736 100644 --- a/posts.py +++ b/posts.py @@ -2040,10 +2040,7 @@ def createBoxBase(session,baseDir: str,boxname: str, \ maxPostCtr=(itemsPerPage+3)*pageNumber with open(indexFilename, 'r') as indexFile: for postFilename in indexFile: - statusNumber=getStatusNumberFromPostFilename(postFilename) - if not statusNumber: - continue - postsInBox[statusNumber]=os.path.join(boxDir, postFilename.replace('\n','')) + postsInBox[postsCtr]=os.path.join(boxDir, postFilename.replace('\n','')) postsCtr+=1 if maxPostCtr: if postsCtr>=maxPostCtr: