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 {
|
||||
|
||||
@@ -60,6 +60,7 @@ func NewServer() (*Server, error) {
|
||||
var err error
|
||||
srv := &Server{}
|
||||
srv.logg = logger.NewLoggerWithSubject("server")
|
||||
srv.ctx, srv.cancel = context.WithCancel(context.Background())
|
||||
return srv, err
|
||||
}
|
||||
|
||||
@@ -425,9 +426,7 @@ func (srv *Server) Run() error {
|
||||
}
|
||||
srv.logg.Infof("Server run with user: %s", usr.Username)
|
||||
|
||||
srv.ctx, srv.cancel = context.WithCancel(context.Background())
|
||||
svcDone := make(chan error, 1)
|
||||
|
||||
// Service run
|
||||
srv.logg.Infof("Start service")
|
||||
startService := func(svc *service.Service, done chan error) {
|
||||
|
||||
Reference in New Issue
Block a user