mirror of
https://github.com/crawlab-team/crawlab.git
synced 2026-01-21 17:21:09 +01:00
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:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user