Skip to content

Commit 2bb3fc2

Browse files
committed
CHANGES:
- Olympus / Tacview: more secure writing of Export.lua
1 parent 27cd543 commit 2bb3fc2

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

extensions/olympus/extension.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
_ = get_translation(__name__.split('.')[1])
2121

22-
OLYMPUS_EXPORT_LINE = "pcall(function() local olympusLFS=require('lfs');dofile(olympusLFS.writedir()..[[Mods\\Services\\Olympus\\Scripts\\OlympusCameraControl.lua]]); end,nil)\n"
22+
OLYMPUS_EXPORT_LINE = "pcall(function() local olympusLFS=require('lfs');dofile(olympusLFS.writedir()..[[Mods\\Services\\Olympus\\Scripts\\OlympusCameraControl.lua]]); end,nil)"
2323
ANSI_ESCAPE_RE = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])')
2424

2525
server_ports: dict[int, str] = dict()
@@ -222,8 +222,11 @@ async def prepare_exports_lua(self):
222222
except FileNotFoundError:
223223
lines = []
224224

225-
if OLYMPUS_EXPORT_LINE not in lines:
226-
lines.append(OLYMPUS_EXPORT_LINE)
225+
for line in lines:
226+
if OLYMPUS_EXPORT_LINE in line:
227+
break
228+
else:
229+
lines.append(OLYMPUS_EXPORT_LINE + '\n')
227230
async with aiofiles.open(export_file, mode='w', encoding='utf-8') as outfile:
228231
await outfile.writelines(lines)
229232

extensions/tacview/extension.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
_ = get_translation(__name__.split('.')[1])
1616

1717
TACVIEW_DEFAULT_DIR = os.path.normpath(os.path.expandvars(os.path.join('%USERPROFILE%', 'Documents', 'Tacview')))
18-
TACVIEW_EXPORT_LINE = "local Tacviewlfs=require('lfs');dofile(Tacviewlfs.writedir()..'Scripts/TacviewGameExport.lua')\n"
18+
TACVIEW_EXPORT_LINE = "local Tacviewlfs=require('lfs');dofile(Tacviewlfs.writedir()..'Scripts/TacviewGameExport.lua')"
1919
TACVIEW_PATTERN_MATCH = r'Successfully saved \[(?P<filename>.*?\.acmi)\]'
2020

2121
rtt_ports: dict[int, str] = dict()
@@ -355,8 +355,11 @@ def ignore_funct(dirname, filenames) -> list[str]:
355355
lines = await infile.readlines()
356356
except FileNotFoundError:
357357
lines = []
358-
if TACVIEW_EXPORT_LINE not in lines:
359-
lines.append(TACVIEW_EXPORT_LINE)
358+
for line in lines:
359+
if TACVIEW_EXPORT_LINE in line:
360+
break
361+
else:
362+
lines.append(TACVIEW_EXPORT_LINE + '\n')
360363
async with aiofiles.open(export_file, mode='w', encoding='utf-8') as outfile:
361364
await outfile.writelines(lines)
362365
# load the configuration

0 commit comments

Comments
 (0)