fix: event callback

This commit is contained in:
Samuel N Cui
2023-09-22 21:12:07 +08:00
parent 6a58412a3d
commit d206218634
4 changed files with 18 additions and 4 deletions
+7
View File
@@ -14,6 +14,7 @@ import (
"time"
mapset "github.com/deckarep/golang-set/v2"
"github.com/samber/lo"
"github.com/samuelncui/acp"
"github.com/samuelncui/tapewriter/entity"
"github.com/samuelncui/tapewriter/library"
@@ -230,6 +231,12 @@ func (a *jobArchiveExecutor) makeTape(ctx context.Context, device, barcode, name
idx := sort.Search(len(a.state.Sources), func(idx int) bool {
return src.Compare(a.state.Sources[idx].Source) <= 0
})
if idx < 0 {
a.logger.Warnf(
"cannot found target file, real_path= %s tape_file_path= %v", src.RealPath(),
lo.Map(a.state.Sources, func(source *entity.SourceState, _ int) string { return source.Source.RealPath() }))
return
}
target := a.state.Sources[idx]
if target == nil || !src.Equal(target.Source) {
+8 -1
View File
@@ -90,6 +90,7 @@ func (a *jobRestoreExecutor) handle(ctx context.Context, param *entity.JobRestor
tools.Working()
go tools.WrapWithLogger(ctx, a.logger, func() {
defer tools.Done()
if err := a.restoreTape(tools.ShutdownContext, p.Device); err != nil {
a.logger.WithContext(ctx).WithError(err).Errorf("restore tape has error, device= '%s'", p.Device)
}
@@ -207,7 +208,7 @@ func (a *jobRestoreExecutor) restoreTape(ctx context.Context, device string) (re
}
}()
opts := make([]acp.Option, 0, 4)
opts := make([]acp.Option, 0, 16)
for _, f := range restoreTape.Files {
if f.Status == entity.CopyStatus_SUBMITED {
continue
@@ -272,6 +273,12 @@ func (a *jobRestoreExecutor) restoreTape(ctx context.Context, device string) (re
idx := sort.Search(len(restoreTape.Files), func(idx int) bool {
return convertPath(realPath) < convertPath(sourcePath(restoreTape.Files[idx].TapePath))
})
if idx < 0 {
a.logger.Warnf(
"cannot found target file, real_path= %s tape_file_path= %v", realPath,
lo.Map(restoreTape.Files, func(file *entity.RestoreFile, _ int) string { return sourcePath(file.TapePath) }))
return
}
target := restoreTape.Files[idx]
if target == nil || realPath != sourcePath(target.TapePath) {