Reader will now check BlockLog
This commit is contained in:
@@ -105,6 +105,7 @@ func (f *File) Sys() interface{} {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
//Close does nothing. It's simply here to satisfy fs.File
|
//Close does nothing. It's simply here to satisfy fs.File
|
||||||
|
//TODO: add actual implementation
|
||||||
// func (f *File) Close() error {
|
// func (f *File) Close() error {
|
||||||
// return nil
|
// return nil
|
||||||
// }
|
// }
|
||||||
@@ -293,13 +294,6 @@ func (f *File) Mode() os.FileMode {
|
|||||||
return mode
|
return mode
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: Implement with 1.16
|
|
||||||
|
|
||||||
//Type returns the type bits from fs.FileMode
|
|
||||||
// func (f *File) Type() fs.FileInfo {
|
|
||||||
// return Mod() ^&fs.ModePerm
|
|
||||||
// }
|
|
||||||
|
|
||||||
//ExtractTo extracts the file to the given path. This is the same as ExtractWithOptions(path, false, false, os.ModePerm, false).
|
//ExtractTo extracts the file to the given path. This is the same as ExtractWithOptions(path, false, false, os.ModePerm, false).
|
||||||
//Will NOT try to keep symlinks valid, folders extracted will have the permissions set by the squashfs, but the folder to make path will have full permissions (777).
|
//Will NOT try to keep symlinks valid, folders extracted will have the permissions set by the squashfs, but the folder to make path will have full permissions (777).
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ var (
|
|||||||
ErrOptions = errors.New("Possibly incompatible compressor options")
|
ErrOptions = errors.New("Possibly incompatible compressor options")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//TODO: implement fs.FS, possibly more FS types for compatibility. Most of this work will mostly be handed off to root anyway so this shouldn't be too difficult.
|
||||||
|
|
||||||
//Reader processes and reads a squashfs archive.
|
//Reader processes and reads a squashfs archive.
|
||||||
type Reader struct {
|
type Reader struct {
|
||||||
r io.ReaderAt
|
r io.ReaderAt
|
||||||
@@ -39,7 +41,6 @@ type Reader struct {
|
|||||||
|
|
||||||
//NewSquashfsReader returns a new squashfs.Reader from an io.ReaderAt
|
//NewSquashfsReader returns a new squashfs.Reader from an io.ReaderAt
|
||||||
func NewSquashfsReader(r io.ReaderAt) (*Reader, error) {
|
func NewSquashfsReader(r io.ReaderAt) (*Reader, error) {
|
||||||
hasUnsupportedOptions := false
|
|
||||||
var rdr Reader
|
var rdr Reader
|
||||||
rdr.r = r
|
rdr.r = r
|
||||||
err := binary.Read(io.NewSectionReader(rdr.r, 0, int64(binary.Size(rdr.super))), binary.LittleEndian, &rdr.super)
|
err := binary.Read(io.NewSectionReader(rdr.r, 0, int64(binary.Size(rdr.super))), binary.LittleEndian, &rdr.super)
|
||||||
@@ -49,9 +50,10 @@ func NewSquashfsReader(r io.ReaderAt) (*Reader, error) {
|
|||||||
if rdr.super.Magic != magic {
|
if rdr.super.Magic != magic {
|
||||||
return nil, errNoMagic
|
return nil, errNoMagic
|
||||||
}
|
}
|
||||||
// if rdr.super.BlockLog == uint16(math.Log2(float64(rdr.super.BlockSize))) {
|
if rdr.super.BlockLog != uint16(math.Log2(float64(rdr.super.BlockSize))) {
|
||||||
// return nil, errors.New("BlockSize and BlockLog doesn't match. The archive is probably corrupt")
|
return nil, errors.New("BlockSize and BlockLog doesn't match. The archive is probably corrupt")
|
||||||
// }
|
}
|
||||||
|
hasUnsupportedOptions := false
|
||||||
rdr.flags = rdr.super.GetFlags()
|
rdr.flags = rdr.super.GetFlags()
|
||||||
if rdr.flags.compressorOptions {
|
if rdr.flags.compressorOptions {
|
||||||
switch rdr.super.CompressionType {
|
switch rdr.super.CompressionType {
|
||||||
|
|||||||
+3
-8
@@ -3,6 +3,7 @@ package squashfs
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"math"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
@@ -69,19 +70,13 @@ func TestAppImage(t *testing.T) {
|
|||||||
}
|
}
|
||||||
defer aiFil.Close()
|
defer aiFil.Close()
|
||||||
stat, _ := aiFil.Stat()
|
stat, _ := aiFil.Stat()
|
||||||
os.RemoveAll(wd + "/testing/firefox")
|
|
||||||
ai := goappimage.NewAppImage(wd + "/testing/" + appImageName)
|
ai := goappimage.NewAppImage(wd + "/testing/" + appImageName)
|
||||||
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)
|
||||||
}
|
}
|
||||||
desktop := rdr.GetFileAtPath("*.desktop")
|
fmt.Println(rdr.super.BlockLog, strconv.FormatInt(int64(rdr.super.BlockSize), 2))
|
||||||
if desktop == nil {
|
fmt.Println(math.Log2(float64(rdr.super.BlockSize)))
|
||||||
t.Fatal("Problema!")
|
|
||||||
}
|
|
||||||
os.Remove(wd + "/testing/cura.desktop")
|
|
||||||
deskFil, _ := os.Create(wd + "/testing/cura.desktop")
|
|
||||||
io.Copy(deskFil, desktop.Sys().(io.Reader))
|
|
||||||
t.Fatal("No problemo!")
|
t.Fatal("No problemo!")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import (
|
|||||||
"github.com/CalebQ42/squashfs/internal/compression"
|
"github.com/CalebQ42/squashfs/internal/compression"
|
||||||
)
|
)
|
||||||
|
|
||||||
//Writer is used to creaste squashfs archives. Currently unusable
|
//Writer is used to creaste squashfs archives. Currently unusable.
|
||||||
//TODO: Make usable
|
//TODO: Make usable
|
||||||
type Writer struct {
|
type Writer struct {
|
||||||
compressor compression.Compressor
|
compressor compression.Compressor
|
||||||
@@ -21,8 +21,9 @@ type Writer struct {
|
|||||||
symlinkTable map[string]string //[oldpath]newpath
|
symlinkTable map[string]string //[oldpath]newpath
|
||||||
uidGUIDTable []int
|
uidGUIDTable []int
|
||||||
compressionType int
|
compressionType int
|
||||||
//BlockSize is how large the data blocks are. Can be between 4096 (4KB) and 1048576 (1 MB). Default is 1048576.
|
//BlockSize is how large the data blocks are. Can be between 4096 (4KB) and 1048576 (1 MB).
|
||||||
//If BlockSize is not inside that range, it will be set to within the range before writing
|
//If BlockSize is not inside that range, it will be set to within the range before writing.
|
||||||
|
//Default is 1048576.
|
||||||
BlockSize uint32
|
BlockSize uint32
|
||||||
//Flags are the SuperblockFlags used when writing the archive.
|
//Flags are the SuperblockFlags used when writing the archive.
|
||||||
//Currently Duplicates, Exportable, UncompressedXattr, NoXattr values are ignored
|
//Currently Duplicates, Exportable, UncompressedXattr, NoXattr values are ignored
|
||||||
|
|||||||
Reference in New Issue
Block a user