@@ -158,28 +158,49 @@ - (void)setDBPath:(NSString *)filePath
158
158
if (self.bindingQueue && [self .dbPath isEqualToString: filePath]) {
159
159
return ;
160
160
}
161
-
161
+ NSFileManager * fileManager = [ NSFileManager defaultManager ];
162
162
// 创建数据库目录
163
163
NSRange lastComponent = [filePath rangeOfString: @" /" options: NSBackwardsSearch];
164
164
165
165
if (lastComponent.length > 0 ) {
166
166
NSString *dirPath = [filePath substringToIndex: lastComponent.location];
167
167
BOOL isDir = NO ;
168
- BOOL isCreated = [[ NSFileManager defaultManager ] fileExistsAtPath: dirPath isDirectory: &isDir];
168
+ BOOL isCreated = [fileManager fileExistsAtPath: dirPath isDirectory: &isDir];
169
169
170
170
if ((isCreated == NO ) || (isDir == NO )) {
171
171
NSError *error = nil ;
172
- BOOL success = [[NSFileManager defaultManager ] createDirectoryAtPath: dirPath withIntermediateDirectories: YES attributes: nil error: &error];
172
+ BOOL success = [fileManager createDirectoryAtPath: dirPath withIntermediateDirectories: YES
173
+ attributes: @{NSFileProtectionKey :NSFileProtectionNone } error: &error];
173
174
174
175
if (success == NO ) {
175
- NSLog (@" create dir error: %@ " , error.debugDescription );
176
+ LKErrorLog (@" create dir error: %@ " , error.debugDescription );
176
177
}
177
178
}
179
+ else
180
+ {
181
+ /* *
182
+ * @brief Disk I/O error when device is locked
183
+ * https://github.com/ccgus/fmdb/issues/262
184
+ */
185
+ [fileManager setAttributes: @{NSFileProtectionKey :NSFileProtectionNone } ofItemAtPath: dirPath error: nil ];
186
+ }
178
187
}
179
-
188
+
180
189
self.dbPath = filePath;
181
190
[self .bindingQueue close ];
182
- self.bindingQueue = [[FMDatabaseQueue alloc ]initWithPath:filePath];
191
+
192
+ #ifndef SQLITE_OPEN_FILEPROTECTION_NONE
193
+ #define SQLITE_OPEN_FILEPROTECTION_NONE 0x00400000
194
+ #endif
195
+
196
+ self.bindingQueue = [[FMDatabaseQueue alloc ]initWithPath:filePath
197
+ flags: SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FILEPROTECTION_NONE];
198
+
199
+ if ([fileManager fileExistsAtPath: filePath])
200
+ {
201
+ [fileManager setAttributes: @{NSFileProtectionKey :NSFileProtectionNone } ofItemAtPath: filePath error: nil ];
202
+ }
203
+
183
204
_encryptionKey = nil ;
184
205
185
206
#ifdef DEBUG
0 commit comments