Skip to content

fix: add test to cover behavior for invalid manifests - #48

Merged
amoeba merged 10 commits into
columnar-tech:mainfrom
amoeba:fix/uninstall-defensive-bad-manifest
Sep 19, 2025
Merged

amoeba merged 10 commits into
columnar-tech:mainfrom
amoeba:fix/uninstall-defensive-bad-manifest

Conversation

@amoeba

@amoeba amoeba commented Sep 17, 2025 •

Copy link
Copy Markdown
Member

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
Comment thread cmd/dbc/testdata/test_manifest.yaml Resolved
@amoeba

amoeba commented Sep 18, 2025

Copy link
Copy Markdown
Member Author

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

amoeba commented Sep 19, 2025

Copy link
Copy Markdown
Member Author

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
Comment thread cmd/dbc/uninstall_test.go Resolved
Comment thread config/config.go Resolved
Comment thread 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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

@zeroshade zeroshade Sep 19, 2025 •

Copy link
Copy Markdown
Member

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Comment thread config/config.go Resolved
@amoeba
amoeba merged commit 415676d into columnar-tech:main Sep 19, 2025
zeroshade added a commit that referenced this pull request Apr 17, 2026
zeroshade pushed a commit that referenced this pull request Apr 17, 2026
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 by skipping. 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
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