Skip to content

Conversation

@amoeba
Copy link
Member

@amoeba amoeba commented Sep 17, 2025

Fixes an edge case where we get confused about what fields to put in a manifest. When we package a driver, we include an all-caps MANIFEST file which has a Files table that points to the shared library living in the same package. When dbc installs a package, it converts what's in Files into what goes in Driver.shared. If we goof up and put a Driver.shared table in MANIFEST, dbc uninstall was mistakenly deleting all drivers in the config level.

This patch catches this case and handles it. It's good to be defensive here because we'll be asking people to crate MANIFEST files who aren't us so mistakes will happnen.

Closes #29

@ianmcook ianmcook requested a review from zeroshade September 18, 2025 00:20
@amoeba
Copy link
Member Author

amoeba commented Sep 18, 2025

Okay good. I rebased this and now it's failing like I expect. The current code is exposing a bad bug we need to patch. If Driver.shared isn't a file like it's supposed to be, we actually delete the entirety of ADBC_DRIVER_PATH, meaning we nuke all of the user's drivers.

@amoeba amoeba changed the title fix: add test to cover behavior for invalid manifestes fix: add test to cover behavior for invalid manifests Sep 19, 2025
@amoeba
Copy link
Member Author

amoeba commented Sep 19, 2025

I ended up just explicitly detecting the weird state that causes this bug, see 43bd381. It might be cleaner just entirely fail the install when we get a MANIFEST that has this issue but until then this catches it.

@amoeba amoeba requested a review from zeroshade September 19, 2025 03:15
config/config.go Outdated
Comment on lines 348 to 351
shared_path_is_subdir, err := IsImmediateSubDir(cfg.Location, sharedPath)
if err != nil {
return fmt.Errorf("error removing driver %s: %w", info.ID, err)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we simplify this logic by using filepath.Ext(sharedPath) and assuming that it should have a non-empty extension? (so, dll, dylib, etc.)

We could also leverage https://pkg.go.dev/os#Root.FS to ensure that we don't have any issues with malicious symbolic links. Maybe do os.OpenRoot(cfg.Location) and then work in terms of the returned root FS?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we simplify this logic by using filepath.Ext(sharedPath) and assuming that it should have a non-empty extension? (so, dll, dylib, etc.)

I don't know if that would quite cover it. We basically just want to know whether calling filepath.Dir doesn't give us a subfolder of cfg.Location. It should almost every time, just not in this edge case.

https://pkg.go.dev/os#Root.FS looks cool. That could be a nice improvement (followup?).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if that would quite cover it. We basically just want to know whether calling filepath.Dir doesn't give us a subfolder of cfg.Location. It should almost every time, just not in this edge case.

Should we just do info, _ := os.Stat() and info.IsDir() then? would be simpler

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I see how that'd catch the issue. If you want to take a shot at the idea I can take a look. Knowing the path is a folder is part of detecting that we're in the edge case but we also need to ensure it's a folder that, when we call filepath.Dir, we don't get cfg.Location and then delete all the user's drivers.

Copy link
Member

@zeroshade zeroshade Sep 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we just do filepath.Clean(dir) != filepath.Clean(cfg.Location) then?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I guess so. Maybe we don't need to also remove the folder in the case of the edge case.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i like that better in the edge case, so we can reduce the complexity of the logic

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed.

@amoeba amoeba requested a review from zeroshade September 19, 2025 19:17
@amoeba amoeba merged commit 415676d into columnar-tech:main Sep 19, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

uninstall erroring and deleting more than it should

2 participants