1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-12-04 18:19:54 +00:00

Rename WikiDir to WikiGitDir

Rhymes well with the forecoming Structure.
This commit is contained in:
Timur Ismagilov 2021-06-15 01:30:17 +05:00
parent b4e0ff2e34
commit 839b1e2448
9 changed files with 18 additions and 18 deletions

View File

@ -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
)

View File

@ -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

View File

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

View File

@ -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()

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.
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
}

View File

@ -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()

View File

@ -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()
}

View File

@ -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 ""
}

View File

@ -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)
}