Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

重复上传爬虫bug #603

Closed
760363357 opened this issue Mar 1, 2020 · 4 comments
Closed

重复上传爬虫bug #603

760363357 opened this issue Mar 1, 2020 · 4 comments
Labels
bug Something isn't working

Comments

@760363357
Copy link

版本:0.4.7(最新的master也会存在这个问题)
文件路径: crawlab/backend/routes/spider.go
函数名称:UploadSpider
代码开始行数: 265
代码片段:
if spider.Name == "" { // 保存爬虫信息 srcPath := viper.GetString("spider.path") spider := model.Spider{ Name: spiderName, DisplayName: spiderName, Type: constants.Customized, Src: filepath.Join(srcPath, spiderName), FileId: fid, } if name != "" { spider.Name = name } if displayName != "" { spider.DisplayName = displayName } if col != "" { spider.Col = col } if cmd != "" { spider.Cmd = cmd } if err := spider.Add(); err != nil { log.Error("add spider error: " + err.Error()) debug.PrintStack() HandleError(http.StatusInternalServerError, c, err) return } } else { if name != "" { spider.Name = name } if displayName != "" { spider.DisplayName = displayName } if col != "" { spider.Col = col } if cmd != "" { spider.Cmd = cmd } // 更新file_id spider.FileId = fid if err := spider.Add(); err != nil { log.Error("add spider error: " + err.Error()) debug.PrintStack() HandleError(http.StatusInternalServerError, c, err) return } }

在该代码中找不到spider name是增加爬虫没错,但是找到了也是增加爬虫,这逻辑是不是有问题, 是不是应该将else里面到spider.Add()改成spider.Save()

这个问题会导致在新版本中上传两次相同的爬虫名会增加同样的爬虫而不是更新

@760363357 760363357 added the bug Something isn't working label Mar 1, 2020
@tikazyq
Copy link
Collaborator

tikazyq commented Mar 2, 2020

把代码地址发一下

@760363357
Copy link
Author

把代码地址发一下

什么代码地址,就是crawlab的master分支上的代码啊

@tikazyq
Copy link
Collaborator

tikazyq commented Mar 2, 2020

不好意思,没看到前面的描述。

这里确实可能出现问题。我们讨论一下看看。同时,您也可以提一个PR到develop分支

@tikazyq
Copy link
Collaborator

tikazyq commented Mar 11, 2020

fixed in develop

@tikazyq tikazyq closed this as completed Mar 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants