Things just aren't working right now...

Had to re-write a seemingly fine for loop because it wouldn't increment
Extracting just isn't working right now.
I'm waaaay too tired for this right now, lol.
This commit is contained in:
Caleb Gardner
2020-12-01 15:29:25 -06:00
parent e302d98665
commit 28bb0f873a
2 changed files with 47 additions and 38 deletions
+22 -4
View File
@@ -237,10 +237,11 @@ func (f *File) ExtractWithOptions(path string, unbreakSymlink bool, folderPerm o
case f.IsDir(): case f.IsDir():
if f.Name != "" { if f.Name != "" {
//TODO: check if folder is present, and if so, try to set it's permission //TODO: check if folder is present, and if so, try to set it's permission
err = os.Mkdir(path+"/"+f.Name, f.Permission()) err = os.Mkdir(path+"/"+f.Name, os.ModePerm)
if err != nil { if err != nil {
if verbose { if verbose {
fmt.Println("Error while making: ", path+"/"+f.Name) fmt.Println("Error while making: ", path+"/"+f.Name)
fmt.Println(err)
} }
errs = append(errs, err) errs = append(errs, err)
return return
@@ -249,6 +250,7 @@ func (f *File) ExtractWithOptions(path string, unbreakSymlink bool, folderPerm o
if err != nil { if err != nil {
if verbose { if verbose {
fmt.Println("Error while opening:", path+"/"+f.Name) fmt.Println("Error while opening:", path+"/"+f.Name)
fmt.Println(err)
} }
errs = append(errs, err) errs = append(errs, err)
return return
@@ -257,15 +259,24 @@ func (f *File) ExtractWithOptions(path string, unbreakSymlink bool, folderPerm o
if err != nil { if err != nil {
if verbose { if verbose {
fmt.Println("Error while changing owner:", path+"/"+f.Name) fmt.Println("Error while changing owner:", path+"/"+f.Name)
fmt.Println(err)
}
errs = append(errs, err)
}
err = fil.Chmod(f.Permission())
if err != nil {
if verbose {
fmt.Println("Error while changing owner:", path+"/"+f.Name)
fmt.Println(err)
} }
errs = append(errs, err) errs = append(errs, err)
return
} }
} }
children, err := f.GetChildren() children, err := f.GetChildren()
if err != nil { if err != nil {
if verbose { if verbose {
fmt.Println("Error getting children for:", f.Path()) fmt.Println("Error getting children for:", f.Path())
fmt.Println(err)
} }
errs = append(errs, err) errs = append(errs, err)
return return
@@ -292,6 +303,7 @@ func (f *File) ExtractWithOptions(path string, unbreakSymlink bool, folderPerm o
if err != nil { if err != nil {
if verbose { if verbose {
fmt.Println("Error while making:", path+"/"+f.Name) fmt.Println("Error while making:", path+"/"+f.Name)
fmt.Println(err)
} }
errs = append(errs, err) errs = append(errs, err)
return return
@@ -300,6 +312,7 @@ func (f *File) ExtractWithOptions(path string, unbreakSymlink bool, folderPerm o
if err != nil { if err != nil {
if verbose { if verbose {
fmt.Println("Error while making:", path+"/"+f.Name) fmt.Println("Error while making:", path+"/"+f.Name)
fmt.Println(err)
} }
errs = append(errs, err) errs = append(errs, err)
return return
@@ -307,15 +320,17 @@ func (f *File) ExtractWithOptions(path string, unbreakSymlink bool, folderPerm o
} else if err != nil { } else if err != nil {
if verbose { if verbose {
fmt.Println("Error while making:", path+"/"+f.Name) fmt.Println("Error while making:", path+"/"+f.Name)
fmt.Println(err)
} }
errs = append(errs, err) errs = append(errs, err)
return return
} }
defer f.Close() //Since we will be reading from the file // defer f.Close() //Since we will be reading from the file
_, err = io.Copy(fil, f) _, err = io.Copy(fil, f)
if err != nil { if err != nil {
if verbose { if verbose {
fmt.Println("Error while Copying data to:", path+"/"+f.Name) fmt.Println("Error while Copying data to:", path+"/"+f.Name)
fmt.Println(err)
} }
errs = append(errs, err) errs = append(errs, err)
return return
@@ -324,6 +339,7 @@ func (f *File) ExtractWithOptions(path string, unbreakSymlink bool, folderPerm o
if err != nil { if err != nil {
if verbose { if verbose {
fmt.Println("Error while changing owner:", path+"/"+f.Name) fmt.Println("Error while changing owner:", path+"/"+f.Name)
fmt.Println(err)
} }
errs = append(errs, err) errs = append(errs, err)
return return
@@ -332,12 +348,14 @@ func (f *File) ExtractWithOptions(path string, unbreakSymlink bool, folderPerm o
if err != nil { if err != nil {
if verbose { if verbose {
fmt.Println("Error while setting permissions for:", path+"/"+f.Name) fmt.Println("Error while setting permissions for:", path+"/"+f.Name)
fmt.Println(err)
} }
errs = append(errs, err) errs = append(errs, err)
} }
return return
case f.IsSymlink(): case f.IsSymlink():
return []error{errors.New("Symlink not supported (yet)")} //just a temp thing real quick
os.Symlink(f.SymlinkPath(), path+"/"+f.Name)
} }
return return
} }
+15 -24
View File
@@ -3,7 +3,6 @@ package squashfs
import ( import (
"encoding/binary" "encoding/binary"
"errors" "errors"
"fmt"
"io" "io"
"math" "math"
@@ -55,10 +54,10 @@ func NewSquashfsReader(r io.ReaderAt) (*Reader, error) {
//TODO: all compression types. //TODO: all compression types.
return nil, errIncompatibleCompression return nil, errIncompatibleCompression
} }
if rdr.flags.CompressorOptions { // if rdr.flags.CompressorOptions {
//TODO: parse compressor options // //TODO: parse compressor options
return nil, errCompressorOptions // return nil, errCompressorOptions
} // }
fragBlocks := int(math.Ceil(float64(rdr.super.FragCount) / 512)) fragBlocks := int(math.Ceil(float64(rdr.super.FragCount) / 512))
if fragBlocks > 0 { if fragBlocks > 0 {
offset := int64(rdr.super.FragTableStart) offset := int64(rdr.super.FragTableStart)
@@ -72,36 +71,28 @@ func NewSquashfsReader(r io.ReaderAt) (*Reader, error) {
offset += 8 offset += 8
} }
} }
idBlocks := int(math.Ceil(float64(rdr.super.IDCount) / 2048))
fmt.Println("ID Blocks", idBlocks)
for idBlocks > 0 {
unread := rdr.super.IDCount unread := rdr.super.IDCount
offset := int64(rdr.super.IDTableStart) blockOffsets := make([]uint64, int(math.Ceil(float64(rdr.super.IDCount)/2048)))
for i := 0; i < idBlocks; i++ { for i := range blockOffsets {
tmp := make([]byte, 8) secRdr := io.NewSectionReader(r, int64(rdr.super.IDTableStart)+8*int64(i), 8)
_, err = r.ReadAt(tmp, offset) err = binary.Read(secRdr, binary.LittleEndian, &blockOffsets[i])
if err != nil { if err != nil {
return nil, err return nil, err
} }
offset += 8 idRdr, err := rdr.newMetadataReader(int64(blockOffsets[i]))
idRdr, err := rdr.newMetadataReader(int64(binary.LittleEndian.Uint64(tmp)))
if err != nil { if err != nil {
return nil, err return nil, err
} }
for j := 0; j < int(math.Min(float64(unread), 2048)); j++ { read := uint16(math.Min(float64(unread), 2048))
var id uint32 for i := uint16(0); i < read; i++ {
err = binary.Read(idRdr, binary.LittleEndian, &id) var tmp uint32
err = binary.Read(idRdr, binary.LittleEndian, &tmp)
if err != nil { if err != nil {
return nil, err return nil, err
} }
rdr.idTable = append(rdr.idTable, id) rdr.idTable = append(rdr.idTable, tmp)
}
if unread > 2048 {
unread -= 2048
} else {
unread = 0
}
} }
unread -= read
} }
return &rdr, nil return &rdr, nil
} }