Skip to content

Commit db356ed

Browse files
authored
Merge pull request #12 from fallending/master
Supported duplicated db filenames in different dirs
2 parents b68105e + 91b63c5 commit db356ed

4 files changed

Lines changed: 41 additions & 40 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

YYDebugDatabase.xcodeproj/project.pbxproj

Lines changed: 9 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
5829F841247D38DE00D5EAD3 /* module2 in Resources */ = {isa = PBXBuildFile; fileRef = 5829F83F247D38DE00D5EAD3 /* module2 */; };
11+
5829F842247D38DE00D5EAD3 /* module1 in Resources */ = {isa = PBXBuildFile; fileRef = 5829F840247D38DE00D5EAD3 /* module1 */; };
1012
89CC7B5231AD8E77CEC10949 /* libPods-YYDebugDatabase.a in Frameworks */ = {isa = PBXBuildFile; fileRef = F79B17EACE993F42581F0F1C /* libPods-YYDebugDatabase.a */; };
1113
8A6C34EC1FE5175100C44E61 /* DebugDatabaseManager.m in Sources */ = {isa = PBXBuildFile; fileRef = E84AE6331F3C4210003A9EB7 /* DebugDatabaseManager.m */; };
1214
8A6C34ED1FE5175400C44E61 /* DatabaseUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = E84AE6431F3D9F8F003A9EB7 /* DatabaseUtil.m */; };
@@ -46,6 +48,8 @@
4648
/* Begin PBXFileReference section */
4749
22ADD98E9993641841D67B7F /* Pods-YYDebugDatabase.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-YYDebugDatabase.debug.xcconfig"; path = "Pods/Target Support Files/Pods-YYDebugDatabase/Pods-YYDebugDatabase.debug.xcconfig"; sourceTree = "<group>"; };
4850
50D992B943B292D10D75C6C2 /* Pods-YYDebugDatabase.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-YYDebugDatabase.release.xcconfig"; path = "Pods/Target Support Files/Pods-YYDebugDatabase/Pods-YYDebugDatabase.release.xcconfig"; sourceTree = "<group>"; };
51+
5829F83F247D38DE00D5EAD3 /* module2 */ = {isa = PBXFileReference; lastKnownFileType = folder; path = module2; sourceTree = "<group>"; };
52+
5829F840247D38DE00D5EAD3 /* module1 */ = {isa = PBXFileReference; lastKnownFileType = folder; path = module1; sourceTree = "<group>"; };
4953
8A6C34DF1FE516EF00C44E61 /* iOSDebugDatabase.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = iOSDebugDatabase.framework; sourceTree = BUILT_PRODUCTS_DIR; };
5054
8A6C34E11FE516EF00C44E61 /* iOSDebugDatabase.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = iOSDebugDatabase.h; sourceTree = "<group>"; };
5155
8A6C34E21FE516EF00C44E61 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
@@ -149,6 +153,8 @@
149153
E84AE5ED1F3ADDE3003A9EB7 /* YYDebugDatabase */ = {
150154
isa = PBXGroup;
151155
children = (
156+
5829F840247D38DE00D5EAD3 /* module1 */,
157+
5829F83F247D38DE00D5EAD3 /* module2 */,
152158
E84AE63E1F3D8843003A9EB7 /* Car.db */,
153159
E84AE63F1F3D8843003A9EB7 /* Contact.db */,
154160
E84AE5F11F3ADDE3003A9EB7 /* AppDelegate.h */,
@@ -240,8 +246,6 @@
240246
E84AE5E71F3ADDE3003A9EB7 /* Sources */,
241247
E84AE5E81F3ADDE3003A9EB7 /* Frameworks */,
242248
E84AE5E91F3ADDE3003A9EB7 /* Resources */,
243-
9FB2B373BADC92DF69E0334D /* [CP] Embed Pods Frameworks */,
244-
8B25CAB7D4215B4952552A3B /* [CP] Copy Pods Resources */,
245249
);
246250
buildRules = (
247251
);
@@ -278,6 +282,7 @@
278282
developmentRegion = English;
279283
hasScannedForEncodings = 0;
280284
knownRegions = (
285+
English,
281286
en,
282287
Base,
283288
);
@@ -308,49 +313,18 @@
308313
E8E069C91F40954500477064 /* Web.bundle in Resources */,
309314
E84AE6401F3D9BEF003A9EB7 /* Car.db in Resources */,
310315
E84AE6411F3D9BEF003A9EB7 /* Contact.db in Resources */,
316+
5829F842247D38DE00D5EAD3 /* module1 in Resources */,
311317
E84AE5FE1F3ADDE3003A9EB7 /* LaunchScreen.storyboard in Resources */,
312318
E84AE5FB1F3ADDE3003A9EB7 /* Assets.xcassets in Resources */,
313319
E834DAAC22DC5A6400FAC2C1 /* YYDebugDatabase.podspec in Resources */,
314320
E84AE5F91F3ADDE3003A9EB7 /* Main.storyboard in Resources */,
321+
5829F841247D38DE00D5EAD3 /* module2 in Resources */,
315322
);
316323
runOnlyForDeploymentPostprocessing = 0;
317324
};
318325
/* End PBXResourcesBuildPhase section */
319326

320327
/* Begin PBXShellScriptBuildPhase section */
321-
8B25CAB7D4215B4952552A3B /* [CP] Copy Pods Resources */ = {
322-
isa = PBXShellScriptBuildPhase;
323-
buildActionMask = 2147483647;
324-
files = (
325-
);
326-
inputPaths = (
327-
"${SRCROOT}/Pods/Target Support Files/Pods-YYDebugDatabase/Pods-YYDebugDatabase-resources.sh",
328-
"${PODS_ROOT}/GCDWebServer/GCDWebUploader/GCDWebUploader.bundle",
329-
);
330-
name = "[CP] Copy Pods Resources";
331-
outputPaths = (
332-
"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}",
333-
);
334-
runOnlyForDeploymentPostprocessing = 0;
335-
shellPath = /bin/sh;
336-
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-YYDebugDatabase/Pods-YYDebugDatabase-resources.sh\"\n";
337-
showEnvVarsInLog = 0;
338-
};
339-
9FB2B373BADC92DF69E0334D /* [CP] Embed Pods Frameworks */ = {
340-
isa = PBXShellScriptBuildPhase;
341-
buildActionMask = 2147483647;
342-
files = (
343-
);
344-
inputPaths = (
345-
);
346-
name = "[CP] Embed Pods Frameworks";
347-
outputPaths = (
348-
);
349-
runOnlyForDeploymentPostprocessing = 0;
350-
shellPath = /bin/sh;
351-
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-YYDebugDatabase/Pods-YYDebugDatabase-frameworks.sh\"\n";
352-
showEnvVarsInLog = 0;
353-
};
354328
AC614CD6DFA5E640A919CE47 /* [CP] Check Pods Manifest.lock */ = {
355329
isa = PBXShellScriptBuildPhase;
356330
buildActionMask = 2147483647;

YYDebugDatabase/module1/Car.db

16 KB
Binary file not shown.

YYDebugDatabase/module2/Car.db

16 KB
Binary file not shown.

0 commit comments

Comments
 (0)