refactor(utils): simplify EnsureDestinationRoot and consolidate securefile copy

Follow-up to !3650 (merged) — addresses @hacks4oats's post-merge review comments.

Summary

  • Simplifies utils.EnsureDestinationRoot: drops the intermediate os.OpenRoot(".") + MkdirAll dance and its ensureDirectoryExists helper. The relative-path escape check is now an explicit filepath.IsLocal guard, and os.MkdirAll creates the destination directory directly.
  • Removes the local ensureDestinationRoot / ensureDirectoryExists copies in internal/commands/securefile/download/download.go; both call sites now use the shared utils.EnsureDestinationRoot (matching the packages/download command).
  • Migrates the still-useful "absolute path whose parent is a file" test case into internal/utils/root_test.go and drops the obsolete tests that referenced the deleted helpers.

Note on scope

The original suggestion was to drop os.OpenRoot entirely and let callers use os.Create(path). I kept the returned *os.Root because it's what gives the download commands their write-step symlink protection (server-supplied filenames are joined through root.Create / root.Rename). The anti-traversal guarantee for relative paths is now enforced up-front via filepath.IsLocal instead of via wrapping in os.OpenRoot("."), which lets the helper collapse to a single MkdirAll + OpenRoot.

Happy to trim further if you'd rather see the write path move to plain os.Create too — that's a slightly larger change in securefile/download and packages/download.

Test plan

  • go test ./internal/utils/... ./internal/commands/securefile/download/... ./internal/commands/packages/download/...
  • make lint
  • make build

cc @hacks4oats

Merge request reports

Loading