Fix bugs in database migration logic

This commit is contained in:
Kovid Goyal 2008-02-08 00:59:54 +00:00
parent df8f2d88d0
commit 50c484fc35

View File

@ -688,16 +688,20 @@ class Main(MainWindow, Ui_MainWindow):
try: try:
newloc = os.path.join(d.database_location, os.path.basename(self.database_path)) newloc = os.path.join(d.database_location, os.path.basename(self.database_path))
if not os.path.exists(newloc): if not os.path.exists(newloc):
dirname = os.path.dirname(newloc)
if not os.path.isdir(dirname):
os.makedirs(dirname)
dest = open(newloc, 'wb') dest = open(newloc, 'wb')
self.status_bar.showMessage('Copying database to '+newloc) if os.access(self.database_path, os.R_OK):
self.setCursor(Qt.BusyCursor) self.status_bar.showMessage('Copying database to '+newloc)
self.library_view.setEnabled(False) self.setCursor(Qt.BusyCursor)
self.library_view.close() self.library_view.setEnabled(False)
src = open(self.database_path, 'rb') self.library_view.close()
shutil.copyfileobj(src, dest) src = open(self.database_path, 'rb')
src.close() shutil.copyfileobj(src, dest)
dest.close() src.close()
os.unlink(self.database_path) dest.close()
os.unlink(self.database_path)
else: else:
try: try:
db = LibraryDatabase(newloc) db = LibraryDatabase(newloc)