From f0ca2c0cc31ba6771993e157734f0988c50621ba Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 25 Jan 2015 05:05:03 +0530 Subject: [PATCH] Do not mask the correct exception when failing to create the backup metadata.opf file --- src/calibre/db/backend.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/calibre/db/backend.py b/src/calibre/db/backend.py index faa86557f7..1603ac9eb9 100644 --- a/src/calibre/db/backend.py +++ b/src/calibre/db/backend.py @@ -8,7 +8,7 @@ __copyright__ = '2011, Kovid Goyal ' __docformat__ = 'restructuredtext en' # Imports {{{ -import os, shutil, uuid, json, glob, time, cPickle, hashlib, errno +import os, shutil, uuid, json, glob, time, cPickle, hashlib, errno, sys from functools import partial import apsw @@ -1538,7 +1538,14 @@ class DB(object): with lopen(path, 'wb') as f: f.write(raw) except EnvironmentError: - os.makedirs(os.path.dirname(path)) + exc_info = sys.exc_info() + try: + os.makedirs(os.path.dirname(path)) + except EnvironmentError as err: + if err.errno == errno.EEXIST: + # Parent directory already exists, re-raise original exception + raise exc_info[0], exc_info[1], exc_info[2] + raise with lopen(path, 'wb') as f: f.write(raw)