Add support for symlinks

This commit is contained in:
Anders F Björklund
2025-03-15 17:43:55 +01:00
parent 24a9457c6b
commit cef9090210
2 changed files with 36 additions and 2 deletions
+25 -2
View File
@@ -6,14 +6,33 @@ import (
"io/fs"
"os"
"path/filepath"
"strings"
"time"
"github.com/CalebQ42/squashfs"
)
func printEntry(root, path string, d fs.DirEntry) {
fi, _ := d.Info()
sfi := fi.(squashfs.FileInfo)
owner := fmt.Sprintf("%d/%d",
sfi.Uid(),
sfi.Gid())
link := ""
if sfi.IsSymlink() {
link = " -> " + sfi.SymlinkPath()
}
fmt.Printf("%s %s %*d %s %s%s\n",
strings.ToLower(fi.Mode().String()),
owner, 26-len(owner), fi.Size(),
fi.ModTime().Format("2006-01-02 15:04"),
filepath.Join(root, path), link)
}
func main() {
verbose := flag.Bool("v", false, "Verbose")
list := flag.Bool("l", false, "List")
long := flag.Bool("ll", false, "List with attributes")
ignore := flag.Bool("ip", false, "Ignore Permissions and extract all files/folders with 0755")
flag.Parse()
if len(flag.Args()) < 2 {
@@ -28,13 +47,17 @@ func main() {
if err != nil {
panic(err)
}
if *list {
if *list || *long {
root := flag.Arg(1)
fs.WalkDir(r, ".", func(path string, d fs.DirEntry, err error) error {
if err != nil {
panic(err)
}
fmt.Println(filepath.Join(root, path))
if *long {
printEntry(root, path, d)
} else {
fmt.Println(filepath.Join(root, path))
}
return nil
})
return