mirror of
				https://github.com/packwiz/packwiz.git
				synced 2025-10-31 02:34:31 +01:00 
			
		
		
		
	Improve directory traversal performance
This commit is contained in:
		| @@ -4,6 +4,7 @@ import ( | |||||||
| 	"errors" | 	"errors" | ||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"io" | 	"io" | ||||||
|  | 	"io/fs" | ||||||
| 	"os" | 	"os" | ||||||
| 	"path" | 	"path" | ||||||
| 	"path/filepath" | 	"path/filepath" | ||||||
| @@ -214,21 +215,25 @@ func (in *Index) Refresh() error { | |||||||
| 	ignore, ignoreExists := readGitignore(pathIgnore) | 	ignore, ignoreExists := readGitignore(pathIgnore) | ||||||
|  |  | ||||||
| 	var fileList []string | 	var fileList []string | ||||||
| 	err := filepath.Walk(packRoot, func(path string, info os.FileInfo, err error) error { | 	err := filepath.WalkDir(packRoot, func(path string, info os.DirEntry, 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 | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|  | 		if info.IsDir() { | ||||||
|  | 			// Don't traverse ignored directories (consistent with Git handling of ignored dirs) | ||||||
|  | 			if ignore.MatchesPath(path) { | ||||||
|  | 				return fs.SkipDir | ||||||
|  | 			} | ||||||
|  | 			// Don't add directories to the file list | ||||||
|  | 			return nil | ||||||
|  | 		} | ||||||
| 		// Exit if the files are the same as the pack/index files | 		// Exit if the files are the same as the pack/index files | ||||||
| 		absPath, _ := filepath.Abs(path) | 		absPath, _ := filepath.Abs(path) | ||||||
| 		if absPath == pathPF || absPath == pathIndex { | 		if absPath == pathPF || absPath == pathIndex { | ||||||
| 			return nil | 			return nil | ||||||
| 		} | 		} | ||||||
| 		// Exit if this is a directory |  | ||||||
| 		if info.IsDir() { |  | ||||||
| 			return nil |  | ||||||
| 		} |  | ||||||
| 		if ignoreExists { | 		if ignoreExists { | ||||||
| 			if absPath == pathIgnore { | 			if absPath == pathIgnore { | ||||||
| 				return nil | 				return nil | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user