Skip to content

Commit

Permalink
feat: 解决获取远程文件列表失败问题
Browse files Browse the repository at this point in the history
  • Loading branch information
her-cat committed Dec 30, 2023
1 parent bc580cb commit 4bb5a3c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
run: hugo --minify --environment production

- name: Deploy
uses: her-cat/[email protected].2
uses: her-cat/[email protected].3
with:
bucket: ${{ secrets.UPYUN_BUCKET }}
operator: ${{ secrets.UPYUN_OPERATOR_NAME }}
Expand Down
18 changes: 15 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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("/")
}
Expand Down Expand Up @@ -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++
Expand Down Expand Up @@ -310,19 +316,25 @@ 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",
},
})
if err != nil {
fmt.Printf("[%s] list dirs failed: %v\n", path, err)
}

defer func() {
<-taskQueue
}()
}()

for obj := range objsChan {
Expand Down

0 comments on commit 4bb5a3c

Please sign in to comment.