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

Swift 2.0: LiteCore error trying to copy prebuilt DB #2061

Closed
jayzhanghs opened this Issue Feb 7, 2018 · 6 comments

Comments

Projects
None yet
3 participants
@jayzhanghs

jayzhanghs commented Feb 7, 2018

I'm using this code snippet from Couchbase Document at https://developer.couchbase.com/documentation/mobile/2.0/couchbase-lite/swift.html#database

{code}
let assetPath = Bundle.main.path(forResource: "travel-sample", ofType: "cblite2")!
if !Database.exists(withName: "travel-sample") {
do {
try Database.copy(fromPath: assetPath, toDatabase: "travel-sample", withConfig: nil)
} catch {
fatalError("Could not load pre-built database")
}
}
{code}

It jumped to Fatal error with LiteCore error code 12 "no such file or directory"


  • Version: Swift 2.0 DB21
  • Client OS: iOS 11
  • Server: NAME_AND_VERSION

@snej snej changed the title from Swift 2.0: LiteCore crash trying to copy prebuilt DB to Swift 2.0: LiteCore error trying to copy prebuilt DB Feb 7, 2018

@snej

This comment has been minimized.

Member

snej commented Feb 7, 2018

Have you verified that a database exists at assetPath? Because if not, the error is correct.

@jayzhanghs

This comment has been minimized.

jayzhanghs commented Feb 7, 2018

It's in the Resources folder, as shown here, otherwise it would crash at the first line in trying to unwrap the assetPath (the ! sign)

img_0237

@snej

This comment has been minimized.

Member

snej commented Feb 7, 2018

This is a Couchbase Lite bug. +[CBLDatabase copyFromPath:...] calls c4db_copy without first ensuring that the parent directory of toPath exists. If it doesn't, LiteCore will return a file-not-found error instead of creating the database directory.

The method does call setupDatabaseDirectory, but only after the copy request; at that point it's a no-op. It needs to call it beforehand, and it should pass the parent of toPath.

@pasin pasin added bug P1: high labels Feb 7, 2018

@pasin pasin added this to the 2.0.0 milestone Feb 7, 2018

@pasin pasin self-assigned this Feb 7, 2018

@snej

This comment has been minimized.

Member

snej commented Feb 7, 2018

@jayzhanghs, you should be able to work around this by creating another database first; that will cause the parent directory to be created. You can then delete it. Or alternatively, look up the directory property of the DatabaseConfiguration and create that directory yourself.

pasin added a commit that referenced this issue Feb 7, 2018

Fix Database copy to non-existing directory
Somehow the setupDatabaseDirectory() was called after c4db_copy() method. It needs to be called before with the parent directory of the target database.

#2061 #1879
@pasin

This comment has been minimized.

Contributor

pasin commented Feb 7, 2018

I fixed the bug in feature/2.0-dev branch.

@pasin pasin closed this Feb 7, 2018

@jayzhanghs

This comment has been minimized.

jayzhanghs commented Feb 7, 2018

Thanks @pasin and @snej for the quick turn around in investigation and the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment