Move the cleanup() function from Onionshare class to Web class, so that the list of files to be cleaned up is always available (needed for website temp files)

This commit is contained in:
Miguel Jacq 2021-05-04 16:21:42 +10:00
parent e48b300ff9
commit ff5e73a2ae
10 changed files with 40 additions and 38 deletions

View file

@ -21,6 +21,7 @@ import logging
import os
import queue
import requests
import shutil
from distutils.version import LooseVersion as Version
import flask
@ -162,6 +163,8 @@ class Web:
self.socketio.init_app(self.app)
self.chat_mode = ChatModeWeb(self.common, self)
self.cleanup_filenames = []
def get_mode(self):
if self.mode == "share":
return self.share_mode
@ -423,3 +426,21 @@ class Web:
# Reset any password that was in use
self.password = None
def cleanup(self):
"""
Shut everything down and clean up temporary files, etc.
"""
self.common.log("Web", "cleanup")
# Cleanup files
try:
for filename in self.cleanup_filenames:
if os.path.isfile(filename):
os.remove(filename)
elif os.path.isdir(filename):
shutil.rmtree(filename)
except Exception:
# Don't crash if file is still in use
pass
self.cleanup_filenames = []