mirror of
https://github.com/packwiz/packwiz.git
synced 2025-04-19 13:06:30 +02:00
Add default .packwizignore contents (fixes #3)
This commit is contained in:
parent
226a376be9
commit
fa5de4b4bc
@ -3,6 +3,7 @@ package core
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
@ -168,6 +169,35 @@ func (in Index) GetPackRoot() string {
|
|||||||
return filepath.Dir(in.indexFile)
|
return filepath.Dir(in.indexFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var ignoreDefaults = []string{
|
||||||
|
// Defaults (can be overridden with a negating pattern preceded with !)
|
||||||
|
|
||||||
|
// Exclude Git metadata
|
||||||
|
".git/**",
|
||||||
|
".gitattributes",
|
||||||
|
".gitignore",
|
||||||
|
|
||||||
|
// Exclude exported CurseForge zip files
|
||||||
|
"/*.zip",
|
||||||
|
|
||||||
|
// Exclude exported Modrinth packs
|
||||||
|
"*.mrpack",
|
||||||
|
}
|
||||||
|
|
||||||
|
func readGitignore(path string) (*gitignore.GitIgnore, bool) {
|
||||||
|
data, err := ioutil.ReadFile(path)
|
||||||
|
if err != nil {
|
||||||
|
// TODO: check for read errors (and present them)
|
||||||
|
return gitignore.CompileIgnoreLines(ignoreDefaults...), false
|
||||||
|
}
|
||||||
|
|
||||||
|
s := strings.Split(string(data), "\n")
|
||||||
|
var lines []string
|
||||||
|
lines = append(lines, ignoreDefaults...)
|
||||||
|
lines = append(lines, s...)
|
||||||
|
return gitignore.CompileIgnoreLines(lines...), true
|
||||||
|
}
|
||||||
|
|
||||||
// Refresh updates the hashes of all the files in the index, and adds new files to the index
|
// Refresh updates the hashes of all the files in the index, and adds new files to the index
|
||||||
func (in *Index) Refresh() error {
|
func (in *Index) Refresh() error {
|
||||||
// TODO: If needed, multithreaded hashing
|
// TODO: If needed, multithreaded hashing
|
||||||
@ -180,13 +210,10 @@ func (in *Index) Refresh() error {
|
|||||||
packRoot := in.GetPackRoot()
|
packRoot := in.GetPackRoot()
|
||||||
ignoreExists := true
|
ignoreExists := true
|
||||||
pathIgnore, _ := filepath.Abs(filepath.Join(packRoot, ".packwizignore"))
|
pathIgnore, _ := filepath.Abs(filepath.Join(packRoot, ".packwizignore"))
|
||||||
ignore, err := gitignore.CompileIgnoreFile(filepath.Join(packRoot, ".packwizignore"))
|
ignore, ignoreExists := readGitignore(filepath.Join(packRoot, ".packwizignore"))
|
||||||
if err != nil {
|
|
||||||
ignoreExists = false
|
|
||||||
}
|
|
||||||
|
|
||||||
var fileList []string
|
var fileList []string
|
||||||
err = filepath.Walk(packRoot, func(path string, info os.FileInfo, err error) error {
|
err := filepath.Walk(packRoot, func(path string, info os.FileInfo, err error) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// TODO: Handle errors on individual files properly
|
// TODO: Handle errors on individual files properly
|
||||||
return err
|
return err
|
||||||
@ -205,10 +232,9 @@ func (in *Index) Refresh() error {
|
|||||||
if absPath == pathIgnore {
|
if absPath == pathIgnore {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if ignore.MatchesPath(path) {
|
if ignore.MatchesPath(path) {
|
||||||
return nil
|
return nil
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fileList = append(fileList, path)
|
fileList = append(fileList, path)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user