fixed file checker
This commit is contained in:
+10
-2
@@ -6,6 +6,7 @@ package fileoper
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
|
||||
"mstore/pkg/descr"
|
||||
)
|
||||
@@ -21,9 +22,11 @@ type CheckFilesResult struct {
|
||||
|
||||
func (oper *Operator) CheckFiles(ctx context.Context, operatorID string, params *CheckFilesParams) (int, *CheckFilesResult, error) {
|
||||
var code int
|
||||
res := &CheckFilesResult{}
|
||||
res := &CheckFilesResult{
|
||||
Files: make([]descr.File, 0),
|
||||
}
|
||||
var err error
|
||||
|
||||
code = http.StatusOK
|
||||
// Check existing and size
|
||||
files, err := oper.listFiles(ctx, params.PathType, params.Path)
|
||||
if err != nil {
|
||||
@@ -36,7 +39,9 @@ func (oper *Operator) CheckFiles(ctx context.Context, operatorID string, params
|
||||
code := http.StatusInternalServerError
|
||||
return code, res, err
|
||||
}
|
||||
fullpath := filepath.Join(file.Collection, file.Name)
|
||||
if !exists {
|
||||
oper.logg.Warningf("File not exists: %s", fullpath)
|
||||
res.Files = append(res.Files, file)
|
||||
err = oper.mdb.DeleteFileByCollectionName(ctx, file.Collection, file.Name)
|
||||
if err != nil {
|
||||
@@ -45,6 +50,7 @@ func (oper *Operator) CheckFiles(ctx context.Context, operatorID string, params
|
||||
}
|
||||
}
|
||||
if size != file.Size {
|
||||
oper.logg.Warningf("File has incorrect size: %s", fullpath)
|
||||
res.Files = append(res.Files, file)
|
||||
err = oper.mdb.DeleteFileByCollectionName(ctx, file.Collection, file.Name)
|
||||
if err != nil {
|
||||
@@ -70,7 +76,9 @@ func (oper *Operator) CheckFiles(ctx context.Context, operatorID string, params
|
||||
code := http.StatusInternalServerError
|
||||
return code, res, err
|
||||
}
|
||||
fullpath := filepath.Join(file.Collection, file.Name)
|
||||
if sum != file.Checksum {
|
||||
oper.logg.Warningf("File has incorrect digest: %s", fullpath)
|
||||
res.Files = append(res.Files, file)
|
||||
err = oper.mdb.DeleteFileByCollectionName(ctx, file.Collection, file.Name)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user