Conversation
Add a text-only check using the same heuristic as Git (NUL byte detection in the first 8KB). Binary files are rejected with ErrBinaryFile. Non-existent files are still allowed through.
- Use io.EOF instead of string comparison for EOF check - Use bytes.IndexByte instead of bytes.ContainsRune for NUL detection - Check for duplicate files before binary check to avoid unnecessary I/O
- Use errors.Is(err, io.EOF) instead of direct comparison - Check AddFile error return values in tests
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Pull request overview
This PR adds binary-file detection to the Go server’s AddFile path so non-text files can be rejected early (using Git’s “NUL byte in first 8KB” heuristic), and updates callers/tests to handle the new error-returning API.
Changes:
- Introduce
ErrBinaryFile, anisBinaryFilehelper, and changeState.AddFileto return(*FileEntry, error). - Update CLI/server entry points (glob expansion, HTTP endpoints, startup) to handle
AddFileerrors and skip/log when appropriate. - Update server tests to use temp files and add coverage for binary rejection + non-existent path behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
internal/server/server.go |
Adds binary detection + error-returning AddFile; updates pattern/glob + HTTP handlers to handle errors. |
cmd/root.go |
Updates server startup file loading to handle AddFile errors (skip + warn). |
internal/server/server_test.go |
Updates existing backup tests to use temp files; adds a test for binary rejection and non-existent file behavior. |
You can also share your feedback on Copilot code review. Take the survey.
Reorder checks so non-EOF errors (e.g. EISDIR for directories) are returned even when n==0, instead of silently passing the binary check.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
You can also share your feedback on Copilot code review. Take the survey.
- Fix import sort order to pass gofmt - Error when all CLI-specified files are skipped - Add handler-level tests for POST /_/api/files with binary/text files
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
You can also share your feedback on Copilot code review. Take the survey.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
You can also share your feedback on Copilot code review. Take the survey.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
You can also share your feedback on Copilot code review. Take the survey.
Stat the path before opening to ensure it is a regular file. This prevents blocking reads on FIFOs, device files, and sockets.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
You can also share your feedback on Copilot code review. Take the survey.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
You can also share your feedback on Copilot code review. Take the survey.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
You can also share your feedback on Copilot code review. Take the survey.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
You can also share your feedback on Copilot code review. Take the survey.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
You can also share your feedback on Copilot code review. Take the survey.
Code Metrics Report
Details | | main (b91e1b2) | #107 (71cfe54) | +/- |
|---------------------|----------------|----------------|-------|
+ | Coverage | 51.5% | 52.1% | +0.6% |
| Files | 36 | 36 | 0 |
| Lines | 2819 | 2886 | +67 |
+ | Covered | 1454 | 1506 | +52 |
- | Code to Test Ratio | 1:0.5 | 1:0.5 | -0.1 |
| Code | 4363 | 4427 | +64 |
+ | Test | 2589 | 2590 | +1 |
+ | Test Execution Time | 37s | 36s | -1s |Code coverage of files in pull request scope (50.2% → 51.2%)
Reported by octocov |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
You can also share your feedback on Copilot code review. Take the survey.
Summary
AddFileusing Git's NUL byte detection heuristic (first 8KB)ErrBinaryFile; non-regular files (FIFO, device, socket) are also rejectedPOST /_/api/files,POST /_/api/files/open) still validate file existence viaos.Statbefore callingAddFileAddFilecheck