【问题标题】:Core Data migration: File Exists核心数据迁移:文件存在
【发布时间】:2010-06-23 17:13:05
【问题描述】:

在 iPhone 上执行轻量级核心数据迁移时,我收到一些用户的以下错误:

{
NSUnderlyingError = Error Domain=NSPOSIXErrorDomain Code=17 UserInfo=0x2991d0
"Operation could not be completed. File exists";
destinationURL = file://localhost/var/mobile/Applications/AEFD8CE2-0AF6-4227-AB84-73E2F5D83F26/Documents/App.sqlite.new;
reason = "Can't copy source store to destination store path";
sourceURL = file://localhost/var/mobile/Applications/AEFD8CE2-0AF6-4227-AB84-73E2F5D83F26/Documents/App.sqlite;
}

这是迁移中断的结果吗?还是其他什么原因?无论如何,在尝试迁移之前手动删除 .new 数据库是否是适当的补救措施?

代码只是一个简单的轻量级迁移:

NSURL *storeUrl = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @"App.sqlite"]];
NSError *error = nil;
persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
// convert automatically from prior models
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
                         [NSNumber numberWithBool:YES], 
                         NSMigratePersistentStoresAutomaticallyOption,
                         [NSNumber numberWithBool:YES],
                         NSInferMappingModelAutomaticallyOption,
                         nil];
if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:options error:&error]) 
{
    [MainAppDelegate printDetailedErrors:error];
}

更新:Apple 论坛的 BenT 告诉我这是一个 3.1.x 错误,但我还没有返回并使用我的错误日志数据验证这一点。

【问题讨论】:

    标签: iphone core-data


    【解决方案1】:

    Core Data 不会定期将文件命名为 .new。你能显示产生这个错误的代码吗?

    更新

    如果 BenT 说这是一个错误,那就是答案。如果有人知道核心数据问题的答案,Ben 就有。

    【讨论】:

    • “Core Data 不会定期将文件命名为 .new” 是的,现在确实如此。在 10.6.6(Xcode 3.2.5)上的有问题的迁移过程中,我遇到了同样的错误,代码与 @sehugg 相同 - 而不是 iPhone。相关的应用程序支持字典显示了 SQL lite 存储的两个版本:storedata 和 storedata.new,其中 storedata.new 反映了数据模型的新版本。
    【解决方案2】:

    在对 Marcus S. Zarra 的回答写下我的评论后,我做了更多的研究,并在 CocoaBuilder 上遇到了Jerry Krinock's post,他意识到代码 NSPOSIXErrorDomain 确实是由底层 BSD 层函数引发的错误包装。根据Waikato Linux Users Group,Posix 在尝试覆盖现有文件时会引发错误 17。 我的结论:当迁移过程中出现问题并且您最终在应用程序支持目录中的应用程序文件夹中同时拥有一个和一个 .new 文件时,您会被卡住,因为每次 addPersistentStoreWithType: 尝试创建一个用于合并的存储 (. new) 它遇到 Posix 错误代码 17。在确保所有设置正确后,解决方案是删除 .new 并让迁移运行。它确实做到了。

    【讨论】:

      猜你喜欢
      • 2011-09-14
      • 2012-04-11
      • 2014-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-22
      • 2023-03-14
      • 1970-01-01
      相关资源
      最近更新 更多