Skip to content
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

ARK_writeDataBlock uses deprecated writeData that throws Exception #74

Open
eikefalkenberg opened this issue Nov 15, 2019 · 3 comments
Open
Labels
bug Something isn't working as expected

Comments

@eikefalkenberg
Copy link

eikefalkenberg commented Nov 15, 2019

There are several calls to NSFileHandle's writeData inNSFileHandle+ARKAdditions.m which is deprecated.

API_DEPRECATED_WITH_REPLACEMENT("writeData:error:",
                                    macos(10.0, API_TO_BE_DEPRECATED), ios(2.0, API_TO_BE_DEPRECATED),
                                    watchos(2.0, API_TO_BE_DEPRECATED), tvos(9.0, API_TO_BE_DEPRECATED));

The problem here is that this old method will raise an exception in case of an error, especially if the device runs out of disk space:

If the receiver is a file, writing takes place at the file pointer’s current position. After it writes the data, the method advances the file pointer by the number of bytes written. **This method raises an exception if the file descriptor is closed or is not valid, if the receiver represents an unconnected pipe or socket endpoint, if no free space is left on the file system, or if any other writing error occurs.

Using the newer writeData:error: selector would return an error instead of causing an exception.

@dfed
Copy link
Collaborator

dfed commented Nov 15, 2019

I'm working on creating a modernized NSFileHandle+ARKAdditions in dfed/CacheAdvance#1, though I'm not sure if the current owners of this library would want to introduce that dependency.

One complication (which I haven't yet solved in CacheAdvance) is that the new methods are iOS 13+, so we'd need to continue using the old methods in iOS 12, though we could wrap the old methods and have them return an error (or throw in Swift).

@eikefalkenberg
Copy link
Author

Sounds great! The problem for this one in particular is that it runs asynchronous on it's own queue, so you can't handle the exception or a return error. A low hanging fruit here would be to just ignore the error with the new api.

@eikefalkenberg
Copy link
Author

Oh sorry now I see it, I missed that it's a new method, so we might have to wrap it in something like

if (@available(iOS 13.0, *)) {
        NSError *error;
        [self writeData:dataLengthData error:&error];
        [self writeData:dataBlock error:&error];
    } else {
        @try {
            [self writeData:dataLengthData];
            [self writeData:dataBlock];
        }
        @catch ( NSException *e ) {
        }
    }

@NickEntin NickEntin added the bug Something isn't working as expected label Nov 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working as expected
Projects
None yet
Development

No branches or pull requests

3 participants