From 5cfcf4a9e1797437117476eb44b3ed7b4e376438 Mon Sep 17 00:00:00 2001 From: seven Date: Tue, 26 May 2020 20:05:36 +0800 Subject: [PATCH 1/2] feat: support several duplicated db filenames in different dirs. web db list look as: module1/Car.db, module2/Car.db --- DebugDatabase/DebugDatabaseManager.m | 37 ++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/DebugDatabase/DebugDatabaseManager.m b/DebugDatabase/DebugDatabaseManager.m index 523681f..ae6271d 100644 --- a/DebugDatabase/DebugDatabaseManager.m +++ b/DebugDatabase/DebugDatabaseManager.m @@ -227,24 +227,51 @@ - (NSDictionary*)getAllDBPathsWithDirectories:(NSArray*)directories { NSMutableDictionary *paths = @{}.mutableCopy; for (NSString *directory in directories) { - NSArray *dirList = [[[NSFileManager defaultManager] subpathsAtPath:directory] pathsMatchingExtensions:[self databaseSuffixs]]; + NSArray *dirList = [[[NSFileManager defaultManager] subpathsAtPath:directory] pathsMatchingExtensions:[self supportedDatabaseSuffixs]]; for (NSString *subPath in dirList) { if ([self checkDatabaseFile:subPath]) { - [paths setObject:[directory stringByAppendingPathComponent:subPath] forKey:subPath.lastPathComponent]; +// [paths setObject:[directory stringByAppendingPathComponent:subPath] forKey:subPath.lastPathComponent]; + + // added by seven + [self addToDbQueryPathesSupportDuplicatedFilename:paths + object:[directory stringByAppendingPathComponent:subPath] + key:subPath.lastPathComponent]; } } if ([self checkDatabaseFile:directory]) { - [paths setObject:directory forKey:directory.lastPathComponent]; +// [paths setObject:directory forKey:directory.lastPathComponent]; + + // added by seven + [self addToDbQueryPathesSupportDuplicatedFilename:paths + object:directory + key:directory.lastPathComponent]; } } return paths; } +// added by seven +- (void)addToDbQueryPathesSupportDuplicatedFilename:(NSMutableDictionary *)paths object:(NSString *)dbPath key:(NSString *)dbKeyName { + // Key exists, appending the last directory path component + if ([paths objectForKey:dbKeyName]) { + NSString *dbDir = [dbPath stringByDeletingLastPathComponent]; + NSArray *dbDirPathComponents = [dbDir componentsSeparatedByString:@"/"]; + + NSString *lastPathComponent = [dbDirPathComponents lastObject]; + + if (lastPathComponent && lastPathComponent.length) { + dbKeyName = [NSString stringWithFormat:@"%@/%@", lastPathComponent, dbKeyName]; + } + } + + [paths setObject:dbPath forKey:dbKeyName]; +} + - (BOOL)checkDatabaseFile:(NSString*)fileName { - for (NSString *suffix in [self databaseSuffixs]) { + for (NSString *suffix in [self supportedDatabaseSuffixs]) { if ([fileName hasSuffix:suffix]) { return YES; } @@ -252,7 +279,7 @@ - (BOOL)checkDatabaseFile:(NSString*)fileName { return NO; } -- (NSArray*)databaseSuffixs { +- (NSArray*)supportedDatabaseSuffixs { return @[@"sqlite", @"SQLITE", @"db", @"DB", @"sqlite3", @"SQLITE3"]; } From 91b63c56b77b19348daae39f007fc8b3601bc2ba Mon Sep 17 00:00:00 2001 From: seven Date: Tue, 26 May 2020 20:06:39 +0800 Subject: [PATCH 2/2] example feat: supported duplicated db filenames in different dirs. --- YYDebugDatabase.xcodeproj/project.pbxproj | 44 +++++----------------- YYDebugDatabase/module1/Car.db | Bin 0 -> 16384 bytes YYDebugDatabase/module2/Car.db | Bin 0 -> 16384 bytes 3 files changed, 9 insertions(+), 35 deletions(-) create mode 100644 YYDebugDatabase/module1/Car.db create mode 100644 YYDebugDatabase/module2/Car.db diff --git a/YYDebugDatabase.xcodeproj/project.pbxproj b/YYDebugDatabase.xcodeproj/project.pbxproj index d3af203..6b080a9 100644 --- a/YYDebugDatabase.xcodeproj/project.pbxproj +++ b/YYDebugDatabase.xcodeproj/project.pbxproj @@ -7,6 +7,8 @@ objects = { /* Begin PBXBuildFile section */ + 5829F841247D38DE00D5EAD3 /* module2 in Resources */ = {isa = PBXBuildFile; fileRef = 5829F83F247D38DE00D5EAD3 /* module2 */; }; + 5829F842247D38DE00D5EAD3 /* module1 in Resources */ = {isa = PBXBuildFile; fileRef = 5829F840247D38DE00D5EAD3 /* module1 */; }; 89CC7B5231AD8E77CEC10949 /* libPods-YYDebugDatabase.a in Frameworks */ = {isa = PBXBuildFile; fileRef = F79B17EACE993F42581F0F1C /* libPods-YYDebugDatabase.a */; }; 8A6C34EC1FE5175100C44E61 /* DebugDatabaseManager.m in Sources */ = {isa = PBXBuildFile; fileRef = E84AE6331F3C4210003A9EB7 /* DebugDatabaseManager.m */; }; 8A6C34ED1FE5175400C44E61 /* DatabaseUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = E84AE6431F3D9F8F003A9EB7 /* DatabaseUtil.m */; }; @@ -46,6 +48,8 @@ /* Begin PBXFileReference section */ 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 = ""; }; 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 = ""; }; + 5829F83F247D38DE00D5EAD3 /* module2 */ = {isa = PBXFileReference; lastKnownFileType = folder; path = module2; sourceTree = ""; }; + 5829F840247D38DE00D5EAD3 /* module1 */ = {isa = PBXFileReference; lastKnownFileType = folder; path = module1; sourceTree = ""; }; 8A6C34DF1FE516EF00C44E61 /* iOSDebugDatabase.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = iOSDebugDatabase.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 8A6C34E11FE516EF00C44E61 /* iOSDebugDatabase.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = iOSDebugDatabase.h; sourceTree = ""; }; 8A6C34E21FE516EF00C44E61 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; @@ -149,6 +153,8 @@ E84AE5ED1F3ADDE3003A9EB7 /* YYDebugDatabase */ = { isa = PBXGroup; children = ( + 5829F840247D38DE00D5EAD3 /* module1 */, + 5829F83F247D38DE00D5EAD3 /* module2 */, E84AE63E1F3D8843003A9EB7 /* Car.db */, E84AE63F1F3D8843003A9EB7 /* Contact.db */, E84AE5F11F3ADDE3003A9EB7 /* AppDelegate.h */, @@ -240,8 +246,6 @@ E84AE5E71F3ADDE3003A9EB7 /* Sources */, E84AE5E81F3ADDE3003A9EB7 /* Frameworks */, E84AE5E91F3ADDE3003A9EB7 /* Resources */, - 9FB2B373BADC92DF69E0334D /* [CP] Embed Pods Frameworks */, - 8B25CAB7D4215B4952552A3B /* [CP] Copy Pods Resources */, ); buildRules = ( ); @@ -278,6 +282,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, Base, ); @@ -308,49 +313,18 @@ E8E069C91F40954500477064 /* Web.bundle in Resources */, E84AE6401F3D9BEF003A9EB7 /* Car.db in Resources */, E84AE6411F3D9BEF003A9EB7 /* Contact.db in Resources */, + 5829F842247D38DE00D5EAD3 /* module1 in Resources */, E84AE5FE1F3ADDE3003A9EB7 /* LaunchScreen.storyboard in Resources */, E84AE5FB1F3ADDE3003A9EB7 /* Assets.xcassets in Resources */, E834DAAC22DC5A6400FAC2C1 /* YYDebugDatabase.podspec in Resources */, E84AE5F91F3ADDE3003A9EB7 /* Main.storyboard in Resources */, + 5829F841247D38DE00D5EAD3 /* module2 in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ - 8B25CAB7D4215B4952552A3B /* [CP] Copy Pods Resources */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - "${SRCROOT}/Pods/Target Support Files/Pods-YYDebugDatabase/Pods-YYDebugDatabase-resources.sh", - "${PODS_ROOT}/GCDWebServer/GCDWebUploader/GCDWebUploader.bundle", - ); - name = "[CP] Copy Pods Resources"; - outputPaths = ( - "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}", - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-YYDebugDatabase/Pods-YYDebugDatabase-resources.sh\"\n"; - showEnvVarsInLog = 0; - }; - 9FB2B373BADC92DF69E0334D /* [CP] Embed Pods Frameworks */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - ); - name = "[CP] Embed Pods Frameworks"; - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-YYDebugDatabase/Pods-YYDebugDatabase-frameworks.sh\"\n"; - showEnvVarsInLog = 0; - }; AC614CD6DFA5E640A919CE47 /* [CP] Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; diff --git a/YYDebugDatabase/module1/Car.db b/YYDebugDatabase/module1/Car.db new file mode 100644 index 0000000000000000000000000000000000000000..49e9153886c2aa88675c024a6efb5d3d78c3ca55 GIT binary patch literal 16384 zcmeI3Jxmi}7{~7lSnoZ(tcwTsdQ_}fWm{D3ht;UaS4tHJ_shkSZ7tivv8__iZTV2RzhBP7 zomeXcr&25|mhGxlu&UPH_h;ay{OMc=#m0AKmj~W&>=14X^<= zzy{a=8(;%$fDNz#Hoyk{%YgUYylm`9?u9otzy{a=8(;%$fDNz#Hoykh02^QfY~WxS z2+D!*#{I?YoMwEN5{fPYHtr0?io^!NH}{kguOTl$PXsE4#) z+E?v^_D0*(9%;+koHnd=Xm#oj^^>}-zEGd2Wi_X!)K0Zg`Kf$X-YGAYXUdv#N69FW zgQbw$umLu}2G{@_U;}J`4eWmdt#X6Z77lv9$X$$0&zt64y6fB0UH9*+;Y5Sf-drO? zObik*0ss>O1PpuNIwtxF7y^KaC;>?iT*E{k z0SN$@=p`WTfvcG4As_|-6A>RIq4^9Z&JzI5XE4!C05qS*#5n?>`7|cF2!Q5Om^e!S zG@rsmCjrph#Kai_pt*?&K>#$L#KdU=p!p;wPWd1K&9j&|NdPp@VxofpXg-07b^@UJ z1SU=p0L?R)Xd?icXE4!905nfyB1`}@Ph%oP05rd{mP~uE-4+6%`DFyheGrG{mk=}) z0L?EVI7R?8Pa!x;05rdVposuzK90a30Gf{>&lfyj6fj(nh(`L z=!km;!1p;6PvX4MpF{5i&JX)@s2#_7(4Rx=7|sv*b0|Fk=NBo|;Lo9R6zBE+94hzX Zyw0CP;|R_J{u~N-*XHiC-RiEtw%>5ye?9;J literal 0 HcmV?d00001 diff --git a/YYDebugDatabase/module2/Car.db b/YYDebugDatabase/module2/Car.db new file mode 100644 index 0000000000000000000000000000000000000000..49e9153886c2aa88675c024a6efb5d3d78c3ca55 GIT binary patch literal 16384 zcmeI3Jxmi}7{~7lSnoZ(tcwTsdQ_}fWm{D3ht;UaS4tHJ_shkSZ7tivv8__iZTV2RzhBP7 zomeXcr&25|mhGxlu&UPH_h;ay{OMc=#m0AKmj~W&>=14X^<= zzy{a=8(;%$fDNz#Hoyk{%YgUYylm`9?u9otzy{a=8(;%$fDNz#Hoykh02^QfY~WxS z2+D!*#{I?YoMwEN5{fPYHtr0?io^!NH}{kguOTl$PXsE4#) z+E?v^_D0*(9%;+koHnd=Xm#oj^^>}-zEGd2Wi_X!)K0Zg`Kf$X-YGAYXUdv#N69FW zgQbw$umLu}2G{@_U;}J`4eWmdt#X6Z77lv9$X$$0&zt64y6fB0UH9*+;Y5Sf-drO? zObik*0ss>O1PpuNIwtxF7y^KaC;>?iT*E{k z0SN$@=p`WTfvcG4As_|-6A>RIq4^9Z&JzI5XE4!C05qS*#5n?>`7|cF2!Q5Om^e!S zG@rsmCjrph#Kai_pt*?&K>#$L#KdU=p!p;wPWd1K&9j&|NdPp@VxofpXg-07b^@UJ z1SU=p0L?R)Xd?icXE4!905nfyB1`}@Ph%oP05rd{mP~uE-4+6%`DFyheGrG{mk=}) z0L?EVI7R?8Pa!x;05rdVposuzK90a30Gf{>&lfyj6fj(nh(`L z=!km;!1p;6PvX4MpF{5i&JX)@s2#_7(4Rx=7|sv*b0|Fk=NBo|;Lo9R6zBE+94hzX Zyw0CP;|R_J{u~N-*XHiC-RiEtw%>5ye?9;J literal 0 HcmV?d00001