-
Notifications
You must be signed in to change notification settings - Fork 0
Pack #10
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR introduces packing/unpacking functionality for directories and adds a read-only archive-based cache implementation. However, the code contains several critical bugs that prevent compilation and correct execution.
Key changes:
- Added
internal/packpackage with ZIP compression and decompression functions - Added
internal/caches/archivepackage for read-only ZIP-backed cache - Updated documentation in
internal/caches/localto clarify cache compatibility
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 9 comments.
| File | Description |
|---|---|
| internal/pack/pack.go | New package providing Pack/Unpack functions for ZIP compression of directories, with resource leak issue and commented-out code |
| internal/caches/local/local.go | Documentation improvements clarifying compatibility with built-in cache |
| internal/caches/archive/archive.go | New read-only ZIP-backed cache implementation with multiple critical bugs (incomplete struct field, uninitialized fields, unused function call, missing return value) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| type Cache struct { | ||
| zr *zip.Reader | ||
| c io.Closer | ||
| d |
Copilot
AI
Dec 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incomplete field declaration. The field d has no type specified, which will cause a compilation error.
|
|
||
| // Get implements [cache.Cache]. | ||
| func (c *Cache) Get(id cache.ActionID) (cache.Entry, error) { | ||
| return c.dc.Get(id) |
Copilot
AI
Dec 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Undefined field access. The field c.dc is accessed but never initialized in the New or Open functions, which will cause a nil pointer dereference at runtime.
| dst.Close() | ||
| if err != nil { | ||
| resErr = lazyerrors.Error(err) | ||
| return | ||
| } |
Copilot
AI
Dec 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resource leak on error path. If f.Open() succeeds but an error is returned, the dst file handle is closed but its error is ignored. Consider checking the close error or using a deferred close with proper error handling.
| dst.Close() | |
| if err != nil { | |
| resErr = lazyerrors.Error(err) | |
| return | |
| } | |
| closeErr := dst.Close() | |
| if err != nil { | |
| resErr = lazyerrors.Error(err) | |
| return | |
| } | |
| if closeErr != nil && resErr == nil { | |
| resErr = lazyerrors.Error(closeErr) | |
| return | |
| } |
| }, nil | ||
| } | ||
|
|
||
| func Open(file string, l *slog.Logger) (*Cache, error) { |
Copilot
AI
Dec 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Function naming inconsistency. The function Open should be named consistently with Go conventions, such as OpenFile or NewFromFile, to clearly indicate it opens a cache from a file path. Additionally, it should have a documentation comment explaining its purpose.
| func Open(file string, l *slog.Logger) (*Cache, error) { | |
| // OpenFile opens a read-only Cache backed by a zip archive at the given file path. | |
| func OpenFile(file string, l *slog.Logger) (*Cache, error) { |
| l: l, | ||
| }, nil | ||
| } | ||
|
|
Copilot
AI
Dec 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing documentation. The exported function Open lacks a documentation comment, which is required for all exported identifiers in Go.
| // Open opens a zip archive file and returns a new [Cache]. |
| return nil, lazyerrors.Error(err) | ||
| } | ||
|
|
||
| os.CreateTemp() |
Copilot
AI
Dec 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused function call. os.CreateTemp() is called but its return values are ignored and the created temporary file is never used or cleaned up. This will create a resource leak.
| os.CreateTemp() |
|
|
||
| // OutputFile implements [cache.Cache]. | ||
| func (c *Cache) OutputFile(id cache.OutputID) string { | ||
| return c.dc.OutputFile(id) |
Copilot
AI
Dec 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Undefined field access. The field c.dc is accessed but never initialized in the New or Open functions, which will cause a nil pointer dereference at runtime.
|
|
||
| // FuzzDir implements [cache.Cache]. | ||
| func (c *Cache) FuzzDir() string { | ||
| return |
Copilot
AI
Dec 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Empty return value. The function should return a string representing the fuzz directory, but returns an empty value instead.
| return | |
| return "" |
| // err = root.MkdirAll(fp[:len(fp)-len(f.FileInfo().Name())], 0o755) | ||
| // if err != nil { | ||
| // resErr = lazyerrors.Error(err) | ||
| // return | ||
| // } | ||
|
|
Copilot
AI
Dec 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commented-out code should be removed. This block of code for creating parent directories appears to be incomplete work that should either be implemented or removed before merging.
| // err = root.MkdirAll(fp[:len(fp)-len(f.FileInfo().Name())], 0o755) | |
| // if err != nil { | |
| // resErr = lazyerrors.Error(err) | |
| // return | |
| // } |
No description provided.