-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add error for attempt to upload directory #5750
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
8d1e246
Add error for attempt to upload directory
ncooke3 dd74cf4
Resolved feedback
ncooke3 404a1ea
Resolved feedback
ncooke3 afced84
Removed star_wars.pdf from pod spec
ncooke3 2f2e741
Merge branch 'nc-storage-directory-upload-attempt-error' of github.co…
ncooke3 5fbb578
Added HomeImprovement.numbers, removed other .numbers file
ncooke3 ab33ef2
Fixed typo in podspec
ncooke3 825ac13
Edited Storage CHANGELOG
ncooke3 35b00e9
Check for isFile rather than isDirectory
ncooke3 dae4b6d
Changed up the check to validate file
ncooke3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -193,11 +193,14 @@ - (BOOL)isContentToUploadValid:(NSError **)outError { | |
| } | ||
|
|
||
| NSError *fileReachabilityError; | ||
| if (![_fileURL checkResourceIsReachableAndReturnError:&fileReachabilityError]) { | ||
| if (![_fileURL checkResourceIsReachableAndReturnError:&fileReachabilityError] || | ||
| ![self fileURLisFile:_fileURL]) { | ||
| if (outError != NULL) { | ||
| NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithCapacity:2]; | ||
| userInfo[NSLocalizedDescriptionKey] = | ||
| [NSString stringWithFormat:@"File at URL: %@ is not reachable.", _fileURL.absoluteString]; | ||
| userInfo[NSLocalizedDescriptionKey] = [NSString | ||
| stringWithFormat:@"File at URL: %@ is not reachable. " | ||
| @"Ensure file URL is not a directory, symbolic link, or invalid url.", | ||
| _fileURL.absoluteString]; | ||
|
Comment on lines
+200
to
+203
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added some extra context to the error since we are now explicitly checking if the url points to a file. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks good! |
||
|
|
||
| if (fileReachabilityError) { | ||
| userInfo[NSUnderlyingErrorKey] = fileReachabilityError; | ||
|
|
@@ -257,4 +260,12 @@ - (void)resume { | |
| }]; | ||
| } | ||
|
|
||
| #pragma mark - Private Helpers | ||
|
|
||
| - (BOOL)fileURLisFile:(NSURL *)fileURL { | ||
| NSNumber *isFile = [NSNumber numberWithBool:NO]; | ||
| [fileURL getResourceValue:&isFile forKey:NSURLIsRegularFileKey error:nil]; | ||
| return [isFile boolValue]; | ||
| } | ||
|
|
||
| @end | ||
1 change: 1 addition & 0 deletions
1
FirebaseStorage/Tests/Integration/Resources/HomeImprovement.numbers/About.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| The `HomeImprovement.numbers` directory exists to test Firebase Storage's ability to fail gracefully when one attempts to upload a directory. Since git doesn't track track empty directories. This .txt file exists to provide context and make git track the folder. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
checkResourceIsReachableAndReturnErrorreturns true or false depending on if the_fileURLcan be reached. This is why attempts to upload directories weren't being caught in the first place, because they are reachable. Instead of doing a check inputFile:, I figured I should move thefileURLisFilehelper method toFIRStorageUploadTask.mand call it in thisisContentToUploadValidmethod so we have a single check to verify that the file we are trying to upload is both a reachable resource and it is a file.