Skip to content

Commit b6ac437

Browse files
Remove migration logic from document folder to application folder (#4033)
1 parent af730a9 commit b6ac437

11 files changed

+68
-271
lines changed

Example/InstanceID/Tests/FIRInstanceIDBackupExcludedPlistTest.m

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -79,48 +79,6 @@ - (void)testWriteToPlistInApplicationSupportFolder {
7979
XCTAssertTrue([self doesPlistFileExist]);
8080
}
8181

82-
- (void)testMovePlistToApplicationSupportDirectorySuccess {
83-
NSDictionary *plistContents = @{@"hello" : @"world", @"id" : @123};
84-
[self.plist writeDictionary:plistContents error:nil];
85-
[self.plist moveToApplicationSupportSubDirectory:kSubDirectoryName];
86-
XCTAssertTrue([self doesPlistFileExist]);
87-
XCTAssertFalse([self isPlistInDocumentsDirectory]);
88-
89-
NSDictionary *newPlistContents = @{@"world" : @"hello"};
90-
[self.plist writeDictionary:newPlistContents error:nil];
91-
XCTAssertEqualObjects(newPlistContents, [self.plist contentAsDictionary]);
92-
}
93-
94-
- (void)testMovePlistToApplicationSupportDirectoryFailure {
95-
// This is to test moving data from deprecated document folder to application folder
96-
// which should only apply to iOS.
97-
#if TARGET_OS_IOS
98-
// Delete the subdirectory
99-
[FIRInstanceIDStore removeSubDirectory:kSubDirectoryName error:nil];
100-
101-
// Create a new plistl This would try to move or write to the ApplicationSupport directory
102-
// but since the subdirectory is not there anymore it will fail and rather write to the
103-
// Documents folder.
104-
self.plist = [[FIRInstanceIDBackupExcludedPlist alloc] initWithFileName:kTestPlistFileName
105-
subDirectory:kSubDirectoryName];
106-
107-
NSDictionary *plistContents = @{@"hello" : @"world", @"id" : @123};
108-
[self.plist writeDictionary:plistContents error:nil];
109-
110-
XCTAssertFalse([self doesPlistFileExist]);
111-
XCTAssertTrue([self isPlistInDocumentsDirectory]);
112-
113-
NSDictionary *newPlistContents = @{@"world" : @"hello"};
114-
[self.plist writeDictionary:newPlistContents error:nil];
115-
116-
XCTAssertEqualObjects(newPlistContents, [self.plist contentAsDictionary]);
117-
118-
// The new file should still be written to the Documents folder.
119-
XCTAssertFalse([self doesPlistFileExist]);
120-
XCTAssertTrue([self isPlistInDocumentsDirectory]);
121-
#endif
122-
}
123-
12482
#pragma mark - Private Helpers
12583

12684
- (BOOL)doesPlistFileExist {

Example/Messaging/Tests/FIRMessagingDataMessageManagerTest.m

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#import "Firebase/Messaging/FIRMessagingClient.h"
2323
#import "Firebase/Messaging/FIRMessagingConnection.h"
2424
#import "Firebase/Messaging/FIRMessagingDataMessageManager.h"
25+
#import "Firebase/Messaging/FIRMessagingRmq2PersistentStore.h"
2526
#import "Firebase/Messaging/FIRMessagingReceiver.h"
2627
#import "Firebase/Messaging/FIRMessagingRmqManager.h"
2728
#import "Firebase/Messaging/FIRMessagingSyncMessageManager.h"
@@ -50,6 +51,18 @@ - (NSString *)categoryForUpstreamMessages;
5051

5152
@end
5253

54+
@interface FIRMessagingRmqManager (ExposedForTest)
55+
56+
@property(nonatomic, readwrite, strong) FIRMessagingRmq2PersistentStore *rmq2Store;
57+
58+
@end
59+
60+
@interface FIRMessagingRmq2PersistentStore (ExposedForTest)
61+
62+
- (void)removeDatabase;
63+
64+
@end
65+
5366
@interface FIRMessagingDataMessageManagerTest : XCTestCase
5467

5568
@property(nonatomic, readwrite, strong) id mockClient;
@@ -78,6 +91,12 @@ - (void)setUp {
7891
_mockDataMessageManager = OCMPartialMock(_dataMessageManager);
7992
}
8093

94+
-(void)tearDown {
95+
if (_dataMessageManager.rmq2Manager) {
96+
[_dataMessageManager.rmq2Manager.rmq2Store removeDatabase];
97+
}
98+
[super tearDown];
99+
}
81100

82101
- (void)testSendValidMessage_withNoConnection {
83102
// mock no connection initially
@@ -477,7 +496,6 @@ - (void)testResendSavedMessages {
477496
// Set a fake, valid bundle identifier
478497
[[[self.mockDataMessageManager stub] andReturn:@"gcm-dmm-test"] categoryForUpstreamMessages];
479498

480-
[FIRMessagingRmqManager removeDatabaseWithName:kRmqDatabaseName];
481499
FIRMessagingRmqManager *newRmqManager =
482500
[[FIRMessagingRmqManager alloc] initWithDatabaseName:kRmqDatabaseName];
483501
[newRmqManager loadRmqId];
@@ -535,7 +553,6 @@ - (void)testResendingExpiredMessagesFails {
535553
// Set a fake, valid bundle identifier
536554
[[[self.mockDataMessageManager stub] andReturn:@"gcm-dmm-test"] categoryForUpstreamMessages];
537555

538-
[FIRMessagingRmqManager removeDatabaseWithName:kRmqDatabaseName];
539556
FIRMessagingRmqManager *newRmqManager =
540557
[[FIRMessagingRmqManager alloc] initWithDatabaseName:kRmqDatabaseName];
541558
[newRmqManager loadRmqId];

Example/Messaging/Tests/FIRMessagingRmqManagerTest.m

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,24 @@
1919
#import "Firebase/Messaging/FIRMessagingPersistentSyncMessage.h"
2020
#import "Firebase/Messaging/FIRMessagingRmqManager.h"
2121
#import "Firebase/Messaging/FIRMessagingUtilities.h"
22+
#import "Firebase/Messaging/FIRMessagingRmq2PersistentStore.h"
2223
#import "Firebase/Messaging/Protos/GtalkCore.pbobjc.h"
2324

2425
static NSString *const kRmqDatabaseName = @"rmq-test-db";
2526
static NSString *const kRmqDataMessageCategory = @"com.google.gcm-rmq-test";
2627

28+
@interface FIRMessagingRmqManager (ExposedForTest)
29+
30+
@property(nonatomic, readwrite, strong) FIRMessagingRmq2PersistentStore *rmq2Store;
31+
32+
@end
33+
34+
@interface FIRMessagingRmq2PersistentStore (ExposedForTest)
35+
36+
- (void)removeDatabase;
37+
38+
@end
39+
2740
@interface FIRMessagingRmqManagerTest : XCTestCase
2841

2942
@property(nonatomic, readwrite, strong) FIRMessagingRmqManager *rmqManager;
@@ -35,13 +48,13 @@ @implementation FIRMessagingRmqManagerTest
3548
- (void)setUp {
3649
[super setUp];
3750
// Make sure we start off with a clean state each time
38-
[FIRMessagingRmqManager removeDatabaseWithName:kRmqDatabaseName];
3951
_rmqManager = [[FIRMessagingRmqManager alloc] initWithDatabaseName:kRmqDatabaseName];
52+
4053
}
4154

4255
- (void)tearDown {
56+
[self.rmqManager.rmq2Store removeDatabase];
4357
[super tearDown];
44-
[FIRMessagingRmqManager removeDatabaseWithName:kRmqDatabaseName];
4558
}
4659

4760
/**

Example/Messaging/Tests/FIRMessagingSyncMessageManagerTest.m

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,26 @@
1717
#import <XCTest/XCTest.h>
1818

1919
#import "Firebase/Messaging/FIRMessagingPersistentSyncMessage.h"
20+
#import "Firebase/Messaging/FIRMessagingRmq2PersistentStore.h"
2021
#import "Firebase/Messaging/FIRMessagingRmqManager.h"
2122
#import "Firebase/Messaging/FIRMessagingSyncMessageManager.h"
2223
#import "Firebase/Messaging/FIRMessagingUtilities.h"
2324
#import "Firebase/Messaging/FIRMessagingConstants.h"
2425

2526
static NSString *const kRmqSqliteFilename = @"rmq-sync-manager-test";
2627

28+
@interface FIRMessagingRmqManager (ExposedForTest)
29+
30+
@property(nonatomic, readwrite, strong) FIRMessagingRmq2PersistentStore *rmq2Store;
31+
32+
@end
33+
34+
@interface FIRMessagingRmq2PersistentStore (ExposedForTest)
35+
36+
- (void)removeDatabase;
37+
38+
@end
39+
2740
@interface FIRMessagingSyncMessageManagerTest : XCTestCase
2841

2942
@property(nonatomic, readwrite, strong) FIRMessagingRmqManager *rmqManager;
@@ -36,13 +49,12 @@ @implementation FIRMessagingSyncMessageManagerTest
3649
- (void)setUp {
3750
[super setUp];
3851
// Make sure the db state is clean before we begin.
39-
[FIRMessagingRmqManager removeDatabaseWithName:kRmqSqliteFilename];
4052
self.rmqManager = [[FIRMessagingRmqManager alloc] initWithDatabaseName:kRmqSqliteFilename];
4153
self.syncMessageManager = [[FIRMessagingSyncMessageManager alloc] initWithRmqManager:self.rmqManager];
4254
}
4355

4456
- (void)tearDown {
45-
[[self.rmqManager class] removeDatabaseWithName:kRmqSqliteFilename];
57+
[self.rmqManager.rmq2Store removeDatabase];
4658
[super tearDown];
4759
}
4860

Firebase/InstanceID/FIRIMessageCode.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ typedef NS_ENUM(NSInteger, FIRInstanceIDMessageCode) {
5555
kFIRInstanceIDMessageCodeAuthServiceCheckinInProgress = 5004,
5656

5757
// FIRInstanceIDBackupExcludedPlist.m
58+
// Do NOT USE 6003
5859
kFIRInstanceIDMessageCodeBackupExcludedPlist000 = 6000,
5960
kFIRInstanceIDMessageCodeBackupExcludedPlist001 = 6001,
6061
kFIRInstanceIDMessageCodeBackupExcludedPlist002 = 6002,
61-
kFIRInstanceIDMessageCodeBackupExcludedPlistInvalidPlistEnum = 6003,
6262
// FIRInstanceIDCheckinService.m
6363
kFIRInstanceIDMessageCodeService000 = 7000,
6464
kFIRInstanceIDMessageCodeService001 = 7001,

Firebase/InstanceID/FIRInstanceIDBackupExcludedPlist.m

Lines changed: 10 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,10 @@
1818

1919
#import "FIRInstanceIDLogger.h"
2020

21-
typedef enum : NSUInteger {
22-
FIRInstanceIDPlistDirectoryUnknown,
23-
FIRInstanceIDPlistDirectoryDocuments,
24-
FIRInstanceIDPlistDirectoryApplicationSupport,
25-
} FIRInstanceIDPlistDirectory;
26-
2721
@interface FIRInstanceIDBackupExcludedPlist ()
2822

2923
@property(nonatomic, readwrite, copy) NSString *fileName;
3024
@property(nonatomic, readwrite, copy) NSString *subDirectoryName;
31-
@property(nonatomic, readwrite, assign) BOOL fileInStandardDirectory;
32-
3325
@property(nonatomic, readwrite, strong) NSDictionary *cachedPlistContents;
3426

3527
@end
@@ -41,19 +33,12 @@ - (instancetype)initWithFileName:(NSString *)fileName subDirectory:(NSString *)s
4133
if (self) {
4234
_fileName = [fileName copy];
4335
_subDirectoryName = [subDirectory copy];
44-
#if TARGET_OS_IOS
45-
_fileInStandardDirectory = [self moveToApplicationSupportSubDirectory:subDirectory];
46-
#else
47-
// For tvOS and macOS, we never store the content in document folder, so
48-
// the migration is unnecessary.
49-
_fileInStandardDirectory = YES;
50-
#endif
5136
}
5237
return self;
5338
}
5439

5540
- (BOOL)writeDictionary:(NSDictionary *)dict error:(NSError **)error {
56-
NSString *path = [self plistPathInDirectory:[self plistDirectory]];
41+
NSString *path = [self plistPathInDirectory];
5742
if (![dict writeToFile:path atomically:YES]) {
5843
FIRInstanceIDLoggerError(kFIRInstanceIDMessageCodeBackupExcludedPlist000,
5944
@"Failed to write to %@.plist", self.fileName);
@@ -85,7 +70,7 @@ - (BOOL)writeDictionary:(NSDictionary *)dict error:(NSError **)error {
8570

8671
- (BOOL)deleteFile:(NSError **)error {
8772
BOOL success = YES;
88-
NSString *path = [self plistPathInDirectory:[self plistDirectory]];
73+
NSString *path = [self plistPathInDirectory];
8974
if ([[NSFileManager defaultManager] fileExistsAtPath:path]) {
9075
success = [[NSFileManager defaultManager] removeItemAtPath:path error:error];
9176
}
@@ -96,101 +81,31 @@ - (BOOL)deleteFile:(NSError **)error {
9681

9782
- (NSDictionary *)contentAsDictionary {
9883
if (!self.cachedPlistContents) {
99-
NSString *path = [self plistPathInDirectory:[self plistDirectory]];
84+
NSString *path = [self plistPathInDirectory];
10085
if ([[NSFileManager defaultManager] fileExistsAtPath:path]) {
10186
self.cachedPlistContents = [[NSDictionary alloc] initWithContentsOfFile:path];
10287
}
10388
}
10489
return self.cachedPlistContents;
10590
}
10691

107-
- (BOOL)moveToApplicationSupportSubDirectory:(NSString *)subDirectoryName {
108-
NSArray *directoryPaths =
109-
NSSearchPathForDirectoriesInDomains([self supportedDirectory], NSUserDomainMask, YES);
110-
// This only going to happen inside iOS so it is an applicationSupportDirectory.
111-
NSString *applicationSupportDirPath = directoryPaths.lastObject;
112-
NSArray *components = @[ applicationSupportDirPath, subDirectoryName ];
113-
NSString *subDirectoryPath = [NSString pathWithComponents:components];
114-
BOOL hasSubDirectory;
115-
if (![[NSFileManager defaultManager] fileExistsAtPath:subDirectoryPath
116-
isDirectory:&hasSubDirectory]) {
117-
// Cannot move to non-existent directory
118-
return NO;
119-
}
120-
121-
if ([self doesFileExistInDirectory:FIRInstanceIDPlistDirectoryDocuments]) {
122-
NSString *oldPlistPath = [self plistPathInDirectory:FIRInstanceIDPlistDirectoryDocuments];
123-
NSString *newPlistPath =
124-
[self plistPathInDirectory:FIRInstanceIDPlistDirectoryApplicationSupport];
125-
if ([self doesFileExistInDirectory:FIRInstanceIDPlistDirectoryApplicationSupport]) {
126-
// File exists in both Documents and ApplicationSupport
127-
return NO;
128-
}
129-
NSError *moveError;
130-
if (![[NSFileManager defaultManager] moveItemAtPath:oldPlistPath
131-
toPath:newPlistPath
132-
error:&moveError]) {
133-
FIRInstanceIDLoggerError(kFIRInstanceIDMessageCodeBackupExcludedPlist002,
134-
@"Failed to move file %@ from %@ to %@. Error: %@", self.fileName,
135-
oldPlistPath, newPlistPath, moveError);
136-
return NO;
137-
}
138-
}
139-
// We moved the file if it existed, otherwise we didn't need to do anything
140-
return YES;
141-
}
142-
14392
- (BOOL)doesFileExist {
144-
return [self doesFileExistInDirectory:[self plistDirectory]];
93+
NSString *path = [self plistPathInDirectory];
94+
return [[NSFileManager defaultManager] fileExistsAtPath:path];
14595
}
14696

14797
#pragma mark - Private
14898

149-
- (FIRInstanceIDPlistDirectory)plistDirectory {
150-
if (_fileInStandardDirectory) {
151-
return FIRInstanceIDPlistDirectoryApplicationSupport;
152-
} else {
153-
return FIRInstanceIDPlistDirectoryDocuments;
154-
};
155-
}
156-
157-
- (NSString *)plistPathInDirectory:(FIRInstanceIDPlistDirectory)directory {
158-
return [self pathWithName:self.fileName inDirectory:directory];
159-
}
160-
161-
- (NSString *)pathWithName:(NSString *)plistName
162-
inDirectory:(FIRInstanceIDPlistDirectory)directory {
99+
- (NSString *)plistPathInDirectory {
163100
NSArray *directoryPaths;
164-
NSArray *components = @[];
165-
NSString *plistNameWithExtension = [NSString stringWithFormat:@"%@.plist", plistName];
166-
switch (directory) {
167-
case FIRInstanceIDPlistDirectoryDocuments:
168-
directoryPaths =
169-
NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
170-
components = @[ directoryPaths.lastObject, plistNameWithExtension ];
171-
break;
172-
173-
case FIRInstanceIDPlistDirectoryApplicationSupport:
174-
directoryPaths =
175-
NSSearchPathForDirectoriesInDomains([self supportedDirectory], NSUserDomainMask, YES);
176-
components = @[ directoryPaths.lastObject, _subDirectoryName, plistNameWithExtension ];
177-
break;
178-
179-
default:
180-
FIRInstanceIDLoggerError(kFIRInstanceIDMessageCodeBackupExcludedPlistInvalidPlistEnum,
181-
@"Invalid plist directory type: %lu", (unsigned long)directory);
182-
NSAssert(NO, @"Invalid plist directory type: %lu", (unsigned long)directory);
183-
break;
184-
}
101+
NSString *plistNameWithExtension = [NSString stringWithFormat:@"%@.plist", self.fileName];
102+
directoryPaths =
103+
NSSearchPathForDirectoriesInDomains([self supportedDirectory], NSUserDomainMask, YES);
104+
NSArray *components = @[ directoryPaths.lastObject, _subDirectoryName, plistNameWithExtension ];
185105

186106
return [NSString pathWithComponents:components];
187107
}
188108

189-
- (BOOL)doesFileExistInDirectory:(FIRInstanceIDPlistDirectory)directory {
190-
NSString *path = [self plistPathInDirectory:directory];
191-
return [[NSFileManager defaultManager] fileExistsAtPath:path];
192-
}
193-
194109
- (NSSearchPathDirectory)supportedDirectory {
195110
#if TARGET_OS_TV
196111
return NSCachesDirectory;

Firebase/Messaging/FIRMMessageCode.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ typedef NS_ENUM(NSInteger, FIRMessagingMessageCode) {
143143
kFIRMessagingMessageCodeRmq2PersistentStore006 = 13006, // I-FCM013006
144144
kFIRMessagingMessageCodeRmq2PersistentStoreErrorCreatingDatabase = 13007, // I-FCM013007
145145
kFIRMessagingMessageCodeRmq2PersistentStoreErrorOpeningDatabase = 13008, // I-FCM013008
146-
kFIRMessagingMessageCodeRmq2PersistentStoreInvalidRmqDirectory = 13009, // I-FCM013009
146+
kFIRMessagingMessageCodeRmq2PersistentStoreInvalidRmqDirectory = 13009, // no longer used
147147
kFIRMessagingMessageCodeRmq2PersistentStoreErrorCreatingTable = 13010, // I-FCM013010
148148
// FIRMessagingRmqManager.m
149149
kFIRMessagingMessageCodeRmqManager000 = 14000, // I-FCM014000

Firebase/Messaging/FIRMessagingRmq2PersistentStore.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,6 @@ extern NSString *const kTableS2DRmqIds;
121121
- (int)deleteMessagesFromTable:(NSString *)tableName
122122
withRmqIds:(NSArray *)rmqIds;
123123

124-
/**
125-
* Remove database from the device.
126-
*
127-
* @param dbName The database name to be deleted.
128-
*/
129-
+ (void)removeDatabase:(NSString *)dbName;
130-
131124
#pragma mark - Sync Messages
132125

133126
/**

0 commit comments

Comments
 (0)