1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2025-03-10 13:38:20 +00:00
Timur Ismagilov a4cc67cd74
Migrate from log to slog #109 (#255)
* Migrate httpd.go

* Migrate history and main

* Migrate hypview

* Migrate interwiki

* Migrate misc

* Migrate utils

* Migrate backlinks

* Migrate categories

* Reformat some imports

* Migrate hyphae

* Migrate migration

* Reformat more imports

* Migrate user

* Migrate shroom

* Migrate viewutil

* Migrate web

* Migrate others

* Migrate main

* Wording concerns
2024-09-07 23:55:39 +03:00

52 lines
1.2 KiB
Go

package migration
import (
"io/ioutil"
"log/slog"
"os"
"github.com/bouncepaw/mycorrhiza/internal/files"
"git.sr.ht/~bouncepaw/mycomarkup/v5/tools"
)
var headingMarkerPath string
func MigrateHeadingsMaybe() {
headingMarkerPath = files.FileInRoot(".mycomarkup-heading-migration-marker.txt")
if !shouldMigrateHeadings() {
return
}
genericLineMigrator(
"Migrate headings to the new syntax",
tools.MigrateHeadings,
"Something went wrong when commiting heading migration: ")
createHeadingMarker()
}
func shouldMigrateHeadings() bool {
file, err := os.Open(headingMarkerPath)
if os.IsNotExist(err) {
return true
}
if err != nil {
slog.Error("Failed to check if heading migration is needed", "err", err)
os.Exit(1)
}
_ = file.Close()
return false
}
func createHeadingMarker() {
err := ioutil.WriteFile(
headingMarkerPath,
[]byte(`This file is used to mark that the heading migration was successful. If this file is deleted, the migration might happen again depending on the version. You should probably not touch this file at all and let it be.`),
0766,
)
if err != nil {
slog.Error("Failed to create heading migration marker", "err", err)
os.Exit(1)
}
}