Skip to content

Conversation

@ahmad-sanad
Copy link

@ahmad-sanad ahmad-sanad commented Sep 25, 2025

Note: tests fail for me without #925

Fixes #829
Fixes #871
Fixes #910

When using clone with --follow and --filter, the code opens the filters SQLite database then tries to attach the source database multiple times. This fails because the source database has already been attached with the same name.

This code queries pragma_database_list to see if a database has already been attached with the same name. If so, it skips trying to attach it again and returns success.

It's been a while since I've written C, and this is probably my first time using SQLite, so please let me know if I should have gone about this another way.

I considered other approaches but decided on this:

  1. Always detach before attaching
    This seems destructive/heavy handed and might cause race conditions or something
  2. Parse the error message from SQLite and if it contains this error, return true
    The response code for this error isn't unique, so we'd need to actually parse the error message, which seems fragile.
  3. Don't call catalog_attach multiple times
    This seems like a potentially good solution, but it felt like catalog_attach should be idempotent (or whatever the right term is) and not fail when called multiple times.

when using clone with --follow and --filter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant