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():
if f.Name != "" {
//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 verbose {
fmt.Println("Error while making: ", path+"/"+f.Name)
fmt.Println(err)
}
errs = append(errs, err)
return
@@ -249,6 +250,7 @@ func (f *File) ExtractWithOptions(path string, unbreakSymlink bool, folderPerm o
if err != nil {
if verbose {
fmt.Println("Error while opening:", path+"/"+f.Name)
fmt.Println(err)
}
errs = append(errs, err)
return
@@ -257,15 +259,24 @@ func (f *File) ExtractWithOptions(path string, unbreakSymlink bool, folderPerm o
if err != nil {
if verbose {
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)
return
}
}
children, err := f.GetChildren()
if err != nil {
if verbose {
fmt.Println("Error getting children for:", f.Path())
fmt.Println(err)
}
errs = append(errs, err)
return
@@ -292,6 +303,7 @@ func (f *File) ExtractWithOptions(path string, unbreakSymlink bool, folderPerm o
if err != nil {
if verbose {
fmt.Println("Error while making:", path+"/"+f.Name)
fmt.Println(err)
}
errs = append(errs, err)
return
@@ -300,6 +312,7 @@ func (f *File) ExtractWithOptions(path string, unbreakSymlink bool, folderPerm o
if err != nil {
if verbose {
fmt.Println("Error while making:", path+"/"+f.Name)
fmt.Println(err)
}
errs = append(errs, err)
return
@@ -307,15 +320,17 @@ func (f *File) ExtractWithOptions(path string, unbreakSymlink bool, folderPerm o
} else if err != nil {
if verbose {
fmt.Println("Error while making:", path+"/"+f.Name)
fmt.Println(err)
}
errs = append(errs, err)
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)
if err != nil {
if verbose {
fmt.Println("Error while Copying data to:", path+"/"+f.Name)
fmt.Println(err)
}
errs = append(errs, err)
return
@@ -324,6 +339,7 @@ func (f *File) ExtractWithOptions(path string, unbreakSymlink bool, folderPerm o
if err != nil {
if verbose {
fmt.Println("Error while changing owner:", path+"/"+f.Name)
fmt.Println(err)
}
errs = append(errs, err)
return
@@ -332,12 +348,14 @@ func (f *File) ExtractWithOptions(path string, unbreakSymlink bool, folderPerm o
if err != nil {
if verbose {
fmt.Println("Error while setting permissions for:", path+"/"+f.Name)
fmt.Println(err)
}
errs = append(errs, err)
}
return
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
}
+25 -34
View File
@@ -3,7 +3,6 @@ package squashfs
import (
"encoding/binary"
"errors"
"fmt"
"io"
"math"
@@ -55,10 +54,10 @@ func NewSquashfsReader(r io.ReaderAt) (*Reader, error) {
//TODO: all compression types.
return nil, errIncompatibleCompression
}
if rdr.flags.CompressorOptions {
//TODO: parse compressor options
return nil, errCompressorOptions
}
// if rdr.flags.CompressorOptions {
// //TODO: parse compressor options
// return nil, errCompressorOptions
// }
fragBlocks := int(math.Ceil(float64(rdr.super.FragCount) / 512))
if fragBlocks > 0 {
offset := int64(rdr.super.FragTableStart)
@@ -72,36 +71,28 @@ func NewSquashfsReader(r io.ReaderAt) (*Reader, error) {
offset += 8
}
}
idBlocks := int(math.Ceil(float64(rdr.super.IDCount) / 2048))
fmt.Println("ID Blocks", idBlocks)
for idBlocks > 0 {
unread := rdr.super.IDCount
offset := int64(rdr.super.IDTableStart)
for i := 0; i < idBlocks; i++ {
tmp := make([]byte, 8)
_, err = r.ReadAt(tmp, offset)
if err != nil {
return nil, err
}
offset += 8
idRdr, err := rdr.newMetadataReader(int64(binary.LittleEndian.Uint64(tmp)))
if err != nil {
return nil, err
}
for j := 0; j < int(math.Min(float64(unread), 2048)); j++ {
var id uint32
err = binary.Read(idRdr, binary.LittleEndian, &id)
if err != nil {
return nil, err
}
rdr.idTable = append(rdr.idTable, id)
}
if unread > 2048 {
unread -= 2048
} else {
unread = 0
}
unread := rdr.super.IDCount
blockOffsets := make([]uint64, int(math.Ceil(float64(rdr.super.IDCount)/2048)))
for i := range blockOffsets {
secRdr := io.NewSectionReader(r, int64(rdr.super.IDTableStart)+8*int64(i), 8)
err = binary.Read(secRdr, binary.LittleEndian, &blockOffsets[i])
if err != nil {
return nil, err
}
idRdr, err := rdr.newMetadataReader(int64(blockOffsets[i]))
if err != nil {
return nil, err
}
read := uint16(math.Min(float64(unread), 2048))
for i := uint16(0); i < read; i++ {
var tmp uint32
err = binary.Read(idRdr, binary.LittleEndian, &tmp)
if err != nil {
return nil, err
}
rdr.idTable = append(rdr.idTable, tmp)
}
unread -= read
}
return &rdr, nil
}