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

bk-booster -af支持目录 #106 #107

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions src/backend/booster/bk_dist/booster/pkg/booster.go
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,15 @@ func (b *Booster) sendAdditionFile() {
return
}

c, _ := os.Getwd()
for i, f := range b.config.Works.AdditionFiles {
if !filepath.IsAbs(f) {
b.config.Works.AdditionFiles[i] = filepath.Join(c, f)
}
}

b.parseDir()

fds := make([]dcSDK.FileDesc, 0, 100)
for _, f := range b.config.Works.AdditionFiles {
info := dcFile.Stat(f)
Expand Down Expand Up @@ -654,6 +663,47 @@ func (b *Booster) sendAdditionFile() {
blog.Infof("booster: finish send addition files: %v", b.config.Works.AdditionFiles)
}

func (b *Booster) parseDir() {
res := []string{}
dir := []string{}
for _, f := range b.config.Works.AdditionFiles {
isSubdir := false
for _, d := range dir {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果 b.config.Works.AdditionFiles 数组中,子目录在前面,那这个循环子目录就去不掉

if strings.HasPrefix(f, d) {
isSubdir = true
blog.Infof("booster: get aditonal file, dir(%s) is subdir of (%s), skip", f, d)
break
}
}
if isSubdir {
continue
}

info := dcFile.Stat(f)
if info.Basic().IsDir() {
err := filepath.Walk(f, func(path string, info os.FileInfo, err error) error {
if err != nil {
blog.Warnf("parse path %s failed: %v\n", path, err)
return err
}

if !info.IsDir() {
res = append(res, path)
blog.Debugf("booster: get file(%s) from dir(%s)", path, f)
}

return nil
})
if err != nil {
blog.Warnf("booster: parse dir(%s) in addition files failed:%v", f, err)
continue
}
dir = append(dir, f)
}
}
b.config.Works.AdditionFiles = append(b.config.Works.AdditionFiles, res...)
}

func (b *Booster) runWorks(
ctx context.Context,
_ *TaskEvent,
Expand Down
Loading