Skip to content

Implement -[NSData writeToURL:options:error:] #57

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

Closed

Conversation

lowell
Copy link
Contributor

@lowell lowell commented Dec 7, 2015

I feel like I should feel bad for submitting a PR during a weekend, but this is fun.

public func writeToURL(url: NSURL, options writeOptionsMask: NSDataWritingOptions) throws {
NSUnimplemented()
if let path = url.path {
do {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is no need for do {} catch {} blocks, you can simply use try writeToFile(path, options: writeOptionsMask)

bolshedvorsky and others added 3 commits December 7, 2015 12:11
Check only for the existence of file owner's account (user) identifier instead of comparing its numeric value because
- user identifier of `0` are assigned to the superuser in linux
- negative value are valid account identifier. e.g. `nobody` is `-2` (See https://en.wikipedia.org/wiki/User_identifier)
- There's an assumption made here that account identifier are numeric which is reasonable for most system but there's a slim chance that this might not be the case.

Thanks to @lxcid
Add string constants for NSDecimalNumber

Add more string constants

Add more string constants
- verify that URL is a file path, and do it early
- remove unnecessary do/catch

Thanks so much for the feedback, @ookla and @johankool!
public func writeToURL(url: NSURL, options writeOptionsMask: NSDataWritingOptions) throws {
NSUnimplemented()
guard let path = url.path where url.filePathURL == true else {
let userInfo = [NSLocalizedDescriptionKey : "The folder at “\(url)” does not exist or is not a file URL.", // NSLocalizedString() not yet available

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to me that the error message also isn't quite correct about the first part. You aren't checking whether a folder exist, but wether the URL given contains a path. (But I am not sure exactly what the existing Foundation framework does/reports in this case.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the url is a file url then it checks to see if the url has a path, if it does not it claims there is no such file (which is kind-of true-ish)
then it will funnel to writeToFile in the case of a file url (which has it's own error cases)
else it claims the url is an unsupported scheme.

@parkera
Copy link
Contributor

parkera commented Dec 7, 2015

@lowell I'll take you up on your offer to close this one and rebase so we don't get things really confused.

@parkera parkera closed this Dec 7, 2015
@parkera parkera reopened this Dec 7, 2015
@parkera
Copy link
Contributor

parkera commented Dec 7, 2015

Oops, didn't mean to close it myself. Close when you're ready.

@lowell
Copy link
Contributor Author

lowell commented Dec 7, 2015

Thanks @parkera. :D Resubmitted.

@lowell lowell closed this Dec 7, 2015
@lowell lowell deleted the lowell/nsdata-writetourl-options-error branch December 8, 2015 02:22
atrick pushed a commit to atrick/swift-corelibs-foundation that referenced this pull request Jan 12, 2021
Correct location property of DiagnosticRelatedInformation
kateinoigakukun pushed a commit to kateinoigakukun/swift-corelibs-foundation that referenced this pull request Oct 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants