fix: replace string slicing with filepath.Dir() in gRPC file sync

- Fix directory path calculation bug in downloadFileGRPC()
- Bug caused nested directory creation to fail (e.g., crawlab_project/spiders/)
- String slicing incorrectly truncated paths mid-character
- Now uses filepath.Dir() for correct parent directory extraction
- Fixes 'no such file or directory' errors during worker file sync
- Resolves spider task failures on worker nodes after gRPC migration

Validated by: REL-004, REL-005 test cases
This commit is contained in:
Marvin Zhang
2025-10-30 15:22:53 +08:00
parent bd99899182
commit 18c5eb3956

View File

@@ -5,6 +5,7 @@ import (
"fmt"
"io"
"os"
"path/filepath"
"time"
"github.com/crawlab-team/crawlab/core/entity"
@@ -185,7 +186,7 @@ func (r *Runner) downloadFileGRPC(client grpc2.SyncServiceClient, spiderId, path
targetPath := fmt.Sprintf("%s/%s", r.cwd, path)
// Create directory if not exists
targetDir := targetPath[:len(targetPath)-len(path)]
targetDir := filepath.Dir(targetPath)
if err := os.MkdirAll(targetDir, os.ModePerm); err != nil {
return fmt.Errorf("failed to create directory: %w", err)
}