From 2f7ea748669af52cafcef36bcd81c7979089f069 Mon Sep 17 00:00:00 2001 From: handlerug Date: Wed, 16 Jun 2021 19:27:28 +0700 Subject: [PATCH] Revert "Rename WikiDir to WikiGitDir" This reverts commit 839b1e2448932766f58a4629593205a4fd6d8912. --- 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 | 7 ++++--- util/util.go | 11 ++++++----- web/stuff.go | 4 ++-- 9 files changed, 23 insertions(+), 21 deletions(-) diff --git a/cfg/config.go b/cfg/config.go index 13c5a85..786fa1c 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 ( - // WikiGitDir is a full path to the wiki storage directory, which also must be a git repo. - WikiGitDir string + // WikiDir is a full path to the wiki storage directory, which also must be a git repo. + WikiDir 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 842b477..740041b 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.WikiGitDir) { + if strings.HasPrefix(dir, cfg.WikiDir) { return "", errors.New("wiki storage directory includes private config files") } return dir, nil diff --git a/flag.go b/flag.go index 1ded640..872f44c 100644 --- a/flag.go +++ b/flag.go @@ -51,7 +51,7 @@ func parseCliArgs() { } wikiDir, err := filepath.Abs(args[0]) - cfg.WikiGitDir = wikiDir + cfg.WikiDir = wikiDir if err != nil { log.Fatal(err) } diff --git a/history/history.go b/history/history.go index dccb103..e77430b 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.WikiGitDir + cmd.Dir = cfg.WikiDir 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.WikiGitDir + cmd.Dir = cfg.WikiDir cmd.Env = gitEnv b, err := cmd.CombinedOutput() diff --git a/history/information.go b/history/information.go index a24f5a0..3d8342e 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.WikiGitDir+"/")) + out, err := gitsh("show", hash+":"+strings.TrimPrefix(filepath, cfg.WikiDir+"/")) if err != nil { return "", err } diff --git a/main.go b/main.go index 9ba49b5..6bc1091 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.WikiGitDir); err != nil { + if err := os.Chdir(cfg.WikiDir); err != nil { log.Fatal(err) } - log.Println("Wiki storage directory is", cfg.WikiGitDir) + log.Println("Wiki storage directory is", cfg.WikiDir) // Init the subsystems: - hyphae.Index(cfg.WikiGitDir) + hyphae.Index(cfg.WikiDir) user.InitUserDatabase() history.Start() shroom.SetHeaderLinks() // Static files: - static.InitFS(cfg.WikiGitDir + "/static") + static.InitFS(cfg.WikiDir + "/static") // Network: go handleGemini() diff --git a/shroom/upload.go b/shroom/upload.go index c0b0bca..6c45371 100644 --- a/shroom/upload.go +++ b/shroom/upload.go @@ -3,7 +3,6 @@ package shroom import ( "errors" "fmt" - "github.com/bouncepaw/mycorrhiza/cfg" "io/ioutil" "log" "mime/multipart" @@ -11,6 +10,8 @@ import ( "path/filepath" "strings" + "github.com/bouncepaw/mycorrhiza/cfg" + "github.com/bouncepaw/mycorrhiza/history" "github.com/bouncepaw/mycorrhiza/hyphae" "github.com/bouncepaw/mycorrhiza/mimetype" @@ -64,10 +65,10 @@ 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 = filepath.Join(cfg.WikiGitDir, h.Name+ext) + fullPath = filepath.Join(cfg.WikiDir, h.Name+ext) originalFullPath = &h.TextPath ) - if !strings.HasPrefix(fullPath, cfg.WikiGitDir) { // If the path somehow got outside the wiki dir + if !strings.HasPrefix(fullPath, cfg.WikiDir) { // 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 213fa8f..7dd48ba 100644 --- a/util/util.go +++ b/util/util.go @@ -3,12 +3,13 @@ package util import ( "crypto/rand" "encoding/hex" - "github.com/bouncepaw/mycomarkup/util" - "github.com/bouncepaw/mycorrhiza/cfg" "log" "net/http" "regexp" "strings" + + "github.com/bouncepaw/mycomarkup/util" + "github.com/bouncepaw/mycorrhiza/cfg" ) // PrepareRq strips the trailing / in rq.URL.Path. In the future it might do more stuff for making all request structs uniform. @@ -16,10 +17,10 @@ func PrepareRq(rq *http.Request) { rq.URL.Path = strings.TrimSuffix(rq.URL.Path, "/") } -// ShorterPath is used by handlerList to display shorter path to the files. It simply strips WikiGitDir. +// ShorterPath is used by handlerList to display shorter path to the files. It simply strips WikiDir. func ShorterPath(path string) string { - if strings.HasPrefix(path, cfg.WikiGitDir) { - tmp := strings.TrimPrefix(path, cfg.WikiGitDir) + if strings.HasPrefix(path, cfg.WikiDir) { + tmp := strings.TrimPrefix(path, cfg.WikiDir) if tmp == "" { return "" } diff --git a/web/stuff.go b/web/stuff.go index d4ffd4a..2b6ea60 100644 --- a/web/stuff.go +++ b/web/stuff.go @@ -41,9 +41,9 @@ func handlerReindex(w http.ResponseWriter, rq *http.Request) { return } hyphae.ResetCount() - log.Println("Wiki storage directory is", cfg.WikiGitDir) + log.Println("Wiki storage directory is", cfg.WikiDir) log.Println("Start indexing hyphae...") - hyphae.Index(cfg.WikiGitDir) + hyphae.Index(cfg.WikiDir) log.Println("Indexed", hyphae.Count(), "hyphae") http.Redirect(w, rq, "/", http.StatusSeeOther) }