mirror of
https://github.com/packwiz/packwiz.git
synced 2025-04-30 09:46:30 +02:00
Ignore directories in zip file listings, fix cachedFileList
This commit is contained in:
parent
f46ff894cc
commit
985f550010
@ -20,13 +20,20 @@ type zipPackSource struct {
|
|||||||
cachedFileList []ImportPackFile
|
cachedFileList []ImportPackFile
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s zipPackSource) GetFile(path string) (ImportPackFile, error) {
|
func (s *zipPackSource) updateFileList() {
|
||||||
if s.cachedFileList == nil {
|
s.cachedFileList = make([]ImportPackFile, len(s.Reader.File))
|
||||||
s.cachedFileList = make([]ImportPackFile, len(s.Reader.File))
|
i := 0
|
||||||
for i, v := range s.Reader.File {
|
for _, v := range s.Reader.File {
|
||||||
|
// Ignore directories
|
||||||
|
if !v.Mode().IsDir() {
|
||||||
s.cachedFileList[i] = zipReaderFile{v.Name, v}
|
s.cachedFileList[i] = zipReaderFile{v.Name, v}
|
||||||
|
i++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
s.cachedFileList = s.cachedFileList[:i]
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s zipPackSource) GetFile(path string) (ImportPackFile, error) {
|
||||||
for _, v := range s.cachedFileList {
|
for _, v := range s.cachedFileList {
|
||||||
if v.Name() == path {
|
if v.Name() == path {
|
||||||
return v, nil
|
return v, nil
|
||||||
@ -36,12 +43,6 @@ func (s zipPackSource) GetFile(path string) (ImportPackFile, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s zipPackSource) GetFileList() ([]ImportPackFile, error) {
|
func (s zipPackSource) GetFileList() ([]ImportPackFile, error) {
|
||||||
if s.cachedFileList == nil {
|
|
||||||
s.cachedFileList = make([]ImportPackFile, len(s.Reader.File))
|
|
||||||
for i, v := range s.Reader.File {
|
|
||||||
s.cachedFileList[i] = zipReaderFile{v.Name, v}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return s.cachedFileList, nil
|
return s.cachedFileList, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,8 +51,10 @@ func (s zipPackSource) GetPackFile() ImportPackFile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetZipPackSource(metaFile *zip.File, reader *zip.Reader) ImportPackSource {
|
func GetZipPackSource(metaFile *zip.File, reader *zip.Reader) ImportPackSource {
|
||||||
return zipPackSource{
|
source := zipPackSource{
|
||||||
MetaFile: metaFile,
|
MetaFile: metaFile,
|
||||||
Reader: reader,
|
Reader: reader,
|
||||||
}
|
}
|
||||||
|
source.updateFileList()
|
||||||
|
return source
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user