Compare commits

...

5 Commits

Author SHA1 Message Date
Caleb Gardner 0a2ced9072 Merge pull request #11 from tri-adam/path-fix
fix: handle paths with special characters
2022-04-22 04:25:42 -05:00
Adam Hughes a908d69987 fix: handle paths with special characters
Use direct comparison of filenames rather than path.Match, which gives
characters such as '[' special meaning, resulting in unexpected failures
when calling Open, ReadDir, Stat, or Sub.
2022-04-22 05:02:57 +00:00
Caleb Gardner 6ada4f3b49 Create FUNDING.yml 2021-12-31 00:35:04 -06:00
Caleb Gardner 89f28cec6e Merge pull request #6 from stffabi/feature/support-reading-dot
Support reading "." for fs.FS
2021-12-02 07:40:27 -06:00
stffabi c988309edc Support reading "." for fs.FS 2021-12-02 13:43:18 +01:00
4 changed files with 30 additions and 8 deletions
+3
View File
@@ -0,0 +1,3 @@
# These are supported funding model platforms
github: CalebQ42
+1
View File
@@ -189,6 +189,7 @@ func (r *Reader) Init() error {
return err
}
r.FS = FS{
i: i,
r: r,
name: "/",
entries: entries,
+3 -2
View File
@@ -135,10 +135,11 @@ func (f File) FS() (*FS, error) {
return nil, err
}
return &FS{
entries: ents,
parent: f.parent,
i: f.i,
r: f.r,
parent: f.parent,
name: f.name,
entries: ents,
}, nil
}
+23 -6
View File
@@ -10,11 +10,13 @@ import (
"strings"
"github.com/CalebQ42/squashfs/internal/directory"
"github.com/CalebQ42/squashfs/internal/inode"
)
//FS is a fs.FS representation of a squashfs directory.
//Implements fs.GlobFS, fs.ReadDirFS, fs.ReadFileFS, fs.StatFS, and fs.SubFS
type FS struct {
i *inode.Inode
r *Reader
parent *FS
name string
@@ -44,8 +46,11 @@ func (f FS) Open(name string) (fs.File, error) {
}
return f.parent.Open(strings.Join(split[1:], "/"))
}
if split[0] == "." {
return &File{i: f.i, r: f.r, parent: f.parent, name: f.name}, nil
}
for i := 0; i < len(f.entries); i++ {
if match, _ := path.Match(split[0], f.entries[i].Name); match {
if split[0] == f.entries[i].Name {
if len(split) == 1 {
return f.r.newFileFromDirEntry(f.entries[i], &f)
}
@@ -183,8 +188,12 @@ func (f FS) ReadDir(name string) ([]fs.DirEntry, error) {
}
return f.parent.ReadDir(strings.Join(split[1:], "/"))
}
if split[0] == "." {
f := &File{i: f.i, r: f.r, parent: f.parent, name: f.name}
return f.ReadDir(-1)
}
for i := 0; i < len(f.entries); i++ {
if match, _ := path.Match(split[0], f.entries[i].Name); match {
if split[0] == f.entries[i].Name {
if len(split) == 1 {
in, err := f.r.getInodeFromEntry(f.entries[i])
if err != nil {
@@ -202,7 +211,7 @@ func (f FS) ReadDir(name string) ([]fs.DirEntry, error) {
Err: err,
}
}
out := make([]fs.DirEntry, len(f.entries))
out := make([]fs.DirEntry, len(ents))
for i, ent := range ents {
out[i] = &DirEntry{
en: ent,
@@ -299,8 +308,12 @@ func (f FS) Stat(name string) (fs.FileInfo, error) {
}
return f.parent.Stat(strings.Join(split[1:], "/"))
}
if split[0] == "." {
f := &File{i: f.i, r: f.r, parent: f.parent, name: f.name}
return f.Stat()
}
for i := 0; i < len(f.entries); i++ {
if match, _ := path.Match(split[0], f.entries[i].Name); match {
if split[0] == f.entries[i].Name {
if len(split) == 1 {
in, err := f.r.getInodeFromEntry(f.entries[i])
if err != nil {
@@ -382,8 +395,11 @@ func (f FS) Sub(dir string) (fs.FS, error) {
}
return f.parent.Sub(strings.Join(split[1:], "/"))
}
if split[0] == "." {
return f, nil
}
for i := 0; i < len(f.entries); i++ {
if match, _ := path.Match(split[0], f.entries[i].Name); match {
if split[0] == f.entries[i].Name {
if len(split) == 1 {
in, err := f.r.getInodeFromEntry(f.entries[i])
if err != nil {
@@ -401,7 +417,8 @@ func (f FS) Sub(dir string) (fs.FS, error) {
Err: err,
}
}
return &FS{
return FS{
i: in,
r: f.r,
parent: &f,
name: f.entries[i].Name,