File tree 1 file changed +15
-14
lines changed
1 file changed +15
-14
lines changed Original file line number Diff line number Diff line change @@ -56,21 +56,22 @@ def connect(path: str = path_on_device) -> None:
56
56
self .dbpath = path
57
57
self .needs_copy = True
58
58
self .use_row_factory = True
59
- try :
60
- connect ()
61
- self .needs_copy = False
62
- except apsw .IOError :
63
- debug_print (f'Kobo: I/O error connecting to { self .path_on_device } copying it into temporary storage and connecting there' )
64
- with open (self .path_on_device , 'rb' ) as src , PersistentTemporaryFile (suffix = '-kobo-db.sqlite' ) as dest :
65
- shutil .copyfileobj (src , dest )
66
- wal = self .path_on_device + '-wal'
67
- if os .path .exists (wal ):
68
- shutil .copy2 (wal , dest .name + '-wal' )
59
+ with kobo_db_lock :
69
60
try :
70
- connect (dest .name )
71
- except Exception :
72
- os .remove (dest .name )
73
- raise
61
+ connect ()
62
+ self .needs_copy = False
63
+ except apsw .IOError :
64
+ debug_print (f'Kobo: I/O error connecting to { self .path_on_device } copying it into temporary storage and connecting there' )
65
+ with open (self .path_on_device , 'rb' ) as src , PersistentTemporaryFile (suffix = '-kobo-db.sqlite' ) as dest :
66
+ shutil .copyfileobj (src , dest )
67
+ wal = self .path_on_device + '-wal'
68
+ if os .path .exists (wal ):
69
+ shutil .copy2 (wal , dest .name + '-wal' )
70
+ try :
71
+ connect (dest .name )
72
+ except Exception :
73
+ os .remove (dest .name )
74
+ raise
74
75
75
76
def __enter__ (self ) -> apsw .Connection :
76
77
kobo_db_lock .acquire ()
You can’t perform that action at this time.
0 commit comments