Index fixes and performance improvements (fixes #223, #224)

- Fixed creation of duplicate index entries when importing from CurseForge (fixes #224)
- Automatically remove duplicates in index
- Fixed `packwiz serve` with a custom `--pack-root` argument (fixes #223)
- Fixed `packwiz serve` with a custom index.toml location
- Cleaned up internal serving code, added comments and better errors
- Refactored path handling code
- Improved refreshing/exporting performance
- Factored out duplicated exporting logic
- Replaced GetAllMods calls with cleaner LoadAllMods calls and made the former private
- Improved variable names in update command
- Improved handling of aliassed files
- Changed CheckUpdate to take references to metadata
- Removed the ability to use an absolute path to the index file (that probably didn't work anyway)
- Behaviour change: order of entries in exported files may be random
This commit is contained in:
comp500
2023-05-29 23:15:55 +01:00
parent d25817273b
commit 4fb1f1b59d
14 changed files with 401 additions and 352 deletions

View File

@@ -375,7 +375,7 @@ type cachedStateStore struct {
fileInfo *modFileInfo
}
func (u cfUpdater) CheckUpdate(mods []core.Mod, pack core.Pack) ([]core.UpdateCheck, error) {
func (u cfUpdater) CheckUpdate(mods []*core.Mod, pack core.Pack) ([]core.UpdateCheck, error) {
results := make([]core.UpdateCheck, len(mods))
modIDs := make([]uint32, len(mods))
modInfos := make([]modInfo, len(mods))

View File

@@ -10,7 +10,6 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/viper"
"os"
"path/filepath"
"strconv"
)
@@ -59,9 +58,6 @@ var exportCmd = &cobra.Command{
os.Exit(1)
}
// TODO: should index just expose indexPath itself, through a function?
indexPath := filepath.Join(filepath.Dir(viper.GetString("pack-file")), filepath.FromSlash(pack.Index.File))
fmt.Println("Reading external files...")
mods, err := index.LoadAllMods()
if err != nil {
@@ -139,7 +135,7 @@ var exportCmd = &cobra.Command{
cmdshared.ListManualDownloads(session)
for dl := range session.StartDownloads() {
_ = cmdshared.AddToZip(dl, exp, "overrides", indexPath)
_ = cmdshared.AddToZip(dl, exp, "overrides", &index)
}
err = session.SaveIndex()
@@ -173,31 +169,7 @@ var exportCmd = &cobra.Command{
os.Exit(1)
}
i = 0
for _, v := range index.Files {
if !v.MetaFile {
// Save all non-metadata files into the zip
path, err := filepath.Rel(filepath.Dir(indexPath), index.GetFilePath(v))
if err != nil {
fmt.Printf("Error resolving file: %s\n", err.Error())
// TODO: exit(1)?
continue
}
file, err := exp.Create(filepath.ToSlash(filepath.Join("overrides", path)))
if err != nil {
fmt.Printf("Error creating file: %s\n", err.Error())
// TODO: exit(1)?
continue
}
err = index.SaveFile(v, file)
if err != nil {
fmt.Printf("Error copying file: %s\n", err.Error())
// TODO: exit(1)?
continue
}
i++
}
}
cmdshared.AddNonMetafileOverrides(&index, exp)
err = exp.Close()
if err != nil {

View File

@@ -285,9 +285,8 @@ var importCmd = &cobra.Command{
}
successes = 0
packRoot := index.GetPackRoot()
for _, v := range filesList {
filePath := filepath.Join(packRoot, filepath.FromSlash(v.Name()))
filePath := index.ResolveIndexPath(v.Name())
filePathAbs, err := filepath.Abs(filePath)
if err == nil {
found := false

View File

@@ -145,9 +145,11 @@ var installCmd = &cobra.Command{
for len(depIDPendingQueue) > 0 && cycles < maxCycles {
if installedIDList == nil {
// Get modids of all mods
for _, modPath := range index.GetAllMods() {
mod, err := core.LoadMod(modPath)
if err == nil {
mods, err := index.LoadAllMods()
if err != nil {
fmt.Printf("Failed to determine existing projects: %v\n", err)
} else {
for _, mod := range mods {
data, ok := mod.GetParsedUpdateData("curseforge")
if ok {
updateData, ok := data.(cfUpdateData)