Quality improvements: Remove dead code, add unit tests, fix ignored errors
HIGH PRIORITY FIXES: 1. Remove unused progressCallback mechanism (dead code cleanup) 2. Add unit tests for restore package (formats, safety checks) - Test coverage for archive format detection - Test coverage for safety validation - Added NullLogger for testing 3. Fix ignored errors in backup pipeline - Handle StdoutPipe() errors properly - Log stderr pipe errors - Document CPU detection errors IMPROVEMENTS: - formats_test.go: 8 test functions, all passing - safety_test.go: 6 test functions for validation - logger/null.go: Test helper for unit tests - Proper error handling in streaming compression - Fixed indentation in stderr handling
This commit is contained in:
@ -600,7 +600,11 @@ func (e *Engine) executeMySQLWithCompression(ctx context.Context, cmdArgs []stri
|
||||
defer outFile.Close()
|
||||
|
||||
// Set up pipeline: mysqldump | gzip > outputfile
|
||||
gzipCmd.Stdin, _ = dumpCmd.StdoutPipe()
|
||||
stdin, err := dumpCmd.StdoutPipe()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create pipe: %w", err)
|
||||
}
|
||||
gzipCmd.Stdin = stdin
|
||||
gzipCmd.Stdout = outFile
|
||||
|
||||
// Start both commands
|
||||
@ -943,29 +947,39 @@ func (e *Engine) executeWithStreamingCompression(ctx context.Context, cmdArgs []
|
||||
compressCmd.Stdout = outFile
|
||||
|
||||
// Capture stderr from both commands
|
||||
dumpStderr, _ := dumpCmd.StderrPipe()
|
||||
compressStderr, _ := compressCmd.StderrPipe()
|
||||
dumpStderr, err := dumpCmd.StderrPipe()
|
||||
if err != nil {
|
||||
e.log.Warn("Failed to capture dump stderr", "error", err)
|
||||
}
|
||||
compressStderr, err := compressCmd.StderrPipe()
|
||||
if err != nil {
|
||||
e.log.Warn("Failed to capture compress stderr", "error", err)
|
||||
}
|
||||
|
||||
// Stream stderr output
|
||||
go func() {
|
||||
scanner := bufio.NewScanner(dumpStderr)
|
||||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
if line != "" {
|
||||
e.log.Debug("pg_dump", "output", line)
|
||||
if dumpStderr != nil {
|
||||
go func() {
|
||||
scanner := bufio.NewScanner(dumpStderr)
|
||||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
if line != "" {
|
||||
e.log.Debug("pg_dump", "output", line)
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
}()
|
||||
}
|
||||
|
||||
go func() {
|
||||
scanner := bufio.NewScanner(compressStderr)
|
||||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
if line != "" {
|
||||
e.log.Debug("compression", "output", line)
|
||||
if compressStderr != nil {
|
||||
go func() {
|
||||
scanner := bufio.NewScanner(compressStderr)
|
||||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
if line != "" {
|
||||
e.log.Debug("compression", "output", line)
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
}()
|
||||
}
|
||||
|
||||
// Start compression first
|
||||
if err := compressCmd.Start(); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user