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

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