From 18c5eb3956d6d884234a2478124e8aa8ea8b6dcb Mon Sep 17 00:00:00 2001 From: Marvin Zhang Date: Thu, 30 Oct 2025 15:22:53 +0800 Subject: [PATCH] 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 --- core/task/handler/runner_sync_grpc.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/task/handler/runner_sync_grpc.go b/core/task/handler/runner_sync_grpc.go index bfc59e14..f39c41af 100644 --- a/core/task/handler/runner_sync_grpc.go +++ b/core/task/handler/runner_sync_grpc.go @@ -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) }