diff --git a/README.md b/README.md index 7ac7fef..d818da3 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ jobs: run: hugo --minify --environment production - name: Deploy - uses: her-cat/upyun-deployer@v1.0.2 + uses: her-cat/upyun-deployer@v1.0.3 with: bucket: ${{ secrets.UPYUN_BUCKET }} operator: ${{ secrets.UPYUN_OPERATOR_NAME }} diff --git a/main.go b/main.go index 2111ea9..2a4ab43 100644 --- a/main.go +++ b/main.go @@ -25,6 +25,8 @@ type UpYunDeployer struct { publishDir string } +var taskQueue = make(chan struct{}, 100) + func (d *UpYunDeployer) GetAllRemoteFiles() (map[string]int, map[string]int) { return d.GetAllRemoteFilesByPath("/") } @@ -64,6 +66,10 @@ func (d *UpYunDeployer) GetAllRemoteFilesByPath(path string) (map[string]int, ma continue } + if _, exists := directories[obj.Name]; exists { + continue + } + directories[obj.Name] = depth go d.listDirs(obj.Name, objsChan) counter++ @@ -310,12 +316,14 @@ func (d *UpYunDeployer) deleteFile(path string, async bool) error { return err } -func (d UpYunDeployer) listDirs(path string, ch chan *upyun.FileInfo) { +func (d *UpYunDeployer) listDirs(path string, ch chan *upyun.FileInfo) { + taskQueue <- struct{}{} objsChan := make(chan *upyun.FileInfo) go func() { err := d.up.List(&upyun.GetObjectsConfig{ - Path: path, - ObjectsChan: objsChan, + Path: path, + ObjectsChan: objsChan, + MaxListTries: 3, Headers: map[string]string{ "X-List-Limit": "10000", }, @@ -323,6 +331,10 @@ func (d UpYunDeployer) listDirs(path string, ch chan *upyun.FileInfo) { if err != nil { fmt.Printf("[%s] list dirs failed: %v\n", path, err) } + + defer func() { + <-taskQueue + }() }() for obj := range objsChan {