Commit 719035cb authored by Javier Ernesto Flores Robles's avatar Javier Ernesto Flores Robles Committed by Commit Bot

[iOS][Credential-Provider] Create directory if needed.

Bug: 1045457
Change-Id: I7bee2b914485e062bdffbbd7bf4e7f0ab345f015
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2135697
Commit-Queue: Javier Ernesto Flores Robles <javierrobles@chromium.org>
Commit-Queue: David Jean <djean@chromium.org>
Auto-Submit: Javier Ernesto Flores Robles <javierrobles@chromium.org>
Reviewed-by: default avatarDavid Jean <djean@chromium.org>
Cr-Commit-Position: refs/heads/master@{#756632}
parent 205be1aa
...@@ -32,6 +32,9 @@ ...@@ -32,6 +32,9 @@
- (instancetype)initWithFileURL:(NSURL*)fileURL { - (instancetype)initWithFileURL:(NSURL*)fileURL {
self = [super init]; self = [super init];
if (self) { if (self) {
if (fileURL) {
DCHECK(fileURL.isFileURL) << "URL must be a file URL.";
}
_fileURL = fileURL; _fileURL = fileURL;
_workingQueue = dispatch_queue_create(nullptr, DISPATCH_QUEUE_CONCURRENT); _workingQueue = dispatch_queue_create(nullptr, DISPATCH_QUEUE_CONCURRENT);
} }
...@@ -89,6 +92,17 @@ ...@@ -89,6 +92,17 @@
return; return;
} }
[[NSFileManager defaultManager]
createDirectoryAtURL:self.fileURL.URLByDeletingLastPathComponent
withIntermediateDirectories:YES
attributes:nil
error:&error];
if (error) {
completion(error);
return;
}
[data writeToURL:self.fileURL options:NSDataWritingAtomic error:&error]; [data writeToURL:self.fileURL options:NSDataWritingAtomic error:&error];
DCHECK(!error) << error.debugDescription.UTF8String; DCHECK(!error) << error.debugDescription.UTF8String;
completion(error); completion(error);
......
...@@ -131,4 +131,29 @@ TEST_F(ArchivableCredentialStoreTest, persist) { ...@@ -131,4 +131,29 @@ TEST_F(ArchivableCredentialStoreTest, persist) {
EXPECT_TRUE( EXPECT_TRUE(
[credential isEqual:freshCredentialStore.credentials.firstObject]); [credential isEqual:freshCredentialStore.credentials.firstObject]);
} }
// Tests that ArchivableCredentialStore can save in a folder that doesn't exist.
TEST_F(ArchivableCredentialStoreTest, createFolder) {
NSURL* deepFolderURL = [testStorageFileURL()
URLByAppendingPathComponent:@"a/deep/path/component"];
ArchivableCredentialStore* credentialStore =
[[ArchivableCredentialStore alloc] initWithFileURL:deepFolderURL];
EXPECT_TRUE(credentialStore);
ArchivableCredential* credential = TestCredential();
[credentialStore addCredential:credential];
EXPECT_EQ(1u, credentialStore.credentials.count);
__block BOOL blockWaitCompleted = false;
[credentialStore saveDataWithCompletion:^(NSError* error) {
EXPECT_FALSE(error);
blockWaitCompleted = true;
}];
EXPECT_TRUE(WaitUntilConditionOrTimeout(kWaitForFileOperationTimeout, ^bool {
return blockWaitCompleted;
}));
NSError* error = nil;
[deepFolderURL checkResourceIsReachableAndReturnError:&error];
EXPECT_FALSE(error);
}
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment