From 839b1e2448932766f58a4629593205a4fd6d8912 Mon Sep 17 00:00:00 2001 From: Timur Ismagilov Date: Tue, 15 Jun 2021 01:30:17 +0500 Subject: [PATCH] Rename WikiDir to WikiGitDir Rhymes well with the forecoming Structure. --- cfg/config.go | 4 ++-- files/files.go | 2 +- flag.go | 2 +- history/history.go | 4 ++-- history/information.go | 2 +- main.go | 8 ++++---- shroom/upload.go | 4 ++-- util/util.go | 6 +++--- web/stuff.go | 4 ++-- 9 files changed, 18 insertions(+), 18 deletions(-) diff --git a/cfg/config.go b/cfg/config.go index 786fa1c..13c5a85 100644 --- a/cfg/config.go +++ b/cfg/config.go @@ -37,8 +37,8 @@ var ( // These variables are set before reading the config file, they are set in main.parseCliArgs. var ( - // WikiDir is a full path to the wiki storage directory, which also must be a git repo. - WikiDir string + // WikiGitDir is a full path to the wiki storage directory, which also must be a git repo. + WikiGitDir string // ConfigFilePath is a path to the config file. Its value is used when calling ReadConfigFile. ConfigFilePath string ) diff --git a/files/files.go b/files/files.go index 740041b..842b477 100644 --- a/files/files.go +++ b/files/files.go @@ -61,7 +61,7 @@ func tokenStoragePath() (string, error) { if err != nil { return "", err } - if strings.HasPrefix(dir, cfg.WikiDir) { + if strings.HasPrefix(dir, cfg.WikiGitDir) { return "", errors.New("wiki storage directory includes private config files") } return dir, nil diff --git a/flag.go b/flag.go index 872f44c..1ded640 100644 --- a/flag.go +++ b/flag.go @@ -51,7 +51,7 @@ func parseCliArgs() { } wikiDir, err := filepath.Abs(args[0]) - cfg.WikiDir = wikiDir + cfg.WikiGitDir = wikiDir if err != nil { log.Fatal(err) } diff --git a/history/history.go b/history/history.go index e77430b..dccb103 100644 --- a/history/history.go +++ b/history/history.go @@ -162,7 +162,7 @@ func (rev *Revision) bestLink() string { func gitsh(args ...string) (out bytes.Buffer, err error) { fmt.Printf("$ %v\n", args) cmd := exec.Command(gitpath, args...) - cmd.Dir = cfg.WikiDir + cmd.Dir = cfg.WikiGitDir cmd.Env = gitEnv b, err := cmd.CombinedOutput() @@ -175,7 +175,7 @@ func gitsh(args ...string) (out bytes.Buffer, err error) { // silentGitsh is like gitsh, except it writes less to the stdout. func silentGitsh(args ...string) (out bytes.Buffer, err error) { cmd := exec.Command(gitpath, args...) - cmd.Dir = cfg.WikiDir + cmd.Dir = cfg.WikiGitDir cmd.Env = gitEnv b, err := cmd.CombinedOutput() diff --git a/history/information.go b/history/information.go index 3d8342e..a24f5a0 100644 --- a/history/information.go +++ b/history/information.go @@ -176,7 +176,7 @@ func parseRevisionLine(line string) Revision { // FileAtRevision shows how the file with the given file path looked at the commit with the hash. It may return an error if git fails. func FileAtRevision(filepath, hash string) (string, error) { - out, err := gitsh("show", hash+":"+strings.TrimPrefix(filepath, cfg.WikiDir+"/")) + out, err := gitsh("show", hash+":"+strings.TrimPrefix(filepath, cfg.WikiGitDir+"/")) if err != nil { return "", err } diff --git a/main.go b/main.go index 6bc1091..9ba49b5 100644 --- a/main.go +++ b/main.go @@ -30,19 +30,19 @@ func main() { } log.Println("Running Mycorrhiza Wiki 1.2.0 indev") - if err := os.Chdir(cfg.WikiDir); err != nil { + if err := os.Chdir(cfg.WikiGitDir); err != nil { log.Fatal(err) } - log.Println("Wiki storage directory is", cfg.WikiDir) + log.Println("Wiki storage directory is", cfg.WikiGitDir) // Init the subsystems: - hyphae.Index(cfg.WikiDir) + hyphae.Index(cfg.WikiGitDir) user.InitUserDatabase() history.Start() shroom.SetHeaderLinks() // Static files: - static.InitFS(cfg.WikiDir + "/static") + static.InitFS(cfg.WikiGitDir + "/static") // Network: go handleGemini() diff --git a/shroom/upload.go b/shroom/upload.go index a4916d3..24a4e03 100644 --- a/shroom/upload.go +++ b/shroom/upload.go @@ -64,13 +64,13 @@ func UploadBinary(h *hyphae.Hypha, mime string, file multipart.File, u *user.Use // uploadHelp is a helper function for UploadText and UploadBinary func uploadHelp(h *hyphae.Hypha, hop *history.HistoryOp, ext string, data []byte, u *user.User) (*history.HistoryOp, string) { var ( - fullPath, err = filepath.EvalSymlinks(filepath.Join(cfg.WikiDir, h.Name+ext)) + fullPath, err = filepath.EvalSymlinks(filepath.Join(cfg.WikiGitDir, h.Name+ext)) originalFullPath = &h.TextPath ) if err != nil { return hop.WithErrAbort(err), err.Error() } - if !strings.HasPrefix(fullPath, cfg.WikiDir) { // If the path somehow got outside the wiki dir + if !strings.HasPrefix(fullPath, cfg.WikiGitDir) { // If the path somehow got outside the wiki dir err = errors.New("bad path") return hop.WithErrAbort(err), err.Error() } diff --git a/util/util.go b/util/util.go index a9f0f73..b35a7eb 100644 --- a/util/util.go +++ b/util/util.go @@ -34,10 +34,10 @@ func LettersNumbersOnly(s string) string { return strings.Trim(ret.String(), "_") } -// ShorterPath is used by handlerList to display shorter path to the files. It simply strips WikiDir. +// ShorterPath is used by handlerList to display shorter path to the files. It simply strips WikiGitDir. func ShorterPath(path string) string { - if strings.HasPrefix(path, cfg.WikiDir) { - tmp := strings.TrimPrefix(path, cfg.WikiDir) + if strings.HasPrefix(path, cfg.WikiGitDir) { + tmp := strings.TrimPrefix(path, cfg.WikiGitDir) if tmp == "" { return "" } diff --git a/web/stuff.go b/web/stuff.go index 90e4c26..e5b2870 100644 --- a/web/stuff.go +++ b/web/stuff.go @@ -38,9 +38,9 @@ func handlerReindex(w http.ResponseWriter, rq *http.Request) { return } hyphae.ResetCount() - log.Println("Wiki storage directory is", cfg.WikiDir) + log.Println("Wiki storage directory is", cfg.WikiGitDir) log.Println("Start indexing hyphae...") - hyphae.Index(cfg.WikiDir) + hyphae.Index(cfg.WikiGitDir) log.Println("Indexed", hyphae.Count(), "hyphae") http.Redirect(w, rq, "/", http.StatusSeeOther) }