aboutsummaryrefslogtreecommitdiff
path: root/git_hooks_deploy.go
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2025-03-05 08:51:17 +0800
committerRunxi Yu <me@runxiyu.org>2025-03-05 08:51:17 +0800
commit7c341685f878aa8fd4c49788cf8cc0d8c5c6e127 (patch)
tree5295f1f4020e85c065e98fcb88ec217ad66e078a /git_hooks_deploy.go
parentconfig: Add explanatory comments (diff)
downloadforge-7c341685f878aa8fd4c49788cf8cc0d8c5c6e127.tar.gz
forge-7c341685f878aa8fd4c49788cf8cc0d8c5c6e127.tar.zst
forge-7c341685f878aa8fd4c49788cf8cc0d8c5c6e127.zip
*: Replace some := with var
Diffstat (limited to 'git_hooks_deploy.go')
-rw-r--r--git_hooks_deploy.go21
1 files changed, 10 insertions, 11 deletions
diff --git a/git_hooks_deploy.go b/git_hooks_deploy.go
index 99e5464..6acb54f 100644
--- a/git_hooks_deploy.go
+++ b/git_hooks_deploy.go
@@ -6,6 +6,7 @@ package main
import (
"errors"
"io"
+ "io/fs"
"os"
"path/filepath"
)
@@ -14,21 +15,21 @@ import (
// The git hooks client is expected to be embedded in resources_fs and must be
// pre-compiled during the build process; see the Makefile.
func deploy_hooks_to_filesystem() (err error) {
- err = func() error {
- src_fd, err := resources_fs.Open("git_hooks_client/git_hooks_client")
- if err != nil {
+ err = func() (err error) {
+ var src_fd fs.File
+ var dst_fd *os.File
+
+ if src_fd, err = resources_fs.Open("git_hooks_client/git_hooks_client"); err != nil {
return err
}
defer src_fd.Close()
- dst_fd, err := os.OpenFile(filepath.Join(config.Hooks.Execs, "git_hooks_client"), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o755)
- if err != nil {
+ if dst_fd, err = os.OpenFile(filepath.Join(config.Hooks.Execs, "git_hooks_client"), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o755); err != nil {
return err
}
defer dst_fd.Close()
- _, err = io.Copy(dst_fd, src_fd)
- if err != nil {
+ if _, err = io.Copy(dst_fd, src_fd); err != nil {
return err
}
@@ -40,16 +41,14 @@ func deploy_hooks_to_filesystem() (err error) {
// Go's embed filesystems do not store permissions; but in any case,
// they would need to be 0o755:
- err = os.Chmod(filepath.Join(config.Hooks.Execs, "git_hooks_client"), 0o755)
- if err != nil {
+ if err = os.Chmod(filepath.Join(config.Hooks.Execs, "git_hooks_client"), 0o755); err != nil {
return err
}
for _, hook_name := range []string{
"pre-receive",
} {
- err = os.Symlink(filepath.Join(config.Hooks.Execs, "git_hooks_client"), filepath.Join(config.Hooks.Execs, hook_name))
- if err != nil && !errors.Is(err, os.ErrExist) {
+ if err = os.Symlink(filepath.Join(config.Hooks.Execs, "git_hooks_client"), filepath.Join(config.Hooks.Execs, hook_name)); err != nil {
return err
}
}