Compare commits

..

2 Commits

Author SHA1 Message Date
Caleb Gardner 17e1d65488 Fixed Extended Files 2021-01-16 03:09:48 -06:00
Caleb Gardner 80946f58e7 Fixed issue with Extended Symlinks
Removed some shadowed err's
2021-01-16 01:32:00 -06:00
5 changed files with 32 additions and 29 deletions
+3 -3
View File
@@ -203,7 +203,7 @@ func (f *File) IsDir() bool {
//IsSymlink returns if the file is a symlink. //IsSymlink returns if the file is a symlink.
func (f *File) IsSymlink() bool { func (f *File) IsSymlink() bool {
return f.filType == inode.SymType || f.filType == inode.ExtSymlinkType return f.filType == inode.SymType || f.filType == inode.ExtSymType
} }
//IsFile returns if the file is a file. //IsFile returns if the file is a file.
@@ -217,8 +217,8 @@ func (f *File) SymlinkPath() string {
switch f.filType { switch f.filType {
case inode.SymType: case inode.SymType:
return f.in.Info.(inode.Sym).Path return f.in.Info.(inode.Sym).Path
case inode.ExtSymlinkType: case inode.ExtSymType:
return f.in.Info.(inode.Sym).Path return f.in.Info.(inode.ExtSym).Path
default: default:
return "" return ""
} }
+4 -4
View File
@@ -18,7 +18,7 @@ type fragmentEntry struct {
//GetFragmentDataFromInode returns the fragment data for a given inode. //GetFragmentDataFromInode returns the fragment data for a given inode.
//If the inode does not have a fragment, harmlessly returns an empty slice without an error. //If the inode does not have a fragment, harmlessly returns an empty slice without an error.
func (r *Reader) getFragmentDataFromInode(in *inode.Inode) ([]byte, error) { func (r *Reader) getFragmentDataFromInode(in *inode.Inode) ([]byte, error) {
var size uint32 var size uint64
var fragIndex uint32 var fragIndex uint32
var fragOffset uint32 var fragOffset uint32
if in.Type == inode.FileType { if in.Type == inode.FileType {
@@ -27,9 +27,9 @@ func (r *Reader) getFragmentDataFromInode(in *inode.Inode) ([]byte, error) {
return make([]byte, 0), nil return make([]byte, 0), nil
} }
if bf.BlockStart == 0 { if bf.BlockStart == 0 {
size = bf.Size size = uint64(bf.Size)
} else { } else {
size = bf.BlockSizes[len(bf.BlockSizes)-1] size = uint64(bf.BlockSizes[len(bf.BlockSizes)-1])
} }
fragIndex = bf.FragmentIndex fragIndex = bf.FragmentIndex
fragOffset = bf.FragmentOffset fragOffset = bf.FragmentOffset
@@ -41,7 +41,7 @@ func (r *Reader) getFragmentDataFromInode(in *inode.Inode) ([]byte, error) {
if bf.BlockStart == 0 { if bf.BlockStart == 0 {
size = bf.Size size = bf.Size
} else { } else {
size = bf.BlockSizes[len(bf.BlockSizes)-1] size = uint64(bf.BlockSizes[len(bf.BlockSizes)-1])
} }
fragIndex = bf.FragmentIndex fragIndex = bf.FragmentIndex
fragOffset = bf.FragmentOffset fragOffset = bf.FragmentOffset
+7 -6
View File
@@ -16,7 +16,7 @@ const (
SocketType SocketType
ExtDirType ExtDirType
ExtFileType ExtFileType
ExtSymlinkType ExtSymType
ExtBlockDeviceType ExtBlockDeviceType
ExtCharDeviceType ExtCharDeviceType
ExtFifoType ExtFifoType
@@ -67,7 +67,8 @@ func NewExtendedDirectory(rdr io.Reader) (ExtDir, error) {
return inode, err return inode, err
} }
for i := uint16(0); i < inode.IndexCount; i++ { for i := uint16(0); i < inode.IndexCount; i++ {
tmp, err := NewDirectoryIndex(rdr) var tmp DirIndex
tmp, err = NewDirectoryIndex(rdr)
if err != nil { if err != nil {
return inode, err return inode, err
} }
@@ -139,8 +140,8 @@ func NewFile(rdr io.Reader, blockSize uint32) (File, error) {
//ExtFileInit is the information that can be directly decoded //ExtFileInit is the information that can be directly decoded
type ExtFileInit struct { type ExtFileInit struct {
BlockStart uint32 BlockStart uint64
Size uint32 Size uint64
Sparse uint64 Sparse uint64
HardLinks uint32 HardLinks uint32
FragmentIndex uint32 FragmentIndex uint32
@@ -163,8 +164,8 @@ func NewExtendedFile(rdr io.Reader, blockSize uint32) (ExtFile, error) {
return inode, err return inode, err
} }
inode.Fragmented = inode.FragmentIndex != 0xFFFFFFFF inode.Fragmented = inode.FragmentIndex != 0xFFFFFFFF
blocks := inode.Size / blockSize blocks := inode.Size / uint64(blockSize)
if inode.Size%blockSize > 0 { if inode.Size%uint64(blockSize) > 0 {
blocks++ blocks++
} }
inode.BlockSizes = make([]uint32, blocks, blocks) inode.BlockSizes = make([]uint32, blocks, blocks)
+11 -6
View File
@@ -31,13 +31,15 @@ func ProcessInode(br io.Reader, blockSize uint32) (*Inode, error) {
} }
info = inode info = inode
case FileType: case FileType:
inode, err := NewFile(br, blockSize) var inode File
inode, err = NewFile(br, blockSize)
if err != nil { if err != nil {
return nil, err return nil, err
} }
info = inode info = inode
case SymType: case SymType:
inode, err := NewSymlink(br) var inode Sym
inode, err = NewSymlink(br)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -71,19 +73,22 @@ func ProcessInode(br io.Reader, blockSize uint32) (*Inode, error) {
} }
info = inode info = inode
case ExtDirType: case ExtDirType:
inode, err := NewExtendedDirectory(br) var inode ExtDir
inode, err = NewExtendedDirectory(br)
if err != nil { if err != nil {
return nil, err return nil, err
} }
info = inode info = inode
case ExtFileType: case ExtFileType:
inode, err := NewExtendedFile(br, blockSize) var inode ExtFile
inode, err = NewExtendedFile(br, blockSize)
if err != nil { if err != nil {
return nil, err return nil, err
} }
info = inode info = inode
case ExtSymlinkType: case ExtSymType:
inode, err := NewExtendedSymlink(br) var inode ExtSym
inode, err = NewExtendedSymlink(br)
if err != nil { if err != nil {
return nil, err return nil, err
} }
+7 -10
View File
@@ -15,7 +15,7 @@ import (
const ( const (
downloadURL = "https://github.com/srevinsaju/Firefox-Appimage/releases/download/firefox-v84.0.r20201221152838/firefox-84.0.r20201221152838-x86_64.AppImage" downloadURL = "https://github.com/srevinsaju/Firefox-Appimage/releases/download/firefox-v84.0.r20201221152838/firefox-84.0.r20201221152838-x86_64.AppImage"
appImageName = "firefox-84.0.r20201221152838-x86_64.AppImage" appImageName = "Ultimaker_Cura-4.8.0.AppImage"
squashfsName = "balenaEtcher-1.5.113-x64.AppImage.sfs" squashfsName = "balenaEtcher-1.5.113-x64.AppImage.sfs"
) )
@@ -71,20 +71,17 @@ func TestAppImage(t *testing.T) {
stat, _ := aiFil.Stat() stat, _ := aiFil.Stat()
os.RemoveAll(wd + "/testing/firefox") os.RemoveAll(wd + "/testing/firefox")
ai := goappimage.NewAppImage(wd + "/testing/" + appImageName) ai := goappimage.NewAppImage(wd + "/testing/" + appImageName)
start := time.Now()
rdr, err := NewSquashfsReader(io.NewSectionReader(aiFil, ai.Offset, stat.Size()-ai.Offset)) rdr, err := NewSquashfsReader(io.NewSectionReader(aiFil, ai.Offset, stat.Size()-ai.Offset))
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
rt := rdr.GetFileAtPath("/") desktop := rdr.GetFileAtPath("*.desktop")
fils, err := rt.GetChildrenRecursively() if desktop == nil {
if err != nil { t.Fatal("Problema!")
t.Fatal(err)
} }
for _, fil := range fils { os.Remove(wd + "/testing/cura.desktop")
fmt.Println(fil.Path()) deskFil, _ := os.Create(wd + "/testing/cura.desktop")
} io.Copy(deskFil, desktop.Sys().(io.Reader))
fmt.Println(time.Since(start))
t.Fatal("No problemo!") t.Fatal("No problemo!")
} }