Skip to content

Commit 5cfcf4a

Browse files
committed
feat: support several duplicated db filenames in different dirs. web db list look as: module1/Car.db, module2/Car.db
1 parent b68105e commit 5cfcf4a

1 file changed

Lines changed: 32 additions & 5 deletions

File tree

DebugDatabase/DebugDatabaseManager.m

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,32 +227,59 @@ - (NSDictionary*)getAllDBPathsWithDirectories:(NSArray*)directories {
227227
NSMutableDictionary *paths = @{}.mutableCopy;
228228

229229
for (NSString *directory in directories) {
230-
NSArray *dirList = [[[NSFileManager defaultManager] subpathsAtPath:directory] pathsMatchingExtensions:[self databaseSuffixs]];
230+
NSArray *dirList = [[[NSFileManager defaultManager] subpathsAtPath:directory] pathsMatchingExtensions:[self supportedDatabaseSuffixs]];
231231

232232
for (NSString *subPath in dirList) {
233233
if ([self checkDatabaseFile:subPath]) {
234-
[paths setObject:[directory stringByAppendingPathComponent:subPath] forKey:subPath.lastPathComponent];
234+
// [paths setObject:[directory stringByAppendingPathComponent:subPath] forKey:subPath.lastPathComponent];
235+
236+
// added by seven
237+
[self addToDbQueryPathesSupportDuplicatedFilename:paths
238+
object:[directory stringByAppendingPathComponent:subPath]
239+
key:subPath.lastPathComponent];
235240
}
236241
}
237242

238243
if ([self checkDatabaseFile:directory]) {
239-
[paths setObject:directory forKey:directory.lastPathComponent];
244+
// [paths setObject:directory forKey:directory.lastPathComponent];
245+
246+
// added by seven
247+
[self addToDbQueryPathesSupportDuplicatedFilename:paths
248+
object:directory
249+
key:directory.lastPathComponent];
240250
}
241251
}
242252

243253
return paths;
244254
}
245255

256+
// added by seven
257+
- (void)addToDbQueryPathesSupportDuplicatedFilename:(NSMutableDictionary *)paths object:(NSString *)dbPath key:(NSString *)dbKeyName {
258+
// Key exists, appending the last directory path component
259+
if ([paths objectForKey:dbKeyName]) {
260+
NSString *dbDir = [dbPath stringByDeletingLastPathComponent];
261+
NSArray *dbDirPathComponents = [dbDir componentsSeparatedByString:@"/"];
262+
263+
NSString *lastPathComponent = [dbDirPathComponents lastObject];
264+
265+
if (lastPathComponent && lastPathComponent.length) {
266+
dbKeyName = [NSString stringWithFormat:@"%@/%@", lastPathComponent, dbKeyName];
267+
}
268+
}
269+
270+
[paths setObject:dbPath forKey:dbKeyName];
271+
}
272+
246273
- (BOOL)checkDatabaseFile:(NSString*)fileName {
247-
for (NSString *suffix in [self databaseSuffixs]) {
274+
for (NSString *suffix in [self supportedDatabaseSuffixs]) {
248275
if ([fileName hasSuffix:suffix]) {
249276
return YES;
250277
}
251278
}
252279
return NO;
253280
}
254281

255-
- (NSArray*)databaseSuffixs {
282+
- (NSArray*)supportedDatabaseSuffixs {
256283
return @[@"sqlite", @"SQLITE", @"db", @"DB", @"sqlite3", @"SQLITE3"];
257284
}
258285

0 commit comments

Comments
 (0)