Skip to content

feat(remotefs): add DownloadFile helper to fetch files from hosts - #523

Merged
kke merged 3 commits into
mainfrom
feat/remotefs-download-file
Nov 19, 2026
Merged

kke merged 3 commits into
mainfrom
feat/remotefs-download-file

Conversation

@kke

@kke kke commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Adds remotefs.DownloadFile, the remote-to-local counterpart of Upload: atomic temp+rename, SHA-256 verified against the remote file, and the remote mode (or WithPermissions, which now applies to both) and mtime applied. Symlinks and other non-regular sources are rejected, since the remote stat describes the link itself; Windows file info now reports symbolic links so this holds there too.

upload.go is renamed to transfer.go in a separate commit now that it holds both directions.

Refs #193 (directory transfer not included).

kke added 2 commits November 19, 2026 09:57
DownloadFile is the counterpart of Upload: it writes to a temporary file
next to dst, verifies the bytes against the remote file's SHA-256, applies
the remote mode (or WithDownloadPermissions) and modification time, and
renames into place, so a failed transfer never leaves a truncated dst.
WithSkipUnchanged skips the transfer when dst already has the remote
file's size and modification time. Non-regular sources, including
symlinks, are rejected because the remote stat describes the link.

Refs #193

Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
The file now holds DownloadFile as well as Upload.

Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
@github-actions github-actions Bot added the additive-change Applied by the API diff workflow label Nov 19, 2026
@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Exported API changed by this pull request

Compared against d29782c.

This only adds exported API.

Compared for linux, windows, darwin. Entries read ./package.Symbol; the module root package is unprefixed.

Compatible changes (1):

- ./remotefs.DownloadFile: added

@kke
kke requested a balanced review from Copilot November 19, 2026 08:02
@kke kke changed the title feat(remotefs): add DownloadFile for remote-to-local copies feat(remotefs): add DownloadFile helper for fetching remote files Nov 19, 2026
@kke kke changed the title feat(remotefs): add DownloadFile helper for fetching remote files feat(remotefs): add DownloadFile helper to fetch files from hosts Nov 19, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Windows downloads fail because checksumming reopens an exclusively held source handle, and Windows file-info handling fails to identify symbolic links, bypassing their required rejection.

2 open issues
What changed in this PR

Adds remotefs.DownloadFile as the remote-to-local counterpart of Upload, addressing single-file downloads requested in #193 and #194. Directory transfers remain out of scope.

Changes:

  • Adds temporary-file downloads with SHA-256 verification and rename into place.
  • Supports remote permissions and modification times, permission overrides, and skipping unchanged files.
  • Consolidates transfer code and adds download tests and a usage example.
File Description
remotefs/​upload.go Moves existing upload implementation to transfer.go.
remotefs/​transfer.go Houses uploads and introduces download functionality and options.
remotefs/​transfer_test.go Tests downloads, metadata, replacement, failures, and skip behavior.
README.md Adds a download example alongside upload usage.

Review effort: Balanced

Comment thread remotefs/transfer.go Resolved
Comment thread remotefs/transfer.go Resolved
…ymlinks

The Windows file daemon opens files without sharing, so WinFS.Sha256
failed with a sharing violation while DownloadFile still held the
source open. Close it, checking the error, before the checksum.

winFileInfo never set fs.ModeSymlink, so DownloadFile's symlink
rejection did not hold on Windows hosts. Stat and ReadDir now fetch
LinkType and Mode reports SymbolicLink entries as links.

Drop WithSkipUnchanged and WithDownloadPermissions: Upload has no skip
either, and DownloadFile now takes UploadOption so WithPermissions
serves both.

Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
@kke
kke requested a balanced review from Copilot November 19, 2026 08:20

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The download path strips setuid, setgid, and sticky bits via Perm(), violating the promised source-mode preservation.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Medium severity Preserve special permission bits when downloading files

remotefs/​transfer.go:168

For a remote file with setuid, setgid, or sticky bits, Perm() silently strips those bits, so the default download does not preserve the source mode promised by DownloadFile and WithPermissions. Upload preserves the full source mode. Since non-regular files have already been rejected, retain stat.Mode() here so the subsequent chmod can preserve these bits too.

2 resolved since last review

Review effort: Balanced

@kke
kke merged commit 271ac3b into main Nov 19, 2026
18 checks passed
@kke
kke deleted the feat/remotefs-download-file branch November 19, 2026 10:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

additive-change Applied by the API diff workflow

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants