Finished wildcard support.
Realized that path.Match works perfectly for my wildcard needs.
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/CalebQ42/squashfs/internal/directory"
|
||||
@@ -124,20 +125,20 @@ func (f *File) Path() string {
|
||||
|
||||
//GetFileAtPath tries to return the File at the given path, relative to the file.
|
||||
//Returns nil if called on something other then a folder, OR if the path goes oustide the archive.
|
||||
//Allows * wildcards.
|
||||
func (f *File) GetFileAtPath(path string) *File {
|
||||
if path == "" {
|
||||
//Allows wildcards supported by path.Match (namely * and ?).
|
||||
func (f *File) GetFileAtPath(dirPath string) *File {
|
||||
if dirPath == "" {
|
||||
return f
|
||||
}
|
||||
path = strings.TrimSuffix(strings.TrimPrefix(path, "/"), "/")
|
||||
if path != "" && !f.IsDir() {
|
||||
dirPath = strings.TrimSuffix(strings.TrimPrefix(dirPath, "/"), "/")
|
||||
if dirPath != "" && !f.IsDir() {
|
||||
return nil
|
||||
}
|
||||
for strings.HasSuffix(path, "./") {
|
||||
for strings.HasSuffix(dirPath, "./") {
|
||||
//since you can TECHNICALLY have an infinite amount of ./ and it would still be valid.
|
||||
path = strings.TrimPrefix(path, "./")
|
||||
dirPath = strings.TrimPrefix(dirPath, "./")
|
||||
}
|
||||
split := strings.Split(path, "/")
|
||||
split := strings.Split(dirPath, "/")
|
||||
if split[0] == ".." && f.Name == "" {
|
||||
return nil
|
||||
} else if split[0] == ".." {
|
||||
@@ -150,18 +151,9 @@ func (f *File) GetFileAtPath(path string) *File {
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
outer:
|
||||
for _, child := range children {
|
||||
if strings.Contains(split[0], "*") {
|
||||
wilds := strings.Split(split[0], "*")
|
||||
curIndex := 0
|
||||
for i, section := range wilds {
|
||||
ind := strings.Index(child.Name, section)
|
||||
if ind == -1 {
|
||||
continue outer
|
||||
}
|
||||
}
|
||||
} else if child.Name == split[0] {
|
||||
eq, _ := path.Match(split[0], child.Name)
|
||||
if eq {
|
||||
return child.GetFileAtPath(strings.Join(split[1:], "/"))
|
||||
}
|
||||
}
|
||||
|
||||
+11
-4
@@ -1,6 +1,7 @@
|
||||
package squashfs
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
@@ -58,10 +59,16 @@ func TestAppImage(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
os.RemoveAll(wd + "/testing/" + appImageName + ".d")
|
||||
root, _ := rdr.GetRootFolder()
|
||||
errs := root.ExtractWithOptions(wd+"/testing/"+appImageName+".d", true, os.ModePerm, true)
|
||||
t.Fatal(errs)
|
||||
fil := rdr.GetFileAtPath("usr/q*/QtQ*k/Extras/Priv*/q*")
|
||||
if fil == nil {
|
||||
t.Fatal("Can't find desktop file")
|
||||
}
|
||||
fmt.Println("Fount:", fil.Path())
|
||||
// os.RemoveAll(wd + "/testing/" + appImageName + ".d")
|
||||
// root, _ := rdr.GetRootFolder()
|
||||
// errs := root.ExtractWithOptions(wd+"/testing/"+appImageName+".d", true, os.ModePerm, true)
|
||||
// t.Fatal(errs)
|
||||
t.Fatal("No problemo!")
|
||||
}
|
||||
|
||||
func downloadTestAppImage(t *testing.T, dir string) {
|
||||
|
||||
Reference in New Issue
Block a user