-
Notifications
You must be signed in to change notification settings - Fork 7
fix: add test to cover behavior for invalid manifests #48
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
Changes from 5 commits
9a03e29
4fc0ed8
ba2a449
585aa8e
43bd381
1b43728
49cf0fd
4ea8c5c
e449b63
cb2e9e7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -331,7 +331,36 @@ func UninstallDriverShared(cfg Config, info DriverInfo) error { | |
| // dbc installs drivers in a folder, other tools may not so we handle each | ||
| // differently. | ||
| if info.Source == "dbc" { | ||
| if err := os.RemoveAll(filepath.Dir(sharedPath)); err != nil { | ||
| shared_dir := filepath.Dir(sharedPath) | ||
|
|
||
| // Handle an edge case first. We've already verified that Driver.shared is | ||
| // an absolute path inside cfg.Location but we also expect the shared | ||
| // library to be in a subfolder, e.g., | ||
| // | ||
| // ${cfg.Location} | ||
| // └── libadbc_driver_linux_amd64_v1.0.0 | ||
| // └── libadbc_driver_linux_amd64_v1.0.0.so | ||
| // | ||
| // If the MANIFEST we're installed has Driver.shared already set, this is | ||
| // invalid becuase it should have Files set instead. When this happens, | ||
| // the Driver.shared value in the installed manifest ends up as a absolute | ||
| // path to a folder, not a shared library. | ||
| shared_path_is_subdir, err := IsImmediateSubDir(cfg.Location, sharedPath) | ||
| if err != nil { | ||
| return fmt.Errorf("error removing driver %s: %w", info.ID, err) | ||
| } | ||
|
||
| if shared_path_is_subdir { | ||
| if err := os.RemoveAll(sharedPath); err != nil { | ||
| if errors.Is(err, fs.ErrNotExist) { | ||
| continue | ||
| } | ||
| return fmt.Errorf("error removing driver %s: %w", info.ID, err) | ||
| } | ||
| continue | ||
| } | ||
|
|
||
| // The rest of this is "normal" operation... | ||
| if err := os.RemoveAll(shared_dir); err != nil { | ||
| // Ignore only when not found. This supports manifest-only drivers. | ||
| // TODO: Come up with a better mechanism to handle manifest-only drivers | ||
| // and remove this continue when we do | ||
|
|
@@ -371,3 +400,34 @@ func UninstallDriverShared(cfg Config, info DriverInfo) error { | |
|
|
||
| return nil | ||
| } | ||
|
|
||
| // Determine whether target is an immediate subdirectory of base. | ||
| func IsImmediateSubDir(base string, target string) (bool, error) { | ||
amoeba marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| base_abs, err := filepath.Abs(base) | ||
| if err != nil { | ||
| return false, err | ||
| } | ||
| target_abs, err := filepath.Abs(target) | ||
| if err != nil { | ||
| return false, err | ||
| } | ||
|
|
||
| result, err := filepath.Rel(base_abs, target_abs) | ||
| if err != nil { | ||
| return false, err | ||
| } | ||
|
|
||
| parts := strings.Split(result, string(filepath.Separator)) | ||
|
|
||
| // return false if we're not a direct child | ||
| if len(parts) != 1 { | ||
| return false, nil | ||
| } | ||
|
|
||
| // return false if we're above | ||
| if strings.HasPrefix(result, ".") { | ||
| return false, nil | ||
| } | ||
|
|
||
| return true, nil | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.