Skip to content

Commit

Permalink
fix: fix hz gen file permission (#1262)
Browse files Browse the repository at this point in the history
  • Loading branch information
HeyJavaBean authored Jan 22, 2025
1 parent 02dd68f commit 240d401
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
12 changes: 5 additions & 7 deletions cmd/hz/generator/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,15 +247,13 @@ func (tg *TemplateGenerator) Persist() error {
}

err = func() error {
file, err := os.OpenFile(abPath, os.O_CREATE|os.O_TRUNC|os.O_RDWR, os.FileMode(0o755))
defer file.Close()
if err != nil {
return fmt.Errorf("open file '%s' failed, err: %v", abPath, err.Error())
fileMode := os.FileMode(0o644)
if strings.HasSuffix(abPath, ".sh") {
fileMode = os.FileMode(0o755)
}
if _, err = file.WriteString(data.Content); err != nil {
return fmt.Errorf("write file '%s' failed, err: %v", abPath, err.Error())
if err := os.WriteFile(abPath, []byte(data.Content), fileMode); err != nil {
return fmt.Errorf("write file '%s' failed, err: %v", abPath, err)
}

return nil
}()
if err != nil {
Expand Down
9 changes: 7 additions & 2 deletions cmd/hz/test_hz_unix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,20 @@ compile_hz() {
judge_exit "$?"
}


PATH_BIN=$PWD/bin
mkdir -p $PATH_BIN
export PATH=$PATH_BIN:$PATH

install_dependent_tools() {
# install thriftgo
go install github.com/cloudwego/thriftgo@latest

# install protoc
wget https://github.com/protocolbuffers/protobuf/releases/download/v3.19.4/protoc-3.19.4-linux-x86_64.zip
unzip -d protoc-3.19.4-linux-x86_64 protoc-3.19.4-linux-x86_64.zip
cp protoc-3.19.4-linux-x86_64/bin/protoc /usr/local/bin/protoc
cp -r protoc-3.19.4-linux-x86_64/include/google /usr/local/include/google
cp protoc-3.19.4-linux-x86_64/bin/protoc $PATH_BIN
cp -r protoc-3.19.4-linux-x86_64/include/google $PATH_BIN
}

test_thrift() {
Expand Down

0 comments on commit 240d401

Please sign in to comment.