Migrate migration
This commit is contained in:
parent
191c18fd9e
commit
b3626ee546
@ -1,11 +1,13 @@
|
||||
package migration
|
||||
|
||||
import (
|
||||
"git.sr.ht/~bouncepaw/mycomarkup/v5/tools"
|
||||
"github.com/bouncepaw/mycorrhiza/internal/files"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"log/slog"
|
||||
"os"
|
||||
|
||||
"github.com/bouncepaw/mycorrhiza/internal/files"
|
||||
|
||||
"git.sr.ht/~bouncepaw/mycomarkup/v5/tools"
|
||||
)
|
||||
|
||||
var headingMarkerPath string
|
||||
@ -29,7 +31,8 @@ func shouldMigrateHeadings() bool {
|
||||
return true
|
||||
}
|
||||
if err != nil {
|
||||
log.Fatalln("When checking if heading migration is needed:", err.Error())
|
||||
slog.Error("Failed to check if heading migration is needed", "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
_ = file.Close()
|
||||
return false
|
||||
@ -42,6 +45,7 @@ func createHeadingMarker() {
|
||||
0766,
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
slog.Error("Failed to create heading migration marker", "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,14 +8,14 @@
|
||||
package migration
|
||||
|
||||
import (
|
||||
"github.com/bouncepaw/mycorrhiza/internal/user"
|
||||
"io"
|
||||
"log"
|
||||
"log/slog"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/bouncepaw/mycorrhiza/history"
|
||||
"github.com/bouncepaw/mycorrhiza/internal/hyphae"
|
||||
"github.com/bouncepaw/mycorrhiza/internal/user"
|
||||
)
|
||||
|
||||
func genericLineMigrator(
|
||||
@ -37,7 +37,8 @@ func genericLineMigrator(
|
||||
file, err := os.OpenFile(hypha.TextFilePath(), os.O_RDWR, 0766)
|
||||
if err != nil {
|
||||
hop.WithErrAbort(err)
|
||||
log.Fatal("Something went wrong when opening ", hypha.TextFilePath(), ": ", err.Error())
|
||||
slog.Error("Failed to open text part file", "path", hypha.TextFilePath(), "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
var buf strings.Builder
|
||||
@ -45,7 +46,7 @@ func genericLineMigrator(
|
||||
if err != nil {
|
||||
hop.WithErrAbort(err)
|
||||
_ = file.Close()
|
||||
log.Fatal("Something went wrong when reading ", hypha.TextFilePath(), ": ", err.Error())
|
||||
slog.Error("Failed to read text part file", "path", hypha.TextFilePath(), "err", err)
|
||||
}
|
||||
|
||||
var (
|
||||
@ -59,21 +60,24 @@ func genericLineMigrator(
|
||||
if err != nil {
|
||||
hop.WithErrAbort(err)
|
||||
_ = file.Close()
|
||||
log.Fatal("Something went wrong when truncating ", hypha.TextFilePath(), ": ", err.Error())
|
||||
slog.Error("Failed to truncate text part file", "path", hypha.TextFilePath(), "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
_, err = file.Seek(0, 0)
|
||||
if err != nil {
|
||||
hop.WithErrAbort(err)
|
||||
_ = file.Close()
|
||||
log.Fatal("Something went wrong when seeking in ", hypha.TextFilePath(), ": ", err.Error())
|
||||
slog.Error("Failed to seek in text part file", "path", hypha.TextFilePath(), "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
_, err = file.WriteString(newText)
|
||||
if err != nil {
|
||||
hop.WithErrAbort(err)
|
||||
_ = file.Close()
|
||||
log.Fatal("Something went wrong when writing to ", hypha.TextFilePath(), ": ", err.Error())
|
||||
slog.Error("Failed to write to text part file", "path", hypha.TextFilePath(), "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
_ = file.Close()
|
||||
@ -85,8 +89,8 @@ func genericLineMigrator(
|
||||
}
|
||||
|
||||
if hop.WithFiles(mycoFiles...).Apply().HasErrors() {
|
||||
log.Fatal(commitErrorMessage, hop.FirstErrorText())
|
||||
slog.Error(commitErrorMessage + hop.FirstErrorText())
|
||||
}
|
||||
|
||||
log.Println("Migrated", len(mycoFiles), "Mycomarkup documents")
|
||||
slog.Info("Migrated Mycomarkup documents", "n", len(mycoFiles))
|
||||
}
|
||||
|
||||
@ -1,11 +1,13 @@
|
||||
package migration
|
||||
|
||||
import (
|
||||
"git.sr.ht/~bouncepaw/mycomarkup/v5/tools"
|
||||
"github.com/bouncepaw/mycorrhiza/internal/files"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"log/slog"
|
||||
"os"
|
||||
|
||||
"github.com/bouncepaw/mycorrhiza/internal/files"
|
||||
|
||||
"git.sr.ht/~bouncepaw/mycomarkup/v5/tools"
|
||||
)
|
||||
|
||||
var rocketMarkerPath string
|
||||
@ -33,7 +35,8 @@ func shouldMigrateRockets() bool {
|
||||
return true
|
||||
}
|
||||
if err != nil {
|
||||
log.Fatalln("When checking if rocket migration is needed:", err.Error())
|
||||
slog.Error("Failed to check if rocket migration is needed", "err", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
_ = file.Close()
|
||||
return false
|
||||
@ -46,6 +49,7 @@ func createRocketLinkMarker() {
|
||||
0766,
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
slog.Error("Failed to create rocket link migration marker")
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user