-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.go
More file actions
52 lines (43 loc) · 889 Bytes
/
util.go
File metadata and controls
52 lines (43 loc) · 889 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"bytes"
"io/ioutil"
"os"
"os/exec"
"path"
"path/filepath"
"strconv"
)
func findGitPath() (string, error) {
return exec.LookPath("git")
}
func findBackendCGI() (string, error) {
// git, err := findGitPath()
// if err != nil {
// return "", err
// }
dir, err := exec.Command("git", "--exec-path").Output()
if err != nil {
return "", err
}
dir = bytes.TrimRight(dir, "\r\n")
return filepath.Join(string(dir), "git-http-backend"), nil
}
func writePIDFile(file string) error {
pid := strconv.Itoa(os.Getpid())
return ioutil.WriteFile(file, []byte(pid), 0644)
}
func removePIDFile(file string) error {
err := os.Remove(file)
if err != nil && !os.IsNotExist(err) {
return err
}
return nil
}
func subtreePath(uri string) string {
if uri == "" || uri == "/" {
return "/"
}
// ensure the trailing slash
return path.Clean(uri) + "/"
}