diff options
Diffstat (limited to '')
-rw-r--r-- | git_hooks_deploy.go | 21 |
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 } } |