From 913956ff10a17410c4d44db6a741c6ae228c8f68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B4=94=E7=AB=9E=E5=AE=81?= Date: Tue, 13 Dec 2022 13:45:00 +0800 Subject: [PATCH] fix: stop for no space --- acp.go | 8 ++++++++ copy.go | 18 ++++++++++++++---- report.go | 12 ++++++------ 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/acp.go b/acp.go index 51d9ef9..63811c1 100644 --- a/acp.go +++ b/acp.go @@ -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 } diff --git a/copy.go b/copy.go index 7844175..594a108 100644 --- a/copy.go +++ b/copy.go @@ -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) }() diff --git a/report.go b/report.go index c32eeda..c02c080 100644 --- a/report.go +++ b/report.go @@ -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()) }