Commit 7ca526c3 authored by Martin Matějek's avatar Martin Matějek

Refactor removing files from FS to use python native os.* functions

parent 42222d1c
......@@ -18,3 +18,6 @@ class NoSuchNotificationException(Exception):
class NotificationNotDismissibleException(Exception):
class RemoveFailedException(Exception):
......@@ -5,7 +5,10 @@ from collections import OrderedDict
from datetime import datetime
from functools import lru_cache
from .exceptions import MediaTypeNotAvailableException
from .exceptions import (
from .logger import logger
from .notification import Notification
......@@ -156,7 +159,14 @@ class NotificationStorage:
filename = os.path.join(storage_dir, "{}.json".format(msgid))
tmp_filename = os.path.join("/tmp", "{}.json".format(msgid))
# TODO: os.rename(), unlink()
# py3 pathlib["mv", filename, tmp_filename])["rm", tmp_filename])
os.rename(filename, tmp_filename)
except IsADirectoryError:
logger.warning("Cannot rename file. There already is a directory with the same name!")
raise RemoveFailedException("Moving to tmpfile failed. Please see the logs.")
except OSError as e:
logger.warning("Can't remove '%s'. Reason: %s", tmp_filename, e)
raise RemoveFailedException("Failed to remove file. Please see the logs.")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment