diff --git a/src/calibre/constants.py b/src/calibre/constants.py index a2939ff96f..0444550597 100644 --- a/src/calibre/constants.py +++ b/src/calibre/constants.py @@ -2,7 +2,7 @@ __license__ = 'GPL v3' __copyright__ = '2008, Kovid Goyal kovid@kovidgoyal.net' __docformat__ = 'restructuredtext en' __appname__ = 'calibre' -__version__ = '0.4.84b4' +__version__ = '0.4.84b5' __author__ = "Kovid Goyal " ''' Various run time constants. diff --git a/src/calibre/library/database.py b/src/calibre/library/database.py index cf6b59d25e..947cd0697a 100644 --- a/src/calibre/library/database.py +++ b/src/calibre/library/database.py @@ -1418,6 +1418,8 @@ ALTER TABLE books ADD COLUMN isbn TEXT DEFAULT "" COLLATE NOCASE; fmts = '' for fmt in fmts.split(','): data = self.format(idx, fmt, index_is_id=index_is_id) + if not data: + continue fname = name +'.'+fmt.lower() fname = sanitize_file_name(fname) f = open(os.path.join(base, fname), 'w+b') diff --git a/src/calibre/library/database2.py b/src/calibre/library/database2.py index 4c7ee725d8..1e3b577ead 100644 --- a/src/calibre/library/database2.py +++ b/src/calibre/library/database2.py @@ -281,6 +281,8 @@ class LibraryDatabase2(LibraryDatabase): for format in formats: # Get data as string (cant use file as source and target files may be the same) f = self.format(id, format, index_is_id=True, as_file=False) + if not f: + continue stream = cStringIO.StringIO(f) self.add_format(id, format, stream, index_is_id=True, path=tpath) self.conn.execute('UPDATE books SET path=? WHERE id=?', (path, id)) @@ -344,6 +346,7 @@ class LibraryDatabase2(LibraryDatabase): if os.access(path, os.R_OK|os.W_OK): f = open(path, mode) return f if as_file else f.read() + self.remove_format(id, format, index_is_id=True) def add_format(self, index, format, stream, index_is_id=False, path=None): id = index if index_is_id else self.id(index) @@ -384,7 +387,7 @@ class LibraryDatabase2(LibraryDatabase): ext = ('.' + format.lower()) if format else '' path = os.path.join(path, name+ext) if os.access(path, os.W_OK): - os.unlink(path) + os.remove(path) self.conn.execute('DELETE FROM data WHERE book=? AND format=?', (id, format.upper())) self.conn.commit()