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:
@@ -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
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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))
|
unread := rdr.super.IDCount
|
||||||
fmt.Println("ID Blocks", idBlocks)
|
blockOffsets := make([]uint64, int(math.Ceil(float64(rdr.super.IDCount)/2048)))
|
||||||
for idBlocks > 0 {
|
for i := range blockOffsets {
|
||||||
unread := rdr.super.IDCount
|
secRdr := io.NewSectionReader(r, int64(rdr.super.IDTableStart)+8*int64(i), 8)
|
||||||
offset := int64(rdr.super.IDTableStart)
|
err = binary.Read(secRdr, binary.LittleEndian, &blockOffsets[i])
|
||||||
for i := 0; i < idBlocks; i++ {
|
if err != nil {
|
||||||
tmp := make([]byte, 8)
|
return nil, err
|
||||||
_, 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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
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
|
return &rdr, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user