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

Update NSFileProtection samples to set attributes on lock files #1571

Closed
kronik opened this issue Mar 5, 2015 · 11 comments
Closed

Update NSFileProtection samples to set attributes on lock files #1571

kronik opened this issue Mar 5, 2015 · 11 comments
Assignees

Comments

@kronik
Copy link

kronik commented Mar 5, 2015

This issue is very similar to #1260 .
Application tries to select data from Realm db when app fetch in background handler is called.

And I

disabled protection at all:

+ (void)initialize {
    NSError *error = nil;
    NSURL   *fileUrl = [NSURL fileURLWithPath:[RLMRealm defaultRealmPath]];

    [fileUrl setResourceValue:@YES forKey:NSURLIsExcludedFromBackupKey error:&error];

    [[NSFileManager defaultManager] setAttributes:@{NSFileProtectionKey:NSFileProtectionNone}
                                     ofItemAtPath:[RLMRealm defaultRealmPath]
                                            error:&error];
}

tried also with NSFileProtectionCompleteUntilFirstUserAuthentication but still the same.

What I'm doing wrong?

@kronik
Copy link
Author

kronik commented Mar 5, 2015

I tried to compare behaviour with https://github.com/marcoarment/FCModel and FCModel works fine even in background locked mode.

@segiddins
Copy link
Contributor

What sort of error are you seeing when realm crashes? It'd be really helpful if you could share a stack trace!

@jpsim jpsim added the pending label Mar 6, 2015
@kronik
Copy link
Author

kronik commented Mar 6, 2015

failed to open(). something related with permissions...

@kronik
Copy link
Author

kronik commented Mar 9, 2015

It seems like NSFileProtectionKey:NSFileProtectionNone needs to be applied to db log file or something else you guys use in addition to main db file.

@jpsim jpsim changed the title Realm crashes on background fetch Update NSFileProtection samples to set attributes on lock files Mar 9, 2015
@jpsim jpsim self-assigned this Mar 9, 2015
@jpsim
Copy link
Contributor

jpsim commented Mar 9, 2015

Hi @kronik, you're right that you'll have to set the NSFileProtection file attributes for the lock and log files if you're writing to the realm in the background.

NSString *pathToRealmFile = [RLMRealm defaultRealmPath];
NSArray *allRealmRelatedFiles = @[
  pathToRealmFile,
  [pathToRealmFile stringByAppendingPathExtension:@"lock"],
  [pathToRealmFile stringByAppendingPathExtension:@"log"],
  [pathToRealmFile stringByAppendingPathExtension:@"log_a"],
  [pathToRealmFile stringByAppendingPathExtension:@"log_b"]
];
for (NSString *path in allRealmRelatedFiles) {
  NSError *error = nil;
  [[NSFileManager defaultManager] setAttributes:@{NSFileProtectionKey: NSFileProtectionNone}
                                   ofItemAtPath:path
                                          error:&error];
}

We'll be updating our NSFileProtection related samples to reflect this as soon as possible.

@jpsim
Copy link
Contributor

jpsim commented Mar 9, 2015

That's what we'll do in the short term. However users really shouldn't have to know about all these potential ancillary files so we'll be adding a convenience method like setFileProtectionKeyForRealmsAtPath:. We'll track this in a more flexible RLMConfiguration in #1584.

@alazier
Copy link
Contributor

alazier commented Mar 9, 2015

Lets just do #1584 rather than adding a new global configuration method that we will remove soon after adding.

@dismory
Copy link
Contributor

dismory commented Apr 2, 2015

Similarly, do I need to delete all these five files explicitly if I want to delete a Realm?

@tgoyne
Copy link
Member

tgoyne commented Apr 2, 2015

If you're just deleting and recreating the Realm file, then no (barring bugs in Realm).

@dismory
Copy link
Contributor

dismory commented Apr 2, 2015

If not, will it take more disk space?

@jpsim jpsim added tutorial and removed P2 labels Apr 28, 2015
@jpsim
Copy link
Contributor

jpsim commented Jan 7, 2016

This is now documented in https://realm.io/docs/objc/latest/#encryption.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants