From 0e20f4bc00ed7f71629b0b47c35f1732fc64a96a Mon Sep 17 00:00:00 2001
From: Athanasius <github@miggy.org>
Date: Thu, 29 Sep 2022 17:18:39 +0100
Subject: [PATCH] EDDNSender: Remove legacy file after migration

---
 plugins/eddn.py | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/plugins/eddn.py b/plugins/eddn.py
index a5755b48..f09a4544 100644
--- a/plugins/eddn.py
+++ b/plugins/eddn.py
@@ -24,6 +24,7 @@
 # ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $# ! $#
 import itertools
 import json
+import os
 import pathlib
 import re
 import sqlite3
@@ -281,8 +282,8 @@ class EDDNSender:
 
     def convert_legacy_file(self):
         """Convert a legacy file's contents into the sqlite3 db."""
+        filename = config.app_dir_path / 'replay.jsonl'
         try:
-            filename = config.app_dir_path / 'replay.jsonl'
             with open(filename, 'r+', buffering=1) as replay_file:
                 for line in replay_file:
                     cmdr, msg = json.loads(line)
@@ -291,6 +292,13 @@ class EDDNSender:
         except FileNotFoundError:
             pass
 
+        finally:
+            # Best effort at removing the file/contents
+            # NB: The legacy code assumed it could write to the file.
+            replay_file = open(filename, 'w')  # Will truncate
+            replay_file.close()
+            os.unlink(filename)
+
 
 # TODO: a good few of these methods are static or could be classmethods. they should be created as such.
 class EDDN: