cgroups/fscommon: use errors.Is

This is a forgotten hunk from PR #2291.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
Kir Kolyshkin 2020-04-18 16:15:11 -07:00
parent af6b9e7fa9
commit 58f970a01f
1 changed files with 2 additions and 12 deletions

View File

@ -5,11 +5,11 @@ package fscommon
import ( import (
"io/ioutil" "io/ioutil"
"os" "os"
"syscall"
securejoin "github.com/cyphar/filepath-securejoin" securejoin "github.com/cyphar/filepath-securejoin"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"golang.org/x/sys/unix"
) )
func WriteFile(dir, file, data string) error { func WriteFile(dir, file, data string) error {
@ -41,20 +41,10 @@ func ReadFile(dir, file string) (string, error) {
func retryingWriteFile(filename string, data []byte, perm os.FileMode) error { func retryingWriteFile(filename string, data []byte, perm os.FileMode) error {
for { for {
err := ioutil.WriteFile(filename, data, perm) err := ioutil.WriteFile(filename, data, perm)
if isInterruptedWriteFile(err) { if errors.Is(err, unix.EINTR) {
logrus.Infof("interrupted while writing %s to %s", string(data), filename) logrus.Infof("interrupted while writing %s to %s", string(data), filename)
continue continue
} }
return err return err
} }
} }
func isInterruptedWriteFile(err error) bool {
if patherr, ok := err.(*os.PathError); ok {
errno, ok2 := patherr.Err.(syscall.Errno)
if ok2 && errno == syscall.EINTR {
return true
}
}
return false
}