fix: restore result report

This commit is contained in:
Samuel N Cui
2023-09-22 23:14:58 +08:00
parent d206218634
commit eeb0f4f7bf
4 changed files with 31 additions and 17 deletions

View File

@@ -231,9 +231,9 @@ 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 {
if idx < 0 || idx >= len(a.state.Sources) || src.Compare(a.state.Sources[idx].Source) != 0 {
a.logger.Warnf(
"cannot found target file, real_path= %s tape_file_path= %v", src.RealPath(),
"cannot found target file, real_path= %s found_index= %d tape_file_path= %v", src.RealPath(), idx,
lo.Map(a.state.Sources, func(source *entity.SourceState, _ int) string { return source.Source.RealPath() }))
return
}

View File

@@ -252,7 +252,7 @@ func (a *jobRestoreExecutor) restoreTape(ctx context.Context, device string) (re
a.logger.WithContext(ctx).Infof("file '%s' copy finished, size= %d", src.RealPath(), job.Size)
targetStatus = entity.CopyStatus_SUBMITED
if len(job.SuccessTargets) > 0 {
if len(job.FailTargets) > 0 {
targetStatus = entity.CopyStatus_FAILED
}
@@ -271,20 +271,25 @@ func (a *jobRestoreExecutor) restoreTape(ctx context.Context, device string) (re
realPath := src.RealPath()
idx := sort.Search(len(restoreTape.Files), func(idx int) bool {
return convertPath(realPath) < convertPath(sourcePath(restoreTape.Files[idx].TapePath))
return convertPath(realPath) <= convertPath(sourcePath(restoreTape.Files[idx].TapePath))
})
if idx < 0 {
if idx < 0 || idx >= len(restoreTape.Files) {
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) }))
"cannot found target file, real_path= %s found_index= %d tape_file_path= %v", realPath, idx,
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) {
targetFile := restoreTape.Files[idx]
if targetFile == nil || realPath != sourcePath(targetFile.TapePath) {
a.logger.Warnf(
"cannot match target file, real_path= %s found_index= %d found_file_path= %s",
realPath, idx, sourcePath(targetFile.TapePath),
)
return
}
target.Status = targetStatus
targetFile.Status = targetStatus
if _, err := a.exe.SaveJob(ctx, a.job); err != nil {
logrus.WithContext(ctx).Infof("save job for update file fail, name= %s", job.Base+path.Join(job.Path...))

View File

@@ -339,7 +339,14 @@ const RestoreViewFilesDialog = ({ tapes }: { tapes: RestoreTape[] }) => {
return (
<TreeItem label={tape.barcode} nodeId={`tape-${tape.tapeId}`}>
{tape.files.map((file) => (
<TreeItem label={file.tapePath} nodeId={`file-${file.positionId}`} />
<TreeItem
label={
<pre style={{ margin: 0 }}>
{file.tapePath} <b>{CopyStatus[file.status]}</b>
</pre>
}
nodeId={`file-${file.positionId}`}
/>
))}
</TreeItem>
);

View File

@@ -1,15 +1,17 @@
package tools
func Cache[i comparable, o any](f func(in i) o) func(in i) o {
cache := make(map[i]o, 0)
return func(in i) o {
cached, has := cache[in]
import "sync"
func Cache[K comparable, V any](f func(in K) V) func(in K) V {
cache := new(sync.Map)
return func(in K) V {
cached, has := cache.Load(in)
if has {
return cached
return cached.(V)
}
out := f(in)
cache[in] = out
cache.Store(in, out)
return out
}
}