Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a298a3d7b5 | |||
| 89ec7eb0fb | |||
| d63ba47818 | |||
| 495d2345a4 |
@@ -12,7 +12,3 @@ Special thanks to https://dr-emann.github.io/squashfs/ for some VERY important i
|
|||||||
Thanks also to [distri's squashfs library](https://github.com/distr1/distri/tree/master/internal/squashfs) as I referenced it to figure some things out (and double check others).
|
Thanks also to [distri's squashfs library](https://github.com/distr1/distri/tree/master/internal/squashfs) as I referenced it to figure some things out (and double check others).
|
||||||
|
|
||||||
# [TODO](https://github.com/CalebQ42/squashfs/projects/1?fullscreen=true)
|
# [TODO](https://github.com/CalebQ42/squashfs/projects/1?fullscreen=true)
|
||||||
|
|
||||||
# Where I'm at
|
|
||||||
|
|
||||||
* Working on the File interface that should make it easier to deal with squashfs files. I'm also trying to make them capable for when I get squashing working.
|
|
||||||
+1
-1
@@ -175,12 +175,12 @@ func (d *dataReader) Read(p []byte) (int, error) {
|
|||||||
d.curReadOffset = 0
|
d.curReadOffset = 0
|
||||||
}
|
}
|
||||||
for ; read < len(p); read++ {
|
for ; read < len(p); read++ {
|
||||||
d.curReadOffset++
|
|
||||||
if d.curReadOffset < len(d.curData) {
|
if d.curReadOffset < len(d.curData) {
|
||||||
p[read] = d.curData[d.curReadOffset]
|
p[read] = d.curData[d.curReadOffset]
|
||||||
} else {
|
} else {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
d.curReadOffset++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if read != len(p) {
|
if read != len(p) {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/CalebQ42/squashfs/internal/directory"
|
"github.com/CalebQ42/squashfs/internal/directory"
|
||||||
"github.com/CalebQ42/squashfs/internal/inode"
|
"github.com/CalebQ42/squashfs/internal/inode"
|
||||||
@@ -26,10 +27,12 @@ var (
|
|||||||
//File is the main way to interact with files within squashfs, or when putting files into a squashfs.
|
//File is the main way to interact with files within squashfs, or when putting files into a squashfs.
|
||||||
//File can be either a file or folder. When reading from a squashfs, it reads from the datablocks.
|
//File can be either a file or folder. When reading from a squashfs, it reads from the datablocks.
|
||||||
//When writing, this holds the information on WHERE the file will be placed inside the archive.
|
//When writing, this holds the information on WHERE the file will be placed inside the archive.
|
||||||
|
//
|
||||||
|
//Implements os.FileInfo and io.ReadCloser
|
||||||
type File struct {
|
type File struct {
|
||||||
Name string //The name of the file or folder. Root folder will not have a name ("")
|
|
||||||
Parent *File //The parent directory. Should ALWAYS be a folder. If it's the root directory, will be nil
|
Parent *File //The parent directory. Should ALWAYS be a folder. If it's the root directory, will be nil
|
||||||
Reader io.Reader //Underlying reader. When writing, will probably be an os.File. When reading this is kept nil UNTIL reading to save memory.
|
Reader io.Reader //Underlying reader. When writing, will probably be an os.File. When reading this is kept nil UNTIL reading to save memory.
|
||||||
|
name string //The name of the file or folder. Root folder will not have a name ("")
|
||||||
path string //The path to the folder the File is located in.
|
path string //The path to the folder the File is located in.
|
||||||
r *Reader //The squashfs.Reader where this file is contained.
|
r *Reader //The squashfs.Reader where this file is contained.
|
||||||
in *inode.Inode //Underlyting inode when reading.
|
in *inode.Inode //Underlyting inode when reading.
|
||||||
@@ -43,12 +46,50 @@ func (r *Reader) newFileFromDirEntry(entry *directory.Entry) (fil *File, err err
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
fil.Name = entry.Name
|
fil.name = entry.Name
|
||||||
fil.r = r
|
fil.r = r
|
||||||
fil.filType = fil.in.Type
|
fil.filType = fil.in.Type
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Name is the file's name
|
||||||
|
func (f *File) Name() string {
|
||||||
|
return f.name
|
||||||
|
}
|
||||||
|
|
||||||
|
//Size is the complete size of the file. Zero if it's not a file.
|
||||||
|
func (f *File) Size() int64 {
|
||||||
|
switch f.filType {
|
||||||
|
case inode.BasicFileType:
|
||||||
|
return int64(f.in.Info.(inode.BasicFile).Init.Size)
|
||||||
|
case inode.ExtFileType:
|
||||||
|
return int64(f.in.Info.(inode.ExtendedFile).Init.Size)
|
||||||
|
default:
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//ModTime is the time of last modification.
|
||||||
|
func (f *File) ModTime() time.Time {
|
||||||
|
return time.Unix(int64(f.in.Header.ModifiedTime), 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
//Sys returns the underlying reader, file.Reader. If the reader isn't initialized, it will initialize it.
|
||||||
|
//If called on something other then a file, returns nil.
|
||||||
|
func (f *File) Sys() interface{} {
|
||||||
|
if f.IsFile() {
|
||||||
|
if f.Reader == nil && f.r != nil {
|
||||||
|
var err error
|
||||||
|
f.Reader, err = f.r.newFileReader(f.in)
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return f.Reader
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
//GetChildren returns a *squashfs.File slice of every direct child of the directory. If the File is not a directory, will return ErrNotDirectory
|
//GetChildren returns a *squashfs.File slice of every direct child of the directory. If the File is not a directory, will return ErrNotDirectory
|
||||||
func (f *File) GetChildren() (children []*File, err error) {
|
func (f *File) GetChildren() (children []*File, err error) {
|
||||||
children = make([]*File, 0)
|
children = make([]*File, 0)
|
||||||
@@ -69,7 +110,7 @@ func (f *File) GetChildren() (children []*File, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
fil.Parent = f
|
fil.Parent = f
|
||||||
if f.Name != "" {
|
if f.name != "" {
|
||||||
fil.path = f.Path()
|
fil.path = f.Path()
|
||||||
}
|
}
|
||||||
children = append(children, fil)
|
children = append(children, fil)
|
||||||
@@ -117,10 +158,10 @@ func (f *File) GetChildrenRecursively() (children []*File, err error) {
|
|||||||
|
|
||||||
//Path returns the path of the file within the archive.
|
//Path returns the path of the file within the archive.
|
||||||
func (f *File) Path() string {
|
func (f *File) Path() string {
|
||||||
if f.Name == "" {
|
if f.name == "" {
|
||||||
return f.path
|
return f.path
|
||||||
}
|
}
|
||||||
return f.path + "/" + f.Name
|
return f.path + "/" + f.name
|
||||||
}
|
}
|
||||||
|
|
||||||
//GetFileAtPath tries to return the File at the given path, relative to the file.
|
//GetFileAtPath tries to return the File at the given path, relative to the file.
|
||||||
@@ -139,7 +180,7 @@ func (f *File) GetFileAtPath(dirPath string) *File {
|
|||||||
dirPath = strings.TrimPrefix(dirPath, "./")
|
dirPath = strings.TrimPrefix(dirPath, "./")
|
||||||
}
|
}
|
||||||
split := strings.Split(dirPath, "/")
|
split := strings.Split(dirPath, "/")
|
||||||
if split[0] == ".." && f.Name == "" {
|
if split[0] == ".." && f.name == "" {
|
||||||
return nil
|
return nil
|
||||||
} else if split[0] == ".." {
|
} else if split[0] == ".." {
|
||||||
if f.Parent != nil {
|
if f.Parent != nil {
|
||||||
@@ -152,7 +193,7 @@ func (f *File) GetFileAtPath(dirPath string) *File {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
for _, child := range children {
|
for _, child := range children {
|
||||||
eq, _ := path.Match(split[0], child.Name)
|
eq, _ := path.Match(split[0], child.name)
|
||||||
if eq {
|
if eq {
|
||||||
return child.GetFileAtPath(strings.Join(split[1:], "/"))
|
return child.GetFileAtPath(strings.Join(split[1:], "/"))
|
||||||
}
|
}
|
||||||
@@ -188,7 +229,8 @@ func (f *File) SymlinkPath() string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//GetSymlinkFile tries to return the squashfs.File associated with the symlink
|
//GetSymlinkFile tries to return the squashfs.File associated with the symlink. If the file isn't a symlink
|
||||||
|
//or the symlink points to a location outside the archive, nil is returned.
|
||||||
func (f *File) GetSymlinkFile() *File {
|
func (f *File) GetSymlinkFile() *File {
|
||||||
if !f.IsSymlink() {
|
if !f.IsSymlink() {
|
||||||
return nil
|
return nil
|
||||||
@@ -196,11 +238,32 @@ func (f *File) GetSymlinkFile() *File {
|
|||||||
if strings.HasSuffix(f.SymlinkPath(), "/") {
|
if strings.HasSuffix(f.SymlinkPath(), "/") {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return f.r.GetFileAtPath(f.SymlinkPath())
|
return f.Parent.GetFileAtPath(f.SymlinkPath())
|
||||||
}
|
}
|
||||||
|
|
||||||
//Permission returns the os.FileMode of the File. Sets mode bits for directories and symlinks.
|
//GetSymlinkFileRecursive tries to return the squasfs.File associated with the symlink. It will recursively
|
||||||
func (f *File) Permission() os.FileMode {
|
//try to get the symlink's file. This will return either a non-symlink File, or nil.
|
||||||
|
func (f *File) GetSymlinkFileRecursive() *File {
|
||||||
|
if !f.IsSymlink() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if strings.HasSuffix(f.SymlinkPath(), "/") {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
sym := f
|
||||||
|
for {
|
||||||
|
sym = sym.GetSymlinkFile()
|
||||||
|
if sym == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if !sym.IsSymlink() {
|
||||||
|
return sym
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Mode returns the os.FileMode of the File. Sets mode bits for directories and symlinks.
|
||||||
|
func (f *File) Mode() os.FileMode {
|
||||||
mode := os.FileMode(f.in.Header.Permissions)
|
mode := os.FileMode(f.in.Header.Permissions)
|
||||||
switch {
|
switch {
|
||||||
case f.IsDir():
|
case f.IsDir():
|
||||||
@@ -244,21 +307,21 @@ func (f *File) ExtractWithOptions(path string, dereferenceSymlink, unbreakSymlin
|
|||||||
}
|
}
|
||||||
switch {
|
switch {
|
||||||
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, os.ModePerm)
|
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)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
errs = append(errs, err)
|
errs = append(errs, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fil, err := os.Open(path + "/" + f.Name)
|
fil, err := os.Open(path + "/" + f.name)
|
||||||
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)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
errs = append(errs, err)
|
errs = append(errs, err)
|
||||||
@@ -273,10 +336,10 @@ func (f *File) ExtractWithOptions(path string, dereferenceSymlink, unbreakSymlin
|
|||||||
// }
|
// }
|
||||||
// errs = append(errs, err)
|
// errs = append(errs, err)
|
||||||
// }
|
// }
|
||||||
err = fil.Chmod(f.Permission())
|
err = fil.Chmod(f.Mode())
|
||||||
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)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
errs = append(errs, err)
|
errs = append(errs, err)
|
||||||
@@ -295,10 +358,10 @@ func (f *File) ExtractWithOptions(path string, dereferenceSymlink, unbreakSymlin
|
|||||||
defer close(finishChan)
|
defer close(finishChan)
|
||||||
for _, child := range children {
|
for _, child := range children {
|
||||||
go func(child *File) {
|
go func(child *File) {
|
||||||
if f.Name == "" {
|
if f.name == "" {
|
||||||
finishChan <- child.ExtractWithOptions(path, dereferenceSymlink, unbreakSymlink, folderPerm, verbose)
|
finishChan <- child.ExtractWithOptions(path, dereferenceSymlink, unbreakSymlink, folderPerm, verbose)
|
||||||
} else {
|
} else {
|
||||||
finishChan <- child.ExtractWithOptions(path+"/"+f.Name, dereferenceSymlink, unbreakSymlink, folderPerm, verbose)
|
finishChan <- child.ExtractWithOptions(path+"/"+f.name, dereferenceSymlink, unbreakSymlink, folderPerm, verbose)
|
||||||
}
|
}
|
||||||
}(child)
|
}(child)
|
||||||
}
|
}
|
||||||
@@ -307,21 +370,21 @@ func (f *File) ExtractWithOptions(path string, dereferenceSymlink, unbreakSymlin
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
case f.IsFile():
|
case f.IsFile():
|
||||||
fil, err := os.Create(path + "/" + f.Name)
|
fil, err := os.Create(path + "/" + f.name)
|
||||||
if os.IsExist(err) {
|
if os.IsExist(err) {
|
||||||
err = os.Remove(path + "/" + f.Name)
|
err = os.Remove(path + "/" + f.name)
|
||||||
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)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
errs = append(errs, err)
|
errs = append(errs, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fil, err = os.Create(path + "/" + f.Name)
|
fil, err = os.Create(path + "/" + f.name)
|
||||||
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)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
errs = append(errs, err)
|
errs = append(errs, err)
|
||||||
@@ -329,7 +392,7 @@ func (f *File) ExtractWithOptions(path string, dereferenceSymlink, unbreakSymlin
|
|||||||
}
|
}
|
||||||
} 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)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
errs = append(errs, err)
|
errs = append(errs, err)
|
||||||
@@ -338,7 +401,7 @@ func (f *File) ExtractWithOptions(path string, dereferenceSymlink, unbreakSymlin
|
|||||||
_, 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)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
errs = append(errs, err)
|
errs = append(errs, err)
|
||||||
@@ -355,10 +418,10 @@ func (f *File) ExtractWithOptions(path string, dereferenceSymlink, unbreakSymlin
|
|||||||
// errs = append(errs, err)
|
// errs = append(errs, err)
|
||||||
// return
|
// return
|
||||||
// }
|
// }
|
||||||
err = fil.Chmod(f.Permission())
|
err = fil.Chmod(f.Mode())
|
||||||
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)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
errs = append(errs, err)
|
errs = append(errs, err)
|
||||||
@@ -370,15 +433,15 @@ func (f *File) ExtractWithOptions(path string, dereferenceSymlink, unbreakSymlin
|
|||||||
fil := f.GetSymlinkFile()
|
fil := f.GetSymlinkFile()
|
||||||
if fil == nil {
|
if fil == nil {
|
||||||
if verbose {
|
if verbose {
|
||||||
fmt.Println("Symlink path(", symPath, ") is outside the archive:"+path+"/"+f.Name)
|
fmt.Println("Symlink path(", symPath, ") is outside the archive:"+path+"/"+f.name)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fil.Name = f.Name
|
fil.name = f.name
|
||||||
extracSymErrs := fil.ExtractWithOptions(path, dereferenceSymlink, unbreakSymlink, folderPerm, verbose)
|
extracSymErrs := fil.ExtractWithOptions(path, dereferenceSymlink, unbreakSymlink, folderPerm, verbose)
|
||||||
if len(extracSymErrs) > 0 {
|
if len(extracSymErrs) > 0 {
|
||||||
if verbose {
|
if verbose {
|
||||||
fmt.Println("Error(s) while extracting the symlink's file:", path+"/"+f.Name)
|
fmt.Println("Error(s) while extracting the symlink's file:", path+"/"+f.name)
|
||||||
fmt.Println(extracSymErrs)
|
fmt.Println(extracSymErrs)
|
||||||
}
|
}
|
||||||
errs = append(errs, extracSymErrs...)
|
errs = append(errs, extracSymErrs...)
|
||||||
@@ -392,22 +455,22 @@ func (f *File) ExtractWithOptions(path string, dereferenceSymlink, unbreakSymlin
|
|||||||
extracSymErrs := fil.ExtractWithOptions(strings.Join(paths[:len(paths)-1], "/"), dereferenceSymlink, unbreakSymlink, folderPerm, verbose)
|
extracSymErrs := fil.ExtractWithOptions(strings.Join(paths[:len(paths)-1], "/"), dereferenceSymlink, unbreakSymlink, folderPerm, verbose)
|
||||||
if len(extracSymErrs) > 0 {
|
if len(extracSymErrs) > 0 {
|
||||||
if verbose {
|
if verbose {
|
||||||
fmt.Println("Error(s) while extracting the symlink's file:", path+"/"+f.Name)
|
fmt.Println("Error(s) while extracting the symlink's file:", path+"/"+f.name)
|
||||||
fmt.Println(extracSymErrs)
|
fmt.Println(extracSymErrs)
|
||||||
}
|
}
|
||||||
errs = append(errs, extracSymErrs...)
|
errs = append(errs, extracSymErrs...)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if verbose {
|
if verbose {
|
||||||
fmt.Println("Symlink path(", symPath, ") is outside the archive:"+path+"/"+f.Name)
|
fmt.Println("Symlink path(", symPath, ") is outside the archive:"+path+"/"+f.name)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
err = os.Symlink(f.SymlinkPath(), path+"/"+f.Name)
|
err = os.Symlink(f.SymlinkPath(), path+"/"+f.name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if verbose {
|
if verbose {
|
||||||
fmt.Println("Error while making symlink:", path+"/"+f.Name)
|
fmt.Println("Error while making symlink:", path+"/"+f.name)
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
errs = append(errs, err)
|
errs = append(errs, err)
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"math"
|
"math"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/CalebQ42/squashfs/internal/compression"
|
"github.com/CalebQ42/squashfs/internal/compression"
|
||||||
"github.com/CalebQ42/squashfs/internal/inode"
|
"github.com/CalebQ42/squashfs/internal/inode"
|
||||||
@@ -148,6 +149,11 @@ func NewSquashfsReader(r io.ReaderAt) (*Reader, error) {
|
|||||||
return &rdr, nil
|
return &rdr, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//ModTime is the last time the file was modified/created.
|
||||||
|
func (r *Reader) ModTime() time.Time {
|
||||||
|
return time.Unix(int64(r.super.CreationTime), 0)
|
||||||
|
}
|
||||||
|
|
||||||
//ExtractTo tries to extract ALL files to the given path. This is the same as getting the root folder and extracting that.
|
//ExtractTo tries to extract ALL files to the given path. This is the same as getting the root folder and extracting that.
|
||||||
func (r *Reader) ExtractTo(path string) []error {
|
func (r *Reader) ExtractTo(path string) []error {
|
||||||
root, err := r.GetRootFolder()
|
root, err := r.GetRootFolder()
|
||||||
|
|||||||
+19
-9
@@ -1,6 +1,7 @@
|
|||||||
package squashfs
|
package squashfs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
@@ -12,10 +13,9 @@ import (
|
|||||||
const (
|
const (
|
||||||
downloadURL = "https://github.com/Swordfish90/cool-retro-term/releases/download/1.1.1/Cool-Retro-Term-1.1.1-x86_64.AppImage"
|
downloadURL = "https://github.com/Swordfish90/cool-retro-term/releases/download/1.1.1/Cool-Retro-Term-1.1.1-x86_64.AppImage"
|
||||||
appImageName = "Cool-Retro-Term.AppImage"
|
appImageName = "Cool-Retro-Term.AppImage"
|
||||||
squashfsName = "airootfs.sfs" //testing with a ArchLinux root fs from the live img
|
squashfsName = "balenaEtcher-1.5.113-x64.AppImage.sfs" //testing with a ArchLinux root fs from the live img
|
||||||
)
|
)
|
||||||
|
|
||||||
//Right now, don't use. Arch linux sfs uses XZ compression and when tested, most files just completely fail to extract.
|
|
||||||
func TestSquashfs(t *testing.T) {
|
func TestSquashfs(t *testing.T) {
|
||||||
wd, err := os.Getwd()
|
wd, err := os.Getwd()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -29,10 +29,20 @@ func TestSquashfs(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
os.RemoveAll(wd + "/testing/" + squashfsName + ".d")
|
fmt.Println("stuff", rdr.super.CompressionType)
|
||||||
root, _ := rdr.GetRootFolder()
|
fil := rdr.GetFileAtPath("*.desktop")
|
||||||
errs := root.ExtractWithOptions(wd+"/testing/"+squashfsName+".d", false, false, os.ModePerm, true)
|
if fil == nil {
|
||||||
t.Fatal(errs)
|
t.Fatal("Can't find desktop fil")
|
||||||
|
}
|
||||||
|
errs := fil.ExtractTo(wd + "/testing")
|
||||||
|
if len(errs) > 0 {
|
||||||
|
t.Fatal(errs)
|
||||||
|
}
|
||||||
|
errs = rdr.ExtractTo(wd + "/testing/" + squashfsName + ".d")
|
||||||
|
if len(errs) > 0 {
|
||||||
|
t.Fatal(errs)
|
||||||
|
}
|
||||||
|
t.Fatal("No Problems")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAppImage(t *testing.T) {
|
func TestAppImage(t *testing.T) {
|
||||||
@@ -70,15 +80,15 @@ func TestAppImage(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func downloadTestAppImage(t *testing.T, dir string) {
|
func downloadTestAppImage(t *testing.T, dir string) {
|
||||||
//seems to time out on slow connections. Might fix that at some point... or not
|
//seems to time out on slow connections. Might fix that at some point... or not. It's just a test...
|
||||||
os.Mkdir(dir, 0777)
|
os.Mkdir(dir, os.ModePerm)
|
||||||
appImage, err := os.Create(dir + "/" + appImageName)
|
appImage, err := os.Create(dir + "/" + appImageName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
defer appImage.Close()
|
defer appImage.Close()
|
||||||
check := http.Client{
|
check := http.Client{
|
||||||
CheckRedirect: func(r *http.Request, via []*http.Request) error {
|
CheckRedirect: func(r *http.Request, _ []*http.Request) error {
|
||||||
r.URL.Opaque = r.URL.Path
|
r.URL.Opaque = r.URL.Path
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user