mirror of
git://github.com/kovidgoyal/calibre.git
synced 2025-12-24 09:39:55 +01:00
Welcome wizard: Fix changing the language causing a empty folder to be created. Fixes #1903825 [Calibre installer makes an extra library folder](https://bugs.launchpad.net/calibre/+bug/1903825)
This commit is contained in:
parent
587b113c84
commit
3b5016c010
1 changed files with 12 additions and 3 deletions
|
|
@ -9,7 +9,7 @@
|
|||
import os
|
||||
import re
|
||||
import traceback
|
||||
from contextlib import closing
|
||||
from contextlib import closing, suppress
|
||||
from PyQt5.Qt import (
|
||||
QAbstractListModel, QDir, QIcon, QItemSelection, QItemSelectionModel, Qt,
|
||||
QWizard, QWizardPage, pyqtSignal
|
||||
|
|
@ -655,6 +655,7 @@ class LibraryPage(QWizardPage, LibraryUI):
|
|||
|
||||
def __init__(self):
|
||||
QWizardPage.__init__(self)
|
||||
self.made_dirs = []
|
||||
self.initial_library_location = None
|
||||
self.setupUi(self)
|
||||
self.registerField('library_location', self.location)
|
||||
|
|
@ -664,6 +665,10 @@ def __init__(self):
|
|||
self.location.textChanged.connect(self.location_text_changed)
|
||||
self.set_move_lib_label_text()
|
||||
|
||||
def makedirs(self, x):
|
||||
self.made_dirs.append(x)
|
||||
os.makedirs(x)
|
||||
|
||||
def location_text_changed(self, newtext):
|
||||
self.completeChanged.emit()
|
||||
|
||||
|
|
@ -759,7 +764,7 @@ def change(self):
|
|||
show=True)
|
||||
if not os.path.exists(x):
|
||||
try:
|
||||
os.makedirs(x)
|
||||
self.makedirs(x)
|
||||
except:
|
||||
return error_dialog(self, _('Bad location'),
|
||||
_('Failed to create a folder at %s')%x,
|
||||
|
|
@ -794,7 +799,7 @@ def set_initial_library_location(self):
|
|||
self.default_library_name = lp
|
||||
if not os.path.exists(lp):
|
||||
try:
|
||||
os.makedirs(lp)
|
||||
self.makedirs(lp)
|
||||
except:
|
||||
traceback.print_exc()
|
||||
try:
|
||||
|
|
@ -828,6 +833,10 @@ def commit(self):
|
|||
os.rmdir(dln)
|
||||
except Exception:
|
||||
pass
|
||||
# dont leave behind any empty dirs
|
||||
for x in self.made_dirs:
|
||||
with suppress(OSError):
|
||||
os.rmdir(x)
|
||||
if not os.path.exists(newloc):
|
||||
os.makedirs(newloc)
|
||||
prefs['library_path'] = newloc
|
||||
|
|
|
|||
Loading…
Reference in a new issue