From 4f6ec7636505e30284182044de442522c1fffa23 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Tue, 25 Feb 2020 17:38:49 +1000 Subject: [PATCH] ensure user doesn't try to export into data folder https://anki.tenderapp.com/discussions/ankidesktop/39008-export-path-accidentally-set-to-collectionmedia-possible-damage --- qt/aqt/exporting.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/qt/aqt/exporting.py b/qt/aqt/exporting.py index 657d24f3d..b30cf4287 100644 --- a/qt/aqt/exporting.py +++ b/qt/aqt/exporting.py @@ -1,6 +1,8 @@ # Copyright: Ankitects Pty Ltd and contributors # License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html +from __future__ import annotations + import os import re import time @@ -15,7 +17,7 @@ from aqt.utils import checkInvalidFilename, getSaveFile, showInfo, showWarning, class ExportDialog(QDialog): - def __init__(self, mw, did: Optional[int] = None, cids: Optional[List[int]] = None): + def __init__(self, mw: aqt.main.AnkiQt, did: Optional[int] = None, cids: Optional[List[int]] = None): QDialog.__init__(self, mw, Qt.Window) self.mw = mw self.col = mw.col @@ -129,6 +131,9 @@ class ExportDialog(QDialog): return if checkInvalidFilename(os.path.basename(file), dirsep=False): continue + if os.path.commonprefix([self.mw.pm.base, file]) == self.mw.pm.base: + showWarning("Please choose a different export location.") + continue break self.hide() if file: