mirror of
https://github.com/samuelncui/yatm.git
synced 2026-01-08 06:15:54 +00:00
fix: restore result report
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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...))
|
||||
|
||||
@@ -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>
|
||||
);
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user