diff --git a/blocking.py b/blocking.py index 406b79717..d39b17c70 100644 --- a/blocking.py +++ b/blocking.py @@ -514,7 +514,10 @@ def mutePost(baseDir: str, nickname: str, domain: str, port: int, getCachedPostFilename(baseDir, nickname, domain, postJsonObject) if cachedPostFilename: if os.path.isfile(cachedPostFilename): - os.remove(cachedPostFilename) + try: + os.remove(cachedPostFilename) + except BaseException: + pass with open(postFilename + '.muted', 'w+') as muteFile: muteFile.write('\n') @@ -550,7 +553,10 @@ def unmutePost(baseDir: str, nickname: str, domain: str, port: int, muteFilename = postFilename + '.muted' if os.path.isfile(muteFilename): - os.remove(muteFilename) + try: + os.remove(muteFilename) + except BaseException: + pass print('UNMUTE: ' + muteFilename + ' file removed') if hasObjectDict(postJsonObject): @@ -588,7 +594,10 @@ def unmutePost(baseDir: str, nickname: str, domain: str, port: int, getCachedPostFilename(baseDir, nickname, domain, postJsonObject) if cachedPostFilename: if os.path.isfile(cachedPostFilename): - os.remove(cachedPostFilename) + try: + os.remove(cachedPostFilename) + except BaseException: + pass # if the post is in the recent posts cache then mark it as unmuted if recentPostsCache.get('index'): @@ -740,7 +749,10 @@ def setBrochMode(baseDir: str, domainFull: str, enabled: bool) -> None: if not enabled: # remove instance allow list if os.path.isfile(allowFilename): - os.remove(allowFilename) + try: + os.remove(allowFilename) + except BaseException: + pass print('Broch mode turned off') else: if os.path.isfile(allowFilename): @@ -799,11 +811,14 @@ def brochModeLapses(baseDir: str, lapseDays: int = 7) -> bool: currTime = datetime.datetime.utcnow() daysSinceBroch = (currTime - modifiedDate).days if daysSinceBroch >= lapseDays: + removed = False try: os.remove(allowFilename) + removed = True + except BaseException: + pass + if removed: setConfigParam(baseDir, "brochMode", False) print('Broch mode has elapsed') return True - except BaseException: - pass return False diff --git a/bookmarks.py b/bookmarks.py index 0e45edce8..3cfc09fd0 100644 --- a/bookmarks.py +++ b/bookmarks.py @@ -47,7 +47,10 @@ def undoBookmarksCollectionEntry(recentPostsCache: {}, domain, postJsonObject) if cachedPostFilename: if os.path.isfile(cachedPostFilename): - os.remove(cachedPostFilename) + try: + os.remove(cachedPostFilename) + except BaseException: + pass removePostFromCache(postJsonObject, recentPostsCache) # remove from the index @@ -152,7 +155,10 @@ def updateBookmarksCollection(recentPostsCache: {}, domain, postJsonObject) if cachedPostFilename: if os.path.isfile(cachedPostFilename): - os.remove(cachedPostFilename) + try: + os.remove(cachedPostFilename) + except BaseException: + pass removePostFromCache(postJsonObject, recentPostsCache) if not postJsonObject.get('object'): diff --git a/categories.py b/categories.py index f60520b7e..b21a15e25 100644 --- a/categories.py +++ b/categories.py @@ -93,7 +93,10 @@ def updateHashtagCategories(baseDir: str) -> None: hashtagCategories = getHashtagCategories(baseDir) if not hashtagCategories: if os.path.isfile(categoryListFilename): - os.remove(categoryListFilename) + try: + os.remove(categoryListFilename) + except BaseException: + pass return categoryList = [] diff --git a/content.py b/content.py index 0c13f0e23..e7af2e76f 100644 --- a/content.py +++ b/content.py @@ -938,9 +938,15 @@ def saveMediaInFormPOST(mediaBytes, debug: bool, for ex in extensionTypes: possibleOtherFormat = filenameBase + '.' + ex if os.path.isfile(possibleOtherFormat): - os.remove(possibleOtherFormat) + try: + os.remove(possibleOtherFormat) + except BaseException: + pass if os.path.isfile(filenameBase): - os.remove(filenameBase) + try: + os.remove(filenameBase) + except BaseException: + pass if debug: print('DEBUG: No media found within POST') @@ -1006,7 +1012,10 @@ def saveMediaInFormPOST(mediaBytes, debug: bool, detectedExtension, '.' + ex) if os.path.isfile(possibleOtherFormat): - os.remove(possibleOtherFormat) + try: + os.remove(possibleOtherFormat) + except BaseException: + pass with open(filename, 'wb') as fp: fp.write(mediaBytes[startPos:]) diff --git a/daemon.py b/daemon.py index 9c17d9259..038a27be1 100644 --- a/daemon.py +++ b/daemon.py @@ -488,7 +488,10 @@ class PubServer(BaseHTTPRequestHandler): postJsonObject) if cachedPostFilename: if os.path.isfile(cachedPostFilename): - os.remove(cachedPostFilename) + try: + os.remove(cachedPostFilename) + except BaseException: + pass # remove from memory cache removePostFromCache(postJsonObject, self.server.recentPostsCache) @@ -2256,7 +2259,10 @@ class PubServer(BaseHTTPRequestHandler): newswireBlockedFilename = accountDir + '/.nonewswire' if postsToNews == 'on': if os.path.isfile(newswireBlockedFilename): - os.remove(newswireBlockedFilename) + try: + os.remove(newswireBlockedFilename) + except BaseException: + pass refreshNewswire(self.server.baseDir) else: if os.path.isdir(accountDir): @@ -2291,7 +2297,10 @@ class PubServer(BaseHTTPRequestHandler): featuresBlockedFilename = accountDir + '/.nofeatures' if postsToFeatures == 'on': if os.path.isfile(featuresBlockedFilename): - os.remove(featuresBlockedFilename) + try: + os.remove(featuresBlockedFilename) + except BaseException: + pass refreshNewswire(self.server.baseDir) else: if os.path.isdir(accountDir): @@ -2326,7 +2335,10 @@ class PubServer(BaseHTTPRequestHandler): newswireModFilename = accountDir + '/.newswiremoderated' if modPostsToNews != 'on': if os.path.isfile(newswireModFilename): - os.remove(newswireModFilename) + try: + os.remove(newswireModFilename) + except BaseException: + pass else: if os.path.isdir(accountDir): nwFilename = newswireModFilename @@ -3739,7 +3751,10 @@ class PubServer(BaseHTTPRequestHandler): linksFile.write(linksStr) else: if os.path.isfile(linksFilename): - os.remove(linksFilename) + try: + os.remove(linksFilename) + except BaseException: + pass adminNickname = \ getConfigParam(baseDir, 'admin') @@ -3752,7 +3767,10 @@ class PubServer(BaseHTTPRequestHandler): aboutFile.write(aboutStr) else: if os.path.isfile(aboutFilename): - os.remove(aboutFilename) + try: + os.remove(aboutFilename) + except BaseException: + pass if fields.get('editedTOS'): TOSStr = fields['editedTOS'] @@ -3762,7 +3780,10 @@ class PubServer(BaseHTTPRequestHandler): TOSFile.write(TOSStr) else: if os.path.isfile(TOSFilename): - os.remove(TOSFilename) + try: + os.remove(TOSFilename) + except BaseException: + pass # redirect back to the default timeline self._redirect_headers(actorStr + '/' + defaultTimeline, @@ -3860,7 +3881,10 @@ class PubServer(BaseHTTPRequestHandler): else: categoryFilename = baseDir + '/tags/' + hashtag + '.category' if os.path.isfile(categoryFilename): - os.remove(categoryFilename) + try: + os.remove(categoryFilename) + except BaseException: + pass # redirect back to the default timeline self._redirect_headers(tagScreenStr, @@ -3938,7 +3962,10 @@ class PubServer(BaseHTTPRequestHandler): newswireFile.write(newswireStr) else: if os.path.isfile(newswireFilename): - os.remove(newswireFilename) + try: + os.remove(newswireFilename) + except BaseException: + pass # save filtered words list for the newswire filterNewswireFilename = \ @@ -3949,7 +3976,10 @@ class PubServer(BaseHTTPRequestHandler): filterfile.write(fields['filteredWordsNewswire']) else: if os.path.isfile(filterNewswireFilename): - os.remove(filterNewswireFilename) + try: + os.remove(filterNewswireFilename) + except BaseException: + pass # save news tagging rules hashtagRulesFilename = \ @@ -3959,7 +3989,10 @@ class PubServer(BaseHTTPRequestHandler): rulesfile.write(fields['hashtagRulesList']) else: if os.path.isfile(hashtagRulesFilename): - os.remove(hashtagRulesFilename) + try: + os.remove(hashtagRulesFilename) + except BaseException: + pass newswireTrustedFilename = baseDir + '/accounts/newswiretrusted.txt' if fields.get('trustedNewswire'): @@ -3970,7 +4003,10 @@ class PubServer(BaseHTTPRequestHandler): trustFile.write(newswireTrusted) else: if os.path.isfile(newswireTrustedFilename): - os.remove(newswireTrustedFilename) + try: + os.remove(newswireTrustedFilename) + except BaseException: + pass # redirect back to the default timeline self._redirect_headers(actorStr + '/' + defaultTimeline, @@ -3995,7 +4031,10 @@ class PubServer(BaseHTTPRequestHandler): acctDir(baseDir, nickname, domain) + '/.citations.txt' # remove any existing citations file if os.path.isfile(citationsFilename): - os.remove(citationsFilename) + try: + os.remove(citationsFilename) + except BaseException: + pass if newswire and \ ' boundary=' in self.headers['Content-type']: @@ -4297,7 +4336,10 @@ class PubServer(BaseHTTPRequestHandler): filenameBase = \ baseDir + '/imports/newtheme.zip' if os.path.isfile(filenameBase): - os.remove(filenameBase) + try: + os.remove(filenameBase) + except BaseException: + pass else: filenameBase = \ acctDir(baseDir, nickname, domain) + \ @@ -5334,14 +5376,20 @@ class PubServer(BaseHTTPRequestHandler): for ext in fontExt: if os.path.isfile(baseDir + '/fonts/custom.' + ext): - os.remove(baseDir + - '/fonts/custom.' + ext) + try: + os.remove(baseDir + + '/fonts/custom.' + ext) + except BaseException: + pass if os.path.isfile(baseDir + '/fonts/custom.' + ext + '.etag'): - os.remove(baseDir + - '/fonts/custom.' + ext + - '.etag') + try: + os.remove(baseDir + + '/fonts/custom.' + ext + + '.etag') + except BaseException: + pass currTheme = getTheme(baseDir) if currTheme: self.server.themeName = currTheme @@ -5389,7 +5437,10 @@ class PubServer(BaseHTTPRequestHandler): fFile.write('\n') if not followDMsActive: if os.path.isfile(followDMsFilename): - os.remove(followDMsFilename) + try: + os.remove(followDMsFilename) + except BaseException: + pass # remove Twitter retweets removeTwitterFilename = \ @@ -5404,7 +5455,10 @@ class PubServer(BaseHTTPRequestHandler): rFile.write('\n') if not removeTwitterActive: if os.path.isfile(removeTwitterFilename): - os.remove(removeTwitterFilename) + try: + os.remove(removeTwitterFilename) + except BaseException: + pass # hide Like button hideLikeButtonFile = \ @@ -5421,10 +5475,16 @@ class PubServer(BaseHTTPRequestHandler): rFile.write('\n') # remove notify likes selection if os.path.isfile(notifyLikesFilename): - os.remove(notifyLikesFilename) + try: + os.remove(notifyLikesFilename) + except BaseException: + pass if not hideLikeButtonActive: if os.path.isfile(hideLikeButtonFile): - os.remove(hideLikeButtonFile) + try: + os.remove(hideLikeButtonFile) + except BaseException: + pass # notify about new Likes if onFinalWelcomeScreen: @@ -5442,7 +5502,10 @@ class PubServer(BaseHTTPRequestHandler): rFile.write('\n') if not notifyLikesActive: if os.path.isfile(notifyLikesFilename): - os.remove(notifyLikesFilename) + try: + os.remove(notifyLikesFilename) + except BaseException: + pass # this account is a bot if fields.get('isBot'): @@ -5501,7 +5564,10 @@ class PubServer(BaseHTTPRequestHandler): filterfile.write(fields['filteredWords']) else: if os.path.isfile(filterFilename): - os.remove(filterFilename) + try: + os.remove(filterFilename) + except BaseException: + pass # word replacements switchFilename = \ @@ -5512,7 +5578,10 @@ class PubServer(BaseHTTPRequestHandler): switchfile.write(fields['switchWords']) else: if os.path.isfile(switchFilename): - os.remove(switchFilename) + try: + os.remove(switchFilename) + except BaseException: + pass # autogenerated tags autoTagsFilename = \ @@ -5523,7 +5592,10 @@ class PubServer(BaseHTTPRequestHandler): autoTagsFile.write(fields['autoTags']) else: if os.path.isfile(autoTagsFilename): - os.remove(autoTagsFilename) + try: + os.remove(autoTagsFilename) + except BaseException: + pass # autogenerated content warnings autoCWFilename = \ @@ -5534,7 +5606,10 @@ class PubServer(BaseHTTPRequestHandler): autoCWFile.write(fields['autoCW']) else: if os.path.isfile(autoCWFilename): - os.remove(autoCWFilename) + try: + os.remove(autoCWFilename) + except BaseException: + pass # save blocked accounts list blockedFilename = \ @@ -5545,7 +5620,10 @@ class PubServer(BaseHTTPRequestHandler): blockedfile.write(fields['blocked']) else: if os.path.isfile(blockedFilename): - os.remove(blockedFilename) + try: + os.remove(blockedFilename) + except BaseException: + pass # Save DM allowed instances list. # The allow list for incoming DMs, @@ -5558,7 +5636,10 @@ class PubServer(BaseHTTPRequestHandler): aFile.write(fields['dmAllowedInstances']) else: if os.path.isfile(dmAllowedInstancesFilename): - os.remove(dmAllowedInstancesFilename) + try: + os.remove(dmAllowedInstancesFilename) + except BaseException: + pass # save allowed instances list # This is the account level allow list @@ -5570,7 +5651,10 @@ class PubServer(BaseHTTPRequestHandler): aFile.write(fields['allowedInstances']) else: if os.path.isfile(allowedInstancesFilename): - os.remove(allowedInstancesFilename) + try: + os.remove(allowedInstancesFilename) + except BaseException: + pass # save blocked user agents # This is admin lebel and global to the instance @@ -5615,7 +5699,10 @@ class PubServer(BaseHTTPRequestHandler): self.server.peertubeInstances.append(url) else: if os.path.isfile(peertubeInstancesFile): - os.remove(peertubeInstancesFile) + try: + os.remove(peertubeInstancesFile) + except BaseException: + pass self.server.peertubeInstances.clear() # save git project names list @@ -5627,7 +5714,10 @@ class PubServer(BaseHTTPRequestHandler): aFile.write(fields['gitProjects'].lower()) else: if os.path.isfile(gitProjectsFilename): - os.remove(gitProjectsFilename) + try: + os.remove(gitProjectsFilename) + except BaseException: + pass # save actor json file within accounts if actorChanged: @@ -15025,7 +15115,10 @@ class PubServer(BaseHTTPRequestHandler): self.server.lowBandwidth) if filename: if os.path.isfile(filename): - os.remove(filename) + try: + os.remove(filename) + except BaseException: + pass self.postToNickname = nickname return 1 return -1 diff --git a/devices.py b/devices.py index 8b56e5d37..1075f8582 100644 --- a/devices.py +++ b/devices.py @@ -44,7 +44,10 @@ def E2EEremoveDevice(baseDir: str, nickname: str, domain: str, personDir = acctDir(baseDir, nickname, domain) deviceFilename = personDir + '/devices/' + deviceId + '.json' if os.path.isfile(deviceFilename): - os.remove(deviceFilename) + try: + os.remove(deviceFilename) + except BaseException: + pass return True return False diff --git a/follow.py b/follow.py index 5182f1ff5..211960e96 100644 --- a/follow.py +++ b/follow.py @@ -308,7 +308,10 @@ def clearFollows(baseDir: str, nickname: str, domain: str, os.mkdir(baseDir + '/accounts/' + handle) filename = baseDir + '/accounts/' + handle + '/' + followFile if os.path.isfile(filename): - os.remove(filename) + try: + os.remove(filename) + except BaseException: + pass def clearFollowers(baseDir: str, nickname: str, domain: str) -> None: diff --git a/inbox.py b/inbox.py index c785e90ad..5161f4ca8 100644 --- a/inbox.py +++ b/inbox.py @@ -821,7 +821,10 @@ def _receiveUpdateToQuestion(recentPostsCache: {}, messageJson: {}, getCachedPostFilename(baseDir, nickname, domain, messageJson) if cachedPostFilename: if os.path.isfile(cachedPostFilename): - os.remove(cachedPostFilename) + try: + os.remove(cachedPostFilename) + except BaseException: + pass # remove from memory cache removePostFromCache(messageJson, recentPostsCache) @@ -1583,7 +1586,10 @@ def _receiveAnnounce(recentPostsCache: {}, if domain not in messageJson['object'] and notInOnion: if os.path.isfile(postFilename): # if the announce can't be downloaded then remove it - os.remove(postFilename) + try: + os.remove(postFilename) + except BaseException: + pass else: if debug: print('DEBUG: Announce post downloaded for ' + @@ -1693,7 +1699,10 @@ def _receiveUndoAnnounce(recentPostsCache: {}, undoAnnounceCollectionEntry(recentPostsCache, baseDir, postFilename, messageJson['actor'], domain, debug) if os.path.isfile(postFilename): - os.remove(postFilename) + try: + os.remove(postFilename) + except BaseException: + pass return True @@ -3276,7 +3285,10 @@ def runInboxQueue(recentPostsCache: {}, maxRecentPosts: int, if debug: print('Queue: public key could not be obtained from ' + keyId) if os.path.isfile(queueFilename): - os.remove(queueFilename) + try: + os.remove(queueFilename) + except BaseException: + pass if len(queue) > 0: queue.pop(0) continue @@ -3324,7 +3336,10 @@ def runInboxQueue(recentPostsCache: {}, maxRecentPosts: int, if httpSignatureFailed or verifyAllSignatures: if os.path.isfile(queueFilename): - os.remove(queueFilename) + try: + os.remove(queueFilename) + except BaseException: + pass if len(queue) > 0: queue.pop(0) continue @@ -3341,7 +3356,10 @@ def runInboxQueue(recentPostsCache: {}, maxRecentPosts: int, print('WARN: jsonld inbox signature check failed ' + keyId) if os.path.isfile(queueFilename): - os.remove(queueFilename) + try: + os.remove(queueFilename) + except BaseException: + pass if len(queue) > 0: queue.pop(0) continue @@ -3367,7 +3385,10 @@ def runInboxQueue(recentPostsCache: {}, maxRecentPosts: int, debug): print('Queue: Undo accepted from ' + keyId) if os.path.isfile(queueFilename): - os.remove(queueFilename) + try: + os.remove(queueFilename) + except BaseException: + pass if len(queue) > 0: queue.pop(0) continue @@ -3385,7 +3406,10 @@ def runInboxQueue(recentPostsCache: {}, maxRecentPosts: int, maxFollowers, onionDomain, signingPrivateKeyPem): if os.path.isfile(queueFilename): - os.remove(queueFilename) + try: + os.remove(queueFilename) + except BaseException: + pass if len(queue) > 0: queue.pop(0) print('Queue: Follow activity for ' + keyId + @@ -3403,7 +3427,10 @@ def runInboxQueue(recentPostsCache: {}, maxRecentPosts: int, federationList, debug): print('Queue: Accept/Reject received from ' + keyId) if os.path.isfile(queueFilename): - os.remove(queueFilename) + try: + os.remove(queueFilename) + except BaseException: + pass if len(queue) > 0: queue.pop(0) continue @@ -3421,7 +3448,10 @@ def runInboxQueue(recentPostsCache: {}, maxRecentPosts: int, if debug: print('Queue: Update accepted from ' + keyId) if os.path.isfile(queueFilename): - os.remove(queueFilename) + try: + os.remove(queueFilename) + except BaseException: + pass if len(queue) > 0: queue.pop(0) continue @@ -3436,7 +3466,10 @@ def runInboxQueue(recentPostsCache: {}, maxRecentPosts: int, print('Queue: no recipients were resolved ' + 'for post arriving in inbox') if os.path.isfile(queueFilename): - os.remove(queueFilename) + try: + os.remove(queueFilename) + except BaseException: + pass if len(queue) > 0: queue.pop(0) continue @@ -3506,6 +3539,9 @@ def runInboxQueue(recentPostsCache: {}, maxRecentPosts: int, pprint(queueJson['post']) print('Queue: Queue post accepted') if os.path.isfile(queueFilename): - os.remove(queueFilename) + try: + os.remove(queueFilename) + except BaseException: + pass if len(queue) > 0: queue.pop(0) diff --git a/like.py b/like.py index 55ef0ebbb..6765d6c1b 100644 --- a/like.py +++ b/like.py @@ -431,7 +431,10 @@ def updateLikesCollection(recentPostsCache: {}, domain, postJsonObject) if cachedPostFilename: if os.path.isfile(cachedPostFilename): - os.remove(cachedPostFilename) + try: + os.remove(cachedPostFilename) + except BaseException: + pass if not hasObjectDict(postJsonObject): if debug: diff --git a/manualapprove.py b/manualapprove.py index 97b6ae7b6..0d85bd1e6 100644 --- a/manualapprove.py +++ b/manualapprove.py @@ -222,6 +222,12 @@ def manualApproveFollowRequest(session, baseDir: str, # remove the .follow file if followActivityfilename: if os.path.isfile(followActivityfilename): - os.remove(followActivityfilename) + try: + os.remove(followActivityfilename) + except BaseException: + pass else: - os.remove(approveFollowsFilename + '.new') + try: + os.remove(approveFollowsFilename + '.new') + except BaseException: + pass diff --git a/newsdaemon.py b/newsdaemon.py index 6e529471b..63de2e116 100644 --- a/newsdaemon.py +++ b/newsdaemon.py @@ -702,7 +702,10 @@ def _convertRSStoActivityPub(baseDir: str, httpPrefix: str, blog['object']['arrived']) else: if os.path.isfile(filename + '.arrived'): - os.remove(filename + '.arrived') + try: + os.remove(filename + '.arrived') + except BaseException: + pass # setting the url here links to the activitypub object # stored locally diff --git a/newswire.py b/newswire.py index 5f8a1ba0b..15ca99516 100644 --- a/newswire.py +++ b/newswire.py @@ -1028,7 +1028,10 @@ def _addBlogsToNewswire(baseDir: str, domain: str, newswire: {}, else: # remove the file if there is nothing to moderate if os.path.isfile(newswireModerationFilename): - os.remove(newswireModerationFilename) + try: + os.remove(newswireModerationFilename) + except BaseException: + pass def getDictFromNewswire(session, baseDir: str, domain: str, diff --git a/outbox.py b/outbox.py index de654dc77..45b11d35e 100644 --- a/outbox.py +++ b/outbox.py @@ -390,7 +390,10 @@ def postMessageToOutbox(session, translate: {}, baseDir + '/accounts/' + \ postToNickname + '@' + domain + '/.citations.txt' if os.path.isfile(citationsFilename): - os.remove(citationsFilename) + try: + os.remove(citationsFilename) + except BaseException: + pass # The following activity types get added to the index files indexedActivities = ( diff --git a/person.py b/person.py index 9c5876157..a45d09a11 100644 --- a/person.py +++ b/person.py @@ -919,10 +919,16 @@ def suspendAccount(baseDir: str, nickname: str, domain: str) -> None: saltFilename = acctDir(baseDir, nickname, domain) + '/.salt' if os.path.isfile(saltFilename): - os.remove(saltFilename) + try: + os.remove(saltFilename) + except BaseException: + pass tokenFilename = acctDir(baseDir, nickname, domain) + '/.token' if os.path.isfile(tokenFilename): - os.remove(tokenFilename) + try: + os.remove(tokenFilename) + except BaseException: + pass suspendedFilename = baseDir + '/accounts/suspended.txt' if os.path.isfile(suspendedFilename): @@ -1025,17 +1031,32 @@ def removeAccount(baseDir: str, nickname: str, if os.path.isdir(baseDir + '/accounts/' + handle): shutil.rmtree(baseDir + '/accounts/' + handle) if os.path.isfile(baseDir + '/accounts/' + handle + '.json'): - os.remove(baseDir + '/accounts/' + handle + '.json') + try: + os.remove(baseDir + '/accounts/' + handle + '.json') + except BaseException: + pass if os.path.isfile(baseDir + '/wfendpoints/' + handle + '.json'): - os.remove(baseDir + '/wfendpoints/' + handle + '.json') + try: + os.remove(baseDir + '/wfendpoints/' + handle + '.json') + except BaseException: + pass if os.path.isfile(baseDir + '/keys/private/' + handle + '.key'): - os.remove(baseDir + '/keys/private/' + handle + '.key') + try: + os.remove(baseDir + '/keys/private/' + handle + '.key') + except BaseException: + pass if os.path.isfile(baseDir + '/keys/public/' + handle + '.pem'): - os.remove(baseDir + '/keys/public/' + handle + '.pem') + try: + os.remove(baseDir + '/keys/public/' + handle + '.pem') + except BaseException: + pass if os.path.isdir(baseDir + '/sharefiles/' + nickname): shutil.rmtree(baseDir + '/sharefiles/' + nickname) if os.path.isfile(baseDir + '/wfdeactivated/' + handle + '.json'): - os.remove(baseDir + '/wfdeactivated/' + handle + '.json') + try: + os.remove(baseDir + '/wfdeactivated/' + handle + '.json') + except BaseException: + pass if os.path.isdir(baseDir + '/sharefilesdeactivated/' + nickname): shutil.rmtree(baseDir + '/sharefilesdeactivated/' + nickname) diff --git a/posts.py b/posts.py index 394ccd0ca..df0839a21 100644 --- a/posts.py +++ b/posts.py @@ -1470,7 +1470,10 @@ def undoPinnedPost(baseDir: str, nickname: str, domain: str) -> None: accountDir = acctDir(baseDir, nickname, domain) pinnedFilename = accountDir + '/pinToProfile.txt' if os.path.isfile(pinnedFilename): - os.remove(pinnedFilename) + try: + os.remove(pinnedFilename) + except BaseException: + pass def getPinnedPostAsJson(baseDir: str, httpPrefix: str, @@ -3766,7 +3769,10 @@ def archivePostsForPerson(httpPrefix: str, nickname: str, domain: str, postCacheFilename = \ os.path.join(postCacheDir, postFilename).replace('.json', '.html') if os.path.isfile(postCacheFilename): - os.remove(postCacheFilename) + try: + os.remove(postCacheFilename) + except BaseException: + pass noOfPosts -= 1 removeCtr += 1 diff --git a/schedule.py b/schedule.py index 165160ced..48d4bd035 100644 --- a/schedule.py +++ b/schedule.py @@ -46,7 +46,10 @@ def _updatePostSchedule(baseDir: str, handle: str, httpd, if deleteSchedulePost: # delete extraneous scheduled posts if os.path.isfile(postFilename): - os.remove(postFilename) + try: + os.remove(postFilename) + except BaseException: + pass continue # create the new index file indexLines.append(line) @@ -122,7 +125,10 @@ def _updatePostSchedule(baseDir: str, handle: str, httpd, httpd.maxLikeCount, httpd.maxRecentPosts): indexLines.remove(line) - os.remove(postFilename) + try: + os.remove(postFilename) + except BaseException: + pass continue # move to the outbox @@ -190,7 +196,10 @@ def removeScheduledPosts(baseDir: str, nickname: str, domain: str) -> None: scheduleIndexFilename = \ acctDir(baseDir, nickname, domain) + '/schedule.index' if os.path.isfile(scheduleIndexFilename): - os.remove(scheduleIndexFilename) + try: + os.remove(scheduleIndexFilename) + except BaseException: + pass # remove the scheduled posts scheduledDir = acctDir(baseDir, nickname, domain) + '/scheduled' if not os.path.isdir(scheduledDir): @@ -199,6 +208,9 @@ def removeScheduledPosts(baseDir: str, nickname: str, domain: str) -> None: filePath = os.path.join(scheduledDir, scheduledPostFilename) try: if os.path.isfile(filePath): - os.remove(filePath) + try: + os.remove(filePath) + except BaseException: + pass except BaseException: pass diff --git a/shares.py b/shares.py index dd40d583b..60096d2d2 100644 --- a/shares.py +++ b/shares.py @@ -142,7 +142,10 @@ def removeSharedItem(baseDir: str, nickname: str, domain: str, for ext in formats: if sharesJson[itemID]['imageUrl'].endswith('.' + ext): if os.path.isfile(itemIDfile + '.' + ext): - os.remove(itemIDfile + '.' + ext) + try: + os.remove(itemIDfile + '.' + ext) + except BaseException: + pass # remove the item itself del sharesJson[itemID] saveJson(sharesJson, sharesFilename) @@ -350,7 +353,10 @@ def addShare(baseDir: str, imageFilename, itemIDfile + '.' + ext, city) if moveImage: - os.remove(imageFilename) + try: + os.remove(imageFilename) + except BaseException: + pass imageUrl = \ httpPrefix + '://' + domainFull + \ '/sharefiles/' + nickname + '/' + itemID + '.' + ext @@ -419,7 +425,10 @@ def _expireSharesForAccount(baseDir: str, nickname: str, domain: str, formats = getImageExtensions() for ext in formats: if os.path.isfile(itemIDfile + '.' + ext): - os.remove(itemIDfile + '.' + ext) + try: + os.remove(itemIDfile + '.' + ext) + except BaseException: + pass saveJson(sharesJson, sharesFilename) diff --git a/tests.py b/tests.py index 4b5692f61..2018886f1 100644 --- a/tests.py +++ b/tests.py @@ -3197,7 +3197,10 @@ def _testJsonString() -> None: assert receivedJson['content'] == messageStr encodedStr = json.dumps(testJson, ensure_ascii=False) assert messageStr in encodedStr - os.remove(filename) + try: + os.remove(filename) + except BaseException: + pass def _testSaveLoadJson(): @@ -3208,7 +3211,10 @@ def _testSaveLoadJson(): } testFilename = '.epicyon_tests_testSaveLoadJson.json' if os.path.isfile(testFilename): - os.remove(testFilename) + try: + os.remove(testFilename) + except BaseException: + pass assert saveJson(testJson, testFilename) assert os.path.isfile(testFilename) testLoadJson = loadJson(testFilename) @@ -3217,7 +3223,10 @@ def _testSaveLoadJson(): assert testLoadJson.get('param2') assert testLoadJson['param1'] == 3 assert testLoadJson['param2'] == '"Crème brûlée यह एक परीक्षण ह"' - os.remove(testFilename) + try: + os.remove(testFilename) + except BaseException: + pass def _testTheme(): diff --git a/theme.py b/theme.py index 7f8d96086..232898a9f 100644 --- a/theme.py +++ b/theme.py @@ -83,7 +83,10 @@ def exportTheme(baseDir: str, theme: str) -> bool: os.mkdir(baseDir + '/exports') exportFilename = baseDir + '/exports/' + theme + '.zip' if os.path.isfile(exportFilename): - os.remove(exportFilename) + try: + os.remove(exportFilename) + except BaseException: + pass try: make_archive(baseDir + '/exports/' + theme, 'zip', themeDir) except BaseException: @@ -250,7 +253,10 @@ def _removeTheme(baseDir: str): themeFiles = _getThemeFiles() for filename in themeFiles: if os.path.isfile(baseDir + '/' + filename): - os.remove(baseDir + '/' + filename) + try: + os.remove(baseDir + '/' + filename) + except BaseException: + pass def setCSSparam(css: str, param: str, value: str) -> str: @@ -432,7 +438,10 @@ def disableGrayscale(baseDir: str) -> None: cssfile.write(css) grayscaleFilename = baseDir + '/accounts/.grayscale' if os.path.isfile(grayscaleFilename): - os.remove(grayscaleFilename) + try: + os.remove(grayscaleFilename) + except BaseException: + pass def _setCustomFont(baseDir: str): @@ -587,7 +596,10 @@ def _setTextModeTheme(baseDir: str, name: str) -> None: textModeBannerFilename = \ baseDir + '/theme/' + name + '/banner.txt' if os.path.isfile(baseDir + '/accounts/banner.txt'): - os.remove(baseDir + '/accounts/banner.txt') + try: + os.remove(baseDir + '/accounts/banner.txt') + except BaseException: + pass if os.path.isfile(textModeBannerFilename): try: copyfile(textModeBannerFilename, @@ -684,7 +696,10 @@ def _setThemeImages(baseDir: str, name: str) -> None: else: if os.path.isfile(accountDir + '/left_col_image.png'): - os.remove(accountDir + '/left_col_image.png') + try: + os.remove(accountDir + '/left_col_image.png') + except BaseException: + pass except BaseException: pass @@ -696,7 +711,10 @@ def _setThemeImages(baseDir: str, name: str) -> None: else: if os.path.isfile(accountDir + '/right_col_image.png'): - os.remove(accountDir + '/right_col_image.png') + try: + os.remove(accountDir + '/right_col_image.png') + except BaseException: + pass except BaseException: pass break @@ -719,7 +737,10 @@ def setNewsAvatar(baseDir: str, name: str, filename = baseDir + '/cache/avatars/' + avatarFilename if os.path.isfile(filename): - os.remove(filename) + try: + os.remove(filename) + except BaseException: + pass if os.path.isdir(baseDir + '/cache/avatars'): copyfile(newFilename, filename) accountDir = acctDir(baseDir, nickname, domain) diff --git a/utils.py b/utils.py index 749c89c98..5dc621815 100644 --- a/utils.py +++ b/utils.py @@ -614,7 +614,10 @@ def removeAvatarFromCache(baseDir: str, actorStr: str) -> None: avatarFilename = \ baseDir + '/cache/avatars/' + actorStr + '.' + extension if os.path.isfile(avatarFilename): - os.remove(avatarFilename) + try: + os.remove(avatarFilename) + except BaseException: + pass def saveJson(jsonObject: {}, filename: str) -> bool: @@ -1318,10 +1321,16 @@ def _removeAttachment(baseDir: str, httpPrefix: str, domain: str, mediaFilename = baseDir + '/' + \ attachmentUrl.replace(httpPrefix + '://' + domain + '/', '') if os.path.isfile(mediaFilename): - os.remove(mediaFilename) + try: + os.remove(mediaFilename) + except BaseException: + pass etagFilename = mediaFilename + '.etag' if os.path.isfile(etagFilename): - os.remove(etagFilename) + try: + os.remove(etagFilename) + except BaseException: + pass postJson['attachment'] = [] @@ -1386,7 +1395,10 @@ def _deletePostRemoveReplies(baseDir: str, nickname: str, domain: str, nickname, domain, replyFile, debug, recentPostsCache) # remove the replies file - os.remove(repliesFilename) + try: + os.remove(repliesFilename) + except BaseException: + pass def _isBookmarked(baseDir: str, nickname: str, domain: str, @@ -1442,7 +1454,10 @@ def _deleteCachedHtml(baseDir: str, nickname: str, domain: str, getCachedPostFilename(baseDir, nickname, domain, postJsonObject) if cachedPostFilename: if os.path.isfile(cachedPostFilename): - os.remove(cachedPostFilename) + try: + os.remove(cachedPostFilename) + except BaseException: + pass def _deleteHashtagsOnPost(baseDir: str, postJsonObject: {}) -> None: @@ -1486,7 +1501,10 @@ def _deleteHashtagsOnPost(baseDir: str, postJsonObject: {}) -> None: newlines += fileLine if not newlines.strip(): # if there are no lines then remove the hashtag file - os.remove(tagIndexFilename) + try: + os.remove(tagIndexFilename) + except BaseException: + pass else: # write the new hashtag index without the given post in it with open(tagIndexFilename, 'w+') as f: @@ -1521,8 +1539,14 @@ def _deleteConversationPost(baseDir: str, nickname: str, domain: str, fp.write(conversationStr) else: if os.path.isfile(conversationFilename + '.muted'): - os.remove(conversationFilename + '.muted') - os.remove(conversationFilename) + try: + os.remove(conversationFilename + '.muted') + except BaseException: + pass + try: + os.remove(conversationFilename) + except BaseException: + pass def deletePost(baseDir: str, httpPrefix: str, @@ -1537,7 +1561,10 @@ def deletePost(baseDir: str, httpPrefix: str, httpPrefix, postFilename, recentPostsCache, debug) # finally, remove the post itself - os.remove(postFilename) + try: + os.remove(postFilename) + except BaseException: + pass return # don't allow deletion of bookmarked posts @@ -1562,7 +1589,10 @@ def deletePost(baseDir: str, httpPrefix: str, for ext in extensions: extFilename = postFilename + '.' + ext if os.path.isfile(extFilename): - os.remove(extFilename) + try: + os.remove(extFilename) + except BaseException: + pass # remove cached html version of the post _deleteCachedHtml(baseDir, nickname, domain, postJsonObject) @@ -1588,7 +1618,10 @@ def deletePost(baseDir: str, httpPrefix: str, httpPrefix, postFilename, recentPostsCache, debug) # finally, remove the post itself - os.remove(postFilename) + try: + os.remove(postFilename) + except BaseException: + pass def isValidLanguage(text: str) -> bool: @@ -2022,7 +2055,10 @@ def undoLikesCollectionEntry(recentPostsCache: {}, domain, postJsonObject) if cachedPostFilename: if os.path.isfile(cachedPostFilename): - os.remove(cachedPostFilename) + try: + os.remove(cachedPostFilename) + except BaseException: + pass removePostFromCache(postJsonObject, recentPostsCache) if not postJsonObject.get('type'): @@ -2083,7 +2119,10 @@ def undoAnnounceCollectionEntry(recentPostsCache: {}, postJsonObject) if cachedPostFilename: if os.path.isfile(cachedPostFilename): - os.remove(cachedPostFilename) + try: + os.remove(cachedPostFilename) + except BaseException: + pass removePostFromCache(postJsonObject, recentPostsCache) if not postJsonObject.get('type'): @@ -2144,7 +2183,10 @@ def updateAnnounceCollection(recentPostsCache: {}, postJsonObject) if cachedPostFilename: if os.path.isfile(cachedPostFilename): - os.remove(cachedPostFilename) + try: + os.remove(cachedPostFilename) + except BaseException: + pass removePostFromCache(postJsonObject, recentPostsCache) if not hasObjectDict(postJsonObject): diff --git a/webapp_calendar.py b/webapp_calendar.py index 26a0be727..9fbe1eaed 100644 --- a/webapp_calendar.py +++ b/webapp_calendar.py @@ -110,7 +110,10 @@ def _htmlCalendarDay(personCache: {}, cssCache: {}, translate: {}, accountDir = acctDir(baseDir, nickname, domain) calendarFile = accountDir + '/.newCalendar' if os.path.isfile(calendarFile): - os.remove(calendarFile) + try: + os.remove(calendarFile) + except BaseException: + pass cssFilename = baseDir + '/epicyon-calendar.css' if os.path.isfile(baseDir + '/calendar.css'): diff --git a/webapp_minimalbutton.py b/webapp_minimalbutton.py index b3e3ce40b..716f3ba55 100644 --- a/webapp_minimalbutton.py +++ b/webapp_minimalbutton.py @@ -34,7 +34,10 @@ def setMinimal(baseDir: str, domain: str, nickname: str, minimalFilename = accountDir + '/.notminimal' minimalFileExists = os.path.isfile(minimalFilename) if minimal and minimalFileExists: - os.remove(minimalFilename) + try: + os.remove(minimalFilename) + except BaseException: + pass elif not minimal and not minimalFileExists: with open(minimalFilename, 'w+') as fp: fp.write('\n') diff --git a/webapp_timeline.py b/webapp_timeline.py index 14e1d45d5..f375272ba 100644 --- a/webapp_timeline.py +++ b/webapp_timeline.py @@ -451,7 +451,10 @@ def htmlTimeline(cssCache: {}, defaultTimeline: str, if os.path.isfile(dmFile): newDM = True if boxName == 'dm': - os.remove(dmFile) + try: + os.remove(dmFile) + except BaseException: + pass # should the Replies button be highlighted? newReply = False @@ -459,7 +462,10 @@ def htmlTimeline(cssCache: {}, defaultTimeline: str, if os.path.isfile(replyFile): newReply = True if boxName == 'tlreplies': - os.remove(replyFile) + try: + os.remove(replyFile) + except BaseException: + pass # should the Shares button be highlighted? newShare = False @@ -467,7 +473,10 @@ def htmlTimeline(cssCache: {}, defaultTimeline: str, if os.path.isfile(newShareFile): newShare = True if boxName == 'tlshares': - os.remove(newShareFile) + try: + os.remove(newShareFile) + except BaseException: + pass # should the Wanted button be highlighted? newWanted = False @@ -475,7 +484,10 @@ def htmlTimeline(cssCache: {}, defaultTimeline: str, if os.path.isfile(newWantedFile): newWanted = True if boxName == 'tlwanted': - os.remove(newWantedFile) + try: + os.remove(newWantedFile) + except BaseException: + pass # should the Moderation/reports button be highlighted? newReport = False @@ -483,7 +495,10 @@ def htmlTimeline(cssCache: {}, defaultTimeline: str, if os.path.isfile(newReportFile): newReport = True if boxName == 'moderation': - os.remove(newReportFile) + try: + os.remove(newReportFile) + except BaseException: + pass separatorStr = '' if boxName != 'tlmedia': diff --git a/webapp_utils.py b/webapp_utils.py index 3bb07355d..cae7cfd54 100644 --- a/webapp_utils.py +++ b/webapp_utils.py @@ -280,7 +280,10 @@ def updateAvatarImageCache(signingPrivateKeyPem: str, str(result.status_code)) # remove partial download if os.path.isfile(avatarImageFilename): - os.remove(avatarImageFilename) + try: + os.remove(avatarImageFilename) + except BaseException: + pass else: with open(avatarImageFilename, 'wb') as f: f.write(result.content)