feat(release): add --clobber and --skip-existing to download

Problem

glab release download opens every target with O_EXCL, so a file already in the download directory stops the command:

open /tmp/dl/asset.tar.gz: file exists

That makes two ordinary things awkward. Re-running after an interrupted download needs a manual delete first, and so does refreshing a single asset. The error does not say which flag would help, because there was none.

What this changes

Two flags, matching the behavior of gh release download:

  • --clobber overwrites a file that already exists.
  • --skip-existing keeps it, reports the skip, and continues with the other assets.

They are mutually exclusive, through MarkFlagsMutuallyExclusive.

The default is unchanged. Without either flag the command still stops, so a download cannot destroy a local file by accident. The error now names the file and points at both flags:

"/tmp/dl/asset.tar.gz" already exists. Use '--clobber' to overwrite it, or '--skip-existing' to keep it: file exists

--clobber opens with O_TRUNC, so overwriting a longer file with a shorter one leaves no tail of the old content behind. A test covers that case.

On --update

The issue also asks for an --update parameter. I left it out. Its meaning is ambiguous: it could mean "replace only if the remote asset is newer", which needs a timestamp or checksum the release links API does not return, or it could be another name for --clobber. I would rather implement the two unambiguous flags and let you say what --update should mean.

Testing

21 subtests pass. The new ones cover: an existing file with no flag (fails, and the local content is verified untouched), --clobber overwriting, --skip-existing keeping the content and logging the skip, both flags downloading a file that is missing, and the mutual-exclusion error.

go test ./internal/commands/release/download/... -count=1 -race   # ok
go build ./...                                                    # ok
gofmt -l <changed files>                                          # no output
go run ./cmd/gen-docs/docs.go                                     # docs/source/release/download.md updated

Note on my local environment: internal/commands/release/create fails TestReleaseCreate_ExperimentalNotes/when_experimental_notes_points_to_existing_file on a clean main checkout too, so it is unrelated to this change.

One overlap to be aware of

This changes the signature and body of downloadAsset, and so does !4073 (merged), which fixes the 404 on Markdown upload assets (#1301 (closed)). Whichever merges first, I will rebase the other and re-run its tests. The two changes are independent in behavior, so the order does not matter.

Closes #7559 (closed)

Merge request reports

Loading
Loading