1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2025-05-31 02:14:06 +00:00

Revert "Rename WikiDir to WikiGitDir"

This reverts commit 839b1e2448932766f58a4629593205a4fd6d8912.
This commit is contained in:
handlerug 2021-06-16 19:27:28 +07:00
parent e5e9720654
commit 2f7ea74866
No known key found for this signature in database
GPG Key ID: 38009F0605051491
9 changed files with 23 additions and 21 deletions

View File

@ -37,8 +37,8 @@ var (
// These variables are set before reading the config file, they are set in main.parseCliArgs. // These variables are set before reading the config file, they are set in main.parseCliArgs.
var ( var (
// WikiGitDir is a full path to the wiki storage directory, which also must be a git repo. // WikiDir is a full path to the wiki storage directory, which also must be a git repo.
WikiGitDir string WikiDir string
// ConfigFilePath is a path to the config file. Its value is used when calling ReadConfigFile. // ConfigFilePath is a path to the config file. Its value is used when calling ReadConfigFile.
ConfigFilePath string ConfigFilePath string
) )

View File

@ -61,7 +61,7 @@ func tokenStoragePath() (string, error) {
if err != nil { if err != nil {
return "", err 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 "", errors.New("wiki storage directory includes private config files")
} }
return dir, nil return dir, nil

View File

@ -51,7 +51,7 @@ func parseCliArgs() {
} }
wikiDir, err := filepath.Abs(args[0]) wikiDir, err := filepath.Abs(args[0])
cfg.WikiGitDir = wikiDir cfg.WikiDir = wikiDir
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }

View File

@ -162,7 +162,7 @@ func (rev *Revision) bestLink() string {
func gitsh(args ...string) (out bytes.Buffer, err error) { func gitsh(args ...string) (out bytes.Buffer, err error) {
fmt.Printf("$ %v\n", args) fmt.Printf("$ %v\n", args)
cmd := exec.Command(gitpath, args...) cmd := exec.Command(gitpath, args...)
cmd.Dir = cfg.WikiGitDir cmd.Dir = cfg.WikiDir
cmd.Env = gitEnv cmd.Env = gitEnv
b, err := cmd.CombinedOutput() 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. // silentGitsh is like gitsh, except it writes less to the stdout.
func silentGitsh(args ...string) (out bytes.Buffer, err error) { func silentGitsh(args ...string) (out bytes.Buffer, err error) {
cmd := exec.Command(gitpath, args...) cmd := exec.Command(gitpath, args...)
cmd.Dir = cfg.WikiGitDir cmd.Dir = cfg.WikiDir
cmd.Env = gitEnv cmd.Env = gitEnv
b, err := cmd.CombinedOutput() b, err := cmd.CombinedOutput()

View File

@ -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. // 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) { 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 { if err != nil {
return "", err return "", err
} }

View File

@ -30,19 +30,19 @@ func main() {
} }
log.Println("Running Mycorrhiza Wiki 1.2.0 indev") 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.Fatal(err)
} }
log.Println("Wiki storage directory is", cfg.WikiGitDir) log.Println("Wiki storage directory is", cfg.WikiDir)
// Init the subsystems: // Init the subsystems:
hyphae.Index(cfg.WikiGitDir) hyphae.Index(cfg.WikiDir)
user.InitUserDatabase() user.InitUserDatabase()
history.Start() history.Start()
shroom.SetHeaderLinks() shroom.SetHeaderLinks()
// Static files: // Static files:
static.InitFS(cfg.WikiGitDir + "/static") static.InitFS(cfg.WikiDir + "/static")
// Network: // Network:
go handleGemini() go handleGemini()

View File

@ -3,7 +3,6 @@ package shroom
import ( import (
"errors" "errors"
"fmt" "fmt"
"github.com/bouncepaw/mycorrhiza/cfg"
"io/ioutil" "io/ioutil"
"log" "log"
"mime/multipart" "mime/multipart"
@ -11,6 +10,8 @@ import (
"path/filepath" "path/filepath"
"strings" "strings"
"github.com/bouncepaw/mycorrhiza/cfg"
"github.com/bouncepaw/mycorrhiza/history" "github.com/bouncepaw/mycorrhiza/history"
"github.com/bouncepaw/mycorrhiza/hyphae" "github.com/bouncepaw/mycorrhiza/hyphae"
"github.com/bouncepaw/mycorrhiza/mimetype" "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 // 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) { func uploadHelp(h *hyphae.Hypha, hop *history.HistoryOp, ext string, data []byte, u *user.User) (*history.HistoryOp, string) {
var ( var (
fullPath = filepath.Join(cfg.WikiGitDir, h.Name+ext) fullPath = filepath.Join(cfg.WikiDir, h.Name+ext)
originalFullPath = &h.TextPath 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") err := errors.New("bad path")
return hop.WithErrAbort(err), err.Error() return hop.WithErrAbort(err), err.Error()
} }

View File

@ -3,12 +3,13 @@ package util
import ( import (
"crypto/rand" "crypto/rand"
"encoding/hex" "encoding/hex"
"github.com/bouncepaw/mycomarkup/util"
"github.com/bouncepaw/mycorrhiza/cfg"
"log" "log"
"net/http" "net/http"
"regexp" "regexp"
"strings" "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. // 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, "/") 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 { func ShorterPath(path string) string {
if strings.HasPrefix(path, cfg.WikiGitDir) { if strings.HasPrefix(path, cfg.WikiDir) {
tmp := strings.TrimPrefix(path, cfg.WikiGitDir) tmp := strings.TrimPrefix(path, cfg.WikiDir)
if tmp == "" { if tmp == "" {
return "" return ""
} }

View File

@ -41,9 +41,9 @@ func handlerReindex(w http.ResponseWriter, rq *http.Request) {
return return
} }
hyphae.ResetCount() hyphae.ResetCount()
log.Println("Wiki storage directory is", cfg.WikiGitDir) log.Println("Wiki storage directory is", cfg.WikiDir)
log.Println("Start indexing hyphae...") log.Println("Start indexing hyphae...")
hyphae.Index(cfg.WikiGitDir) hyphae.Index(cfg.WikiDir)
log.Println("Indexed", hyphae.Count(), "hyphae") log.Println("Indexed", hyphae.Count(), "hyphae")
http.Redirect(w, rq, "/", http.StatusSeeOther) http.Redirect(w, rq, "/", http.StatusSeeOther)
} }