mirror of
https://github.com/samuelncui/acp.git
synced 2026-08-16 10:56:01 +00:00
fix: stop for no space
This commit is contained in:
@@ -57,6 +57,14 @@ func (c *Copyer) run(ctx context.Context) error {
|
||||
copyed := c.copy(ctx, prepared)
|
||||
c.cleanupJob(ctx, copyed)
|
||||
|
||||
// empty pipes
|
||||
for range indexed {
|
||||
}
|
||||
for range prepared {
|
||||
}
|
||||
for range copyed {
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -130,12 +130,22 @@ func (c *Copyer) write(ctx context.Context, job *writeJob, ch chan<- *baseJob, c
|
||||
continue
|
||||
}
|
||||
if err := os.MkdirAll(path.Dir(name), os.ModePerm); err != nil {
|
||||
// if no space
|
||||
if errors.Is(err, syscall.ENOSPC) || errors.Is(err, syscall.EROFS) {
|
||||
badDsts.Add(dst)
|
||||
}
|
||||
|
||||
job.fail(name, fmt.Errorf("mkdir dst dir fail, %w", err))
|
||||
continue
|
||||
}
|
||||
|
||||
file, err := os.OpenFile(name, c.createFlag, job.mode)
|
||||
if err != nil {
|
||||
// if no space
|
||||
if errors.Is(err, syscall.ENOSPC) || errors.Is(err, syscall.EROFS) {
|
||||
badDsts.Add(dst)
|
||||
}
|
||||
|
||||
job.fail(name, fmt.Errorf("open dst file fail, %w", err))
|
||||
continue
|
||||
}
|
||||
@@ -158,15 +168,15 @@ func (c *Copyer) write(ctx context.Context, job *writeJob, ch chan<- *baseJob, c
|
||||
for range ch {
|
||||
}
|
||||
|
||||
if re := os.Remove(name); re != nil {
|
||||
rerr = multierror.Append(rerr, re)
|
||||
}
|
||||
|
||||
// if no space
|
||||
if errors.Is(err, syscall.ENOSPC) || errors.Is(err, syscall.EROFS) {
|
||||
badDsts.Add(dst)
|
||||
}
|
||||
|
||||
if re := os.Remove(name); re != nil {
|
||||
rerr = multierror.Append(rerr, re)
|
||||
}
|
||||
|
||||
c.reportError(job.source.src(), name, rerr)
|
||||
job.fail(name, rerr)
|
||||
}()
|
||||
|
||||
@@ -6,10 +6,8 @@ import (
|
||||
"sync"
|
||||
"unsafe"
|
||||
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/modern-go/reflect2"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type ReportGetter func() *Report
|
||||
@@ -76,19 +74,21 @@ var (
|
||||
type errValCoder struct{}
|
||||
|
||||
func (*errValCoder) IsEmpty(ptr unsafe.Pointer) bool {
|
||||
logrus.Infof("IsEmpty %s", spew.Sdump(ptr))
|
||||
val := (*error)(ptr)
|
||||
return *val == nil
|
||||
return val == nil || *val == nil || reflect2.IsNil(*val)
|
||||
}
|
||||
|
||||
func (*errValCoder) Encode(ptr unsafe.Pointer, stream *jsoniter.Stream) {
|
||||
logrus.Infof("Encode %s", spew.Sdump(ptr))
|
||||
val := (*error)(ptr)
|
||||
if val == nil || *val == nil {
|
||||
stream.WriteNil()
|
||||
return
|
||||
}
|
||||
|
||||
stream.WriteString((*val).Error())
|
||||
}
|
||||
|
||||
func (*errValCoder) Decode(ptr unsafe.Pointer, iter *jsoniter.Iterator) {
|
||||
logrus.Infof("Decode %s", spew.Sdump(ptr))
|
||||
val := (*error)(ptr)
|
||||
*val = fmt.Errorf(iter.ReadString())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user