Skip to content
This repository has been archived by the owner on Jan 15, 2024. It is now read-only.

Commit

Permalink
Merge pull request #27 from nixys/fix
Browse files Browse the repository at this point in the history
Fix

* suppression of non-critical warnings
  • Loading branch information
Roman Andreev authored Jul 7, 2023
2 parents d3374c0 + 5923d01 commit 1f75363
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions modules/backend/targz/targz.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ import (
"os"
"os/exec"
"path"
"regexp"
)

const regexToIgnoreErr = "^tar:.*(Removing leading|socket ignored|file changed as we read it|Удаляется начальный|сокет проигнорирован|файл изменился во время чтения)"

type Error struct {
Err error
Stderr string
Expand Down Expand Up @@ -71,6 +74,7 @@ func Tar(src, dst string, incremental, gzip, saveAbsPath bool, excludes []string
args = append(args, "--exclude="+ex)

}
args = append(args, "--ignore-failed-read")
args = append(args, "--create")
args = append(args, "--file=-")
if saveAbsPath {
Expand All @@ -85,11 +89,28 @@ func Tar(src, dst string, incremental, gzip, saveAbsPath bool, excludes []string
cmd.Stderr = &stderr

if err = cmd.Run(); err != nil {
return Error{
Err: err,
Stderr: stderr.String(),
if cmd.ProcessState.ExitCode() == 2 || checkIsRealError(stderr.String()) {
return Error{
Err: err,
Stderr: stderr.String(),
}
}
}

return nil
}

func checkIsRealError(stderr string) bool {
realErr := false
reTar := regexp.MustCompile("^tar:.*\n")
reErr := regexp.MustCompile(regexToIgnoreErr)
strTupl := reTar.FindAllString(stderr, -1)
for _, s := range strTupl {
if match := reErr.MatchString(s); !match {
realErr = true
break
}
}

return realErr
}

0 comments on commit 1f75363

Please sign in to comment.