Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions FirebaseDatabase/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Unreleased
- [fixed] Fix `Fatal Exception: FirebaseDatabasePersistenceFailure`. (#4493)

# 11.9.0
- [fixed] Fix connection failure issue introduced in 10.27.0 by restoring the
Socket Rocket implementation instead of `NSURLSessionWebSocket`. Note that
Expand Down
16 changes: 10 additions & 6 deletions FirebaseDatabase/Sources/Persistence/FLevelDBStorageEngine.m
Original file line number Diff line number Diff line change
Expand Up @@ -977,17 +977,24 @@ - (id)deserializePrimitive:(NSData *)data {
}

+ (void)ensureDir:(NSString *)path markAsDoNotBackup:(BOOL)markAsDoNotBackup {
NSError *error;
NSError *error = nil;
NSDictionary *attributes = @{
NSFileProtectionKey :
NSFileProtectionCompleteUntilFirstUserAuthentication
};
BOOL success =
[[NSFileManager defaultManager] createDirectoryAtPath:path
withIntermediateDirectories:YES
attributes:nil
attributes:attributes
error:&error];
if (!success) {
@throw [NSException
exceptionWithName:@"FailedToCreatePersistenceDir"
reason:@"Failed to create persistence directory."
userInfo:@{@"path" : path}];
userInfo:@{
@"path" : path,
@"error" : error ? error : [NSNull null]
}];
}

if (markAsDoNotBackup) {
Expand All @@ -1000,9 +1007,6 @@ + (void)ensureDir:(NSString *)path markAsDoNotBackup:(BOOL)markAsDoNotBackup {
@"I-RDB076035",
@"Failed to mark firebase database folder as do not backup: %@",
error);
[NSException raise:@"Error marking as do not backup"
format:@"Failed to mark folder %@ as do not backup",
firebaseDirURL];
}
}
}
Expand Down
36 changes: 35 additions & 1 deletion FirebaseDatabase/Tests/Unit/FLevelDBStorageEngineTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@
#import "FirebaseDatabase/Sources/Snapshot/FSnapshotUtilities.h"
#import "FirebaseDatabase/Tests/Helpers/FTestHelpers.h"

@interface FLevelDBStorageEngineTests : XCTestCase
@interface FLevelDBStorageEngine (Tests)
+ (void)ensureDir:(NSString *)path markAsDoNotBackup:(BOOL)markAsDoNotBackup;
@end

@interface FLevelDBStorageEngineTests : XCTestCase
@end

@implementation FLevelDBStorageEngineTests
Expand Down Expand Up @@ -685,4 +688,35 @@ - (void)testRemoveTrackedQueryRemovesTrackedQueryKeys {
([NSSet setWithArray:@[ @"b", @"c" ]]));
}

- (void)testEnsureDirSetsCorrectFileProtection {
NSString *testDirName =
[NSString stringWithFormat:@"fdb_persistence_test_%lu", (unsigned long)arc4random()];
NSString *testPath = [NSTemporaryDirectory() stringByAppendingPathComponent:testDirName];

// Ensure the directory doesn't exist before the test
[[NSFileManager defaultManager] removeItemAtPath:testPath error:nil];

// Call the method to create the directory
[FLevelDBStorageEngine ensureDir:testPath markAsDoNotBackup:NO];

// Get the attributes of the created directory
NSError *error = nil;
NSDictionary<NSFileAttributeKey, id> *attributes =
[[NSFileManager defaultManager] attributesOfItemAtPath:testPath error:&error];

// Assert that the file protection attribute is correct
XCTAssertNil(error, @"Failed to get attributes of directory: %@", error);

#if !TARGET_OS_SIMULATOR
// On a physical device, file protection should be set.
XCTAssertEqualObjects(attributes[NSFileProtectionKey],
NSFileProtectionCompleteUntilFirstUserAuthentication);
#else
// In the simulator, file protection is not supported, so the key should be nil.
XCTAssertNil(attributes[NSFileProtectionKey]);
#endif

// Clean up
[[NSFileManager defaultManager] removeItemAtPath:testPath error:nil];
}
@end
Loading