From 7c341685f878aa8fd4c49788cf8cc0d8c5c6e127 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Wed, 5 Mar 2025 08:51:17 +0800 Subject: *: Replace some := with var --- git_hooks_deploy.go | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'git_hooks_deploy.go') 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 } } -- cgit v1.2.3