Skip to content

Commit 93eb6d8

Browse files
authored
Revert GDTCORStorage changes for now (#5778)
* Revert "Refactor event saving and searching (#5773)" This reverts commit a61786c. * Revert "Expand the storage protocol and provide an event iterator (#5742)" This reverts commit 641d853. * Revert "Implement helpers for storing and finding events (#5738)" This reverts commit 9a0aed8.
1 parent 4158014 commit 93eb6d8

10 files changed

+18
-554
lines changed

GoogleDataTransport/GDTCORLibrary/GDTCORFlatFileStorage.m

Lines changed: 12 additions & 164 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,12 @@
2020
#import <GoogleDataTransport/GDTCORConsoleLogger.h>
2121
#import <GoogleDataTransport/GDTCOREvent.h>
2222
#import <GoogleDataTransport/GDTCORLifecycle.h>
23-
#import <GoogleDataTransport/GDTCORPlatform.h>
2423
#import <GoogleDataTransport/GDTCORPrioritizer.h>
25-
#import <GoogleDataTransport/GDTCORStorageEventSelector.h>
2624

2725
#import "GDTCORLibrary/Private/GDTCOREvent_Private.h"
28-
#import "GDTCORLibrary/Private/GDTCORFlatFileStorageIterator.h"
2926
#import "GDTCORLibrary/Private/GDTCORRegistrar_Private.h"
3027
#import "GDTCORLibrary/Private/GDTCORUploadCoordinator.h"
3128

32-
NSString *const gGDTCORFlatFileStorageEventDataPathKey = @"DataPath";
33-
34-
NSString *const gGDTCORFlatFileStorageMappingIDPathKey = @"MappingIDPath";
35-
36-
NSString *const gGDTCORFlatFileStorageQoSTierPathKey = @"QoSTierPath";
37-
3829
@implementation GDTCORFlatFileStorage
3930

4031
+ (void)load {
@@ -60,115 +51,27 @@ + (NSString *)archivePath {
6051
return archivePath;
6152
}
6253

63-
+ (NSString *)baseEventStoragePath {
64-
static NSString *eventDataPath;
54+
+ (NSString *)libraryDataPath {
55+
static NSString *libraryDataPath;
6556
static dispatch_once_t onceToken;
6657
dispatch_once(&onceToken, ^{
67-
eventDataPath =
58+
libraryDataPath =
6859
[GDTCORRootDirectory() URLByAppendingPathComponent:NSStringFromClass([self class])
6960
isDirectory:YES]
7061
.path;
71-
eventDataPath = [eventDataPath stringByAppendingPathComponent:@"gdt_event_data"];
72-
if (![[NSFileManager defaultManager] fileExistsAtPath:eventDataPath isDirectory:NULL]) {
62+
libraryDataPath = [libraryDataPath stringByAppendingPathComponent:@"gdt_library_data"];
63+
if (![[NSFileManager defaultManager] fileExistsAtPath:libraryDataPath isDirectory:NULL]) {
7364
NSError *error;
74-
[[NSFileManager defaultManager] createDirectoryAtPath:eventDataPath
65+
[[NSFileManager defaultManager] createDirectoryAtPath:libraryDataPath
7566
withIntermediateDirectories:YES
7667
attributes:0
7768
error:&error];
7869
GDTCORAssert(error == nil, @"Creating the library data path failed: %@", error);
7970
}
8071
});
81-
return eventDataPath;
82-
}
83-
84-
+ (NSString *)libraryDataStoragePath {
85-
static NSString *libraryDataPath;
86-
static dispatch_once_t onceToken;
87-
dispatch_once(&onceToken, ^{
88-
libraryDataPath =
89-
[GDTCORRootDirectory() URLByAppendingPathComponent:NSStringFromClass([self class])
90-
isDirectory:YES]
91-
.path;
92-
libraryDataPath = [libraryDataPath stringByAppendingPathComponent:@"gdt_library_data"];
93-
});
94-
if (![[NSFileManager defaultManager] fileExistsAtPath:libraryDataPath isDirectory:NULL]) {
95-
NSError *error;
96-
[[NSFileManager defaultManager] createDirectoryAtPath:libraryDataPath
97-
withIntermediateDirectories:YES
98-
attributes:0
99-
error:&error];
100-
GDTCORAssert(error == nil, @"Creating the library data path failed: %@", error);
101-
}
10272
return libraryDataPath;
10373
}
10474

105-
+ (NSString *)pathForTarget:(GDTCORTarget)target
106-
eventID:(NSNumber *)eventID
107-
qosTier:(NSNumber *)qosTier
108-
mappingID:(NSString *)mappingID {
109-
return
110-
[NSString stringWithFormat:@"%@/%ld/%@.%@.%@", [GDTCORFlatFileStorage baseEventStoragePath],
111-
(long)target, eventID, qosTier, mappingID];
112-
}
113-
114-
+ (NSSet<NSString *> *)pathsForTarget:(GDTCORTarget)target
115-
eventIDs:(nullable NSSet<NSNumber *> *)eventIDs
116-
qosTiers:(nullable NSSet<NSNumber *> *)qosTiers
117-
mappingIDs:(nullable NSSet<NSString *> *)mappingIDs {
118-
NSMutableSet<NSString *> *paths = [[NSMutableSet alloc] init];
119-
NSFileManager *fileManager = [NSFileManager defaultManager];
120-
NSString *targetPath = [NSString
121-
stringWithFormat:@"%@/%ld", [GDTCORFlatFileStorage baseEventStoragePath], (long)target];
122-
NSError *error;
123-
NSArray<NSString *> *dirPaths = [fileManager contentsOfDirectoryAtPath:targetPath error:&error];
124-
if (error) {
125-
GDTCORLogDebug(@"There was an error reading the contents of the target path: %@", error);
126-
return paths;
127-
}
128-
BOOL checkingIDs = eventIDs.count > 0;
129-
BOOL checkingQosTiers = qosTiers.count > 0;
130-
BOOL checkingMappingIDs = mappingIDs.count > 0;
131-
BOOL checkingAnything = checkingIDs == NO && checkingQosTiers == NO && checkingMappingIDs == NO;
132-
for (NSString *path in dirPaths) {
133-
if (checkingAnything) {
134-
[paths addObject:path];
135-
continue;
136-
}
137-
NSString *filename = [path lastPathComponent];
138-
NSArray<NSString *> *components = [filename componentsSeparatedByString:@"."];
139-
if (components.count != 3) {
140-
GDTCORLogDebug(@"There was an error reading the filename components: %@", components);
141-
[[NSFileManager defaultManager] removeItemAtPath:path error:nil];
142-
continue;
143-
}
144-
NSNumber *eventID = @(components[0].integerValue);
145-
NSNumber *qosTier = @(components[1].integerValue);
146-
NSString *mappingID = components[2];
147-
if (eventID == nil || qosTier == nil) {
148-
GDTCORLogDebug(@"There was an error parsing the filename components: %@", components);
149-
[[NSFileManager defaultManager] removeItemAtPath:path error:nil];
150-
continue;
151-
}
152-
NSNumber *eventIDMatch = checkingIDs ? @([eventIDs containsObject:eventID]) : nil;
153-
NSNumber *qosTierMatch = checkingQosTiers ? @([qosTiers containsObject:qosTier]) : nil;
154-
NSNumber *mappingIDMatch = checkingMappingIDs ? @([mappingIDs containsObject:mappingID]) : nil;
155-
if ((eventIDMatch == nil || eventIDMatch.boolValue) &&
156-
(qosTierMatch == nil || qosTierMatch.boolValue) &&
157-
(mappingIDMatch == nil || mappingIDMatch.boolValue)) {
158-
[paths addObject:path];
159-
}
160-
}
161-
return paths;
162-
}
163-
164-
+ (NSArray<NSString *> *)searchPathsWithEventSelector:(GDTCORStorageEventSelector *)eventSelector {
165-
NSSet *searchPaths = [GDTCORFlatFileStorage pathsForTarget:eventSelector.selectedTarget
166-
eventIDs:eventSelector.selectedEventIDs
167-
qosTiers:eventSelector.selectedQosTiers
168-
mappingIDs:eventSelector.selectedMappingIDs];
169-
return [searchPaths allObjects];
170-
}
171-
17275
+ (instancetype)sharedInstance {
17376
static GDTCORFlatFileStorage *sharedStorage;
17477
static dispatch_once_t onceToken;
@@ -311,7 +214,7 @@ - (void)libraryDataForKey:(nonnull NSString *)key
311214
onComplete:
312215
(nonnull void (^)(NSData *_Nullable, NSError *_Nullable error))onComplete {
313216
dispatch_async(_storageQueue, ^{
314-
NSString *dataPath = [[[self class] libraryDataStoragePath] stringByAppendingPathComponent:key];
217+
NSString *dataPath = [[[self class] libraryDataPath] stringByAppendingPathComponent:key];
315218
NSError *error;
316219
NSData *data = [NSData dataWithContentsOfFile:dataPath options:0 error:&error];
317220
if (onComplete) {
@@ -322,7 +225,7 @@ - (void)libraryDataForKey:(nonnull NSString *)key
322225

323226
- (void)storeLibraryData:(NSData *)data
324227
forKey:(nonnull NSString *)key
325-
onComplete:(nullable void (^)(NSError *_Nullable error))onComplete {
228+
onComplete:(nonnull void (^)(NSError *_Nullable error))onComplete {
326229
if (!data || data.length <= 0) {
327230
if (onComplete) {
328231
onComplete([NSError errorWithDomain:NSInternalInconsistencyException code:-1 userInfo:nil]);
@@ -331,7 +234,7 @@ - (void)storeLibraryData:(NSData *)data
331234
}
332235
dispatch_async(_storageQueue, ^{
333236
NSError *error;
334-
NSString *dataPath = [[[self class] libraryDataStoragePath] stringByAppendingPathComponent:key];
237+
NSString *dataPath = [[[self class] libraryDataPath] stringByAppendingPathComponent:key];
335238
[data writeToFile:dataPath options:NSDataWritingAtomic error:&error];
336239
if (onComplete) {
337240
onComplete(error);
@@ -343,7 +246,7 @@ - (void)removeLibraryDataForKey:(nonnull NSString *)key
343246
onComplete:(nonnull void (^)(NSError *_Nullable error))onComplete {
344247
dispatch_async(_storageQueue, ^{
345248
NSError *error;
346-
NSString *dataPath = [[[self class] libraryDataStoragePath] stringByAppendingPathComponent:key];
249+
NSString *dataPath = [[[self class] libraryDataPath] stringByAppendingPathComponent:key];
347250
if ([[NSFileManager defaultManager] fileExistsAtPath:dataPath]) {
348251
[[NSFileManager defaultManager] removeItemAtPath:dataPath error:&error];
349252
if (onComplete) {
@@ -353,61 +256,6 @@ - (void)removeLibraryDataForKey:(nonnull NSString *)key
353256
});
354257
}
355258

356-
- (BOOL)hasEventsForTarget:(GDTCORTarget)target {
357-
// TODO(mikehaney24): Increase the performance of this call.
358-
GDTCORStorageEventSelector *eventSelector =
359-
[[GDTCORStorageEventSelector alloc] initWithTarget:target
360-
eventIDs:nil
361-
mappingIDs:nil
362-
qosTiers:nil];
363-
id<GDTCORStorageEventIterator> iter = [self iteratorWithSelector:eventSelector];
364-
return [iter nextEvent] != nil;
365-
}
366-
367-
- (nullable id<GDTCORStorageEventIterator>)iteratorWithSelector:
368-
(nonnull GDTCORStorageEventSelector *)eventSelector {
369-
__block GDTCORFlatFileStorageIterator *iterator;
370-
dispatch_sync(_storageQueue, ^{
371-
NSArray<NSString *> *searchPaths =
372-
[GDTCORFlatFileStorage searchPathsWithEventSelector:eventSelector];
373-
iterator.eventFiles = searchPaths;
374-
});
375-
return iterator;
376-
}
377-
378-
- (void)purgeEventsFromBefore:(GDTCORClock *)beforeSnapshot
379-
onComplete:(void (^)(NSError *_Nullable error))onComplete {
380-
// TODO(mikehaney24): Figure out how we're going to deal with this.
381-
}
382-
383-
- (void)storageSizeWithCallback:(void (^)(uint64_t storageSize))onComplete {
384-
dispatch_async(_storageQueue, ^{
385-
unsigned long long totalBytes = 0;
386-
NSString *eventDataPath = [GDTCORFlatFileStorage baseEventStoragePath];
387-
NSString *libraryDataPath = [GDTCORFlatFileStorage libraryDataStoragePath];
388-
NSDirectoryEnumerator *enumerator =
389-
[[NSFileManager defaultManager] enumeratorAtPath:eventDataPath];
390-
while ([enumerator nextObject]) {
391-
NSFileAttributeType fileType = enumerator.fileAttributes[NSFileType];
392-
if ([fileType isEqual:NSFileTypeRegular]) {
393-
NSNumber *fileSize = enumerator.fileAttributes[NSFileSize];
394-
totalBytes += fileSize.unsignedLongLongValue;
395-
}
396-
}
397-
enumerator = [[NSFileManager defaultManager] enumeratorAtPath:libraryDataPath];
398-
while ([enumerator nextObject]) {
399-
NSFileAttributeType fileType = enumerator.fileAttributes[NSFileType];
400-
if ([fileType isEqual:NSFileTypeRegular]) {
401-
NSNumber *fileSize = enumerator.fileAttributes[NSFileSize];
402-
totalBytes += fileSize.unsignedLongLongValue;
403-
}
404-
}
405-
if (onComplete) {
406-
onComplete(totalBytes);
407-
}
408-
});
409-
}
410-
411259
#pragma mark - Private helper methods
412260

413261
/** Saves the event's dataObject to a file using NSData mechanisms.
@@ -462,8 +310,8 @@ - (void)appWillForeground:(GDTCORApplication *)app {
462310

463311
- (void)appWillBackground:(GDTCORApplication *)app {
464312
dispatch_async(_storageQueue, ^{
465-
// Immediately request a background task to run until the end of the current queue of work,
466-
// and cancel it once the work is done.
313+
// Immediately request a background task to run until the end of the current queue of work, and
314+
// cancel it once the work is done.
467315
__block GDTCORBackgroundIdentifier bgID =
468316
[app beginBackgroundTaskWithName:@"GDTStorage"
469317
expirationHandler:^{

GoogleDataTransport/GDTCORLibrary/GDTCORFlatFileStorageIterator.m

Lines changed: 0 additions & 66 deletions
This file was deleted.

GoogleDataTransport/GDTCORLibrary/GDTCORStorageEventSelector.m

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)