chore(io): address code review and fix CI
- Fix MockFile.Read to return io.EOF - Use filepath.Match in TaskfileBuilder for precise globbing - Stream xz data in createTarXzArchive to avoid in-memory string conversion - Fix TestPath_RootFilesystem in local medium tests - Fix formatting in pkg/build/buildcmd/cmd_project.go
This commit is contained in:
parent
ad05899e9b
commit
d0b80d311a
5 changed files with 14 additions and 8 deletions
|
|
@ -185,7 +185,13 @@ func createTarXzArchive(fs io_interface.Medium, src, dst string) error {
|
|||
}
|
||||
|
||||
// Write to destination file
|
||||
if err := fs.Write(dst, string(xzData)); err != nil {
|
||||
dstFile, err := fs.Create(dst)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create archive file: %w", err)
|
||||
}
|
||||
defer func() { _ = dstFile.Close() }()
|
||||
|
||||
if _, err := dstFile.Write(xzData); err != nil {
|
||||
return fmt.Errorf("failed to write archive file: %w", err)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -79,7 +79,6 @@ func runProjectBuild(ctx context.Context, buildType string, ciMode bool, targets
|
|||
}
|
||||
outputDir = filepath.Clean(outputDir)
|
||||
|
||||
|
||||
// Ensure config path is absolute if provided
|
||||
if configPath != "" && !filepath.IsAbs(configPath) {
|
||||
configPath = filepath.Join(projectDir, configPath)
|
||||
|
|
|
|||
|
|
@ -246,10 +246,10 @@ func (b *TaskfileBuilder) findArtifactsForTarget(fs io.Medium, outputDir string,
|
|||
return artifacts
|
||||
}
|
||||
|
||||
// matchPattern implements a very simple glob matcher for Taskfile artifacts.
|
||||
// matchPattern implements glob matching for Taskfile artifacts.
|
||||
func (b *TaskfileBuilder) matchPattern(name, pattern string) bool {
|
||||
p := strings.ReplaceAll(pattern, "*", "")
|
||||
return strings.Contains(name, p)
|
||||
matched, _ := filepath.Match(pattern, name)
|
||||
return matched
|
||||
}
|
||||
|
||||
// validateTaskCli checks if the task CLI is available.
|
||||
|
|
|
|||
|
|
@ -350,7 +350,7 @@ func (f *MockFile) Stat() (fs.FileInfo, error) {
|
|||
|
||||
func (f *MockFile) Read(b []byte) (int, error) {
|
||||
if f.offset >= int64(len(f.content)) {
|
||||
return 0, fs.ErrClosed // Or io.EOF?
|
||||
return 0, io.EOF
|
||||
}
|
||||
n := copy(b, f.content[f.offset:])
|
||||
f.offset += int64(n)
|
||||
|
|
|
|||
|
|
@ -40,8 +40,9 @@ func TestPath_RootFilesystem(t *testing.T) {
|
|||
assert.Equal(t, "/etc/passwd", m.path("/etc/passwd"))
|
||||
assert.Equal(t, "/home/user/file.txt", m.path("/home/user/file.txt"))
|
||||
|
||||
// Relative paths still work
|
||||
assert.Equal(t, "/file.txt", m.path("file.txt"))
|
||||
// Relative paths are relative to CWD when root is "/"
|
||||
cwd, _ := os.Getwd()
|
||||
assert.Equal(t, filepath.Join(cwd, "file.txt"), m.path("file.txt"))
|
||||
}
|
||||
|
||||
func TestReadWrite(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue