2024-09-26 11:33:03 +02:00
|
|
|
package archiver
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
)
|
|
|
|
|
|
|
|
func NewErrorOnlyArchiver(conf *Config) func(string, error) {
|
|
|
|
return func(filePath string, archiveErr error) {
|
|
|
|
if archiveErr != nil {
|
|
|
|
err := writeErrorFile(conf, filePath, archiveErr)
|
2024-10-26 19:13:32 +02:00
|
|
|
if err != nil {
|
|
|
|
logger.Error(err)
|
|
|
|
}
|
2024-09-26 11:33:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func writeErrorFile(conf *Config, filePath string, archiveErr error) error {
|
|
|
|
if archiveErr != nil {
|
|
|
|
baseName := filepath.Base(filePath)
|
|
|
|
|
|
|
|
destFolder := getDestFolder(conf, ErrorFolder)
|
|
|
|
globDir := extractGlobbedDir(conf.Folder, filePath)
|
|
|
|
if globDir != "" {
|
|
|
|
destFolder = filepath.Join(destFolder, globDir)
|
|
|
|
}
|
|
|
|
|
|
|
|
err := os.MkdirAll(destFolder, os.ModePerm)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
f, err := os.OpenFile(filepath.Join(destFolder, baseName+".err"), os.O_WRONLY|os.O_CREATE|os.O_APPEND, os.ModePerm)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer f.Close()
|
|
|
|
_, err = f.Write([]byte(archiveErr.Error() + "\n"))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|