diff options
author | Runxi Yu <me@runxiyu.org> | 2025-04-06 01:55:21 +0800 |
---|---|---|
committer | Runxi Yu <me@runxiyu.org> | 2025-04-06 02:08:58 +0800 |
commit | faa5ca8fab23176d390e9522f1485d467851545b (patch) | |
tree | d3b1d081e0ea5e7f71a94dc1d301e2540a8abcc8 /internal/unsorted/ssh_handle_upload_pack.go | |
parent | Slight refactor on NewServer (diff) | |
download | forge-0.1.28.tar.gz forge-0.1.28.tar.zst forge-0.1.28.zip |
Move stuff into internal/unsortedv0.1.28
Diffstat (limited to 'internal/unsorted/ssh_handle_upload_pack.go')
-rw-r--r-- | internal/unsorted/ssh_handle_upload_pack.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/internal/unsorted/ssh_handle_upload_pack.go b/internal/unsorted/ssh_handle_upload_pack.go new file mode 100644 index 0000000..735a053 --- /dev/null +++ b/internal/unsorted/ssh_handle_upload_pack.go @@ -0,0 +1,39 @@ +// SPDX-License-Identifier: AGPL-3.0-only +// SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu <https://runxiyu.org> + +package unsorted + +import ( + "fmt" + "os" + "os/exec" + + glider_ssh "github.com/gliderlabs/ssh" +) + +// sshHandleUploadPack handles clones/fetches. It just uses git-upload-pack +// and has no ACL checks. +func (s *Server) sshHandleUploadPack(session glider_ssh.Session, pubkey, repoIdentifier string) (err error) { + var repoPath string + if _, _, _, repoPath, _, _, _, _, err = s.getRepoInfo2(session.Context(), repoIdentifier, pubkey); err != nil { + return err + } + + proc := exec.CommandContext(session.Context(), "git-upload-pack", repoPath) + proc.Env = append(os.Environ(), "LINDENII_FORGE_HOOKS_SOCKET_PATH="+s.config.Hooks.Socket) + proc.Stdin = session + proc.Stdout = session + proc.Stderr = session.Stderr() + + if err = proc.Start(); err != nil { + fmt.Fprintln(session.Stderr(), "Error while starting process:", err) + return err + } + + err = proc.Wait() + if err != nil { + fmt.Fprintln(session.Stderr(), "Error while waiting for process:", err) + } + + return err +} |