Starting work on ExtractTo from File
When using ExtractTo, will automatically set the correct permissions Will also be able to extract folders
This commit is contained in:
@@ -3,6 +3,7 @@ package squashfs
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/CalebQ42/squashfs/internal/directory"
|
"github.com/CalebQ42/squashfs/internal/directory"
|
||||||
@@ -173,6 +174,20 @@ func (f *File) GetSymlinkFile() *File {
|
|||||||
return f.r.GetFileAtPath(f.SymlinkPath())
|
return f.r.GetFileAtPath(f.SymlinkPath())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Permission returns the os.FileMode of the File. Currently only has the permission bits (the last 9) populated.
|
||||||
|
func (f *File) Permission() os.FileMode {
|
||||||
|
//TODO: possibly populate more os.FileMode bits
|
||||||
|
return os.FileMode(f.in.Header.Permissions)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *File) ExtractTo(path string) error {
|
||||||
|
if f.IsDir() {
|
||||||
|
//TODO
|
||||||
|
} else if f.IsSymlink() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//Close frees up the memory held up by the underlying reader. Should NOT be called when writing.
|
//Close frees up the memory held up by the underlying reader. Should NOT be called when writing.
|
||||||
//When reading, Close is safe to use, but any subsequent Read calls resets to the beginning of the file.
|
//When reading, Close is safe to use, but any subsequent Read calls resets to the beginning of the file.
|
||||||
func (f *File) Close() error {
|
func (f *File) Close() error {
|
||||||
|
|||||||
@@ -71,3 +71,40 @@ func downloadTestAppImage(t *testing.T, dir string) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCreateSquashFromAppImage(t *testing.T) {
|
||||||
|
wd, err := os.Getwd()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
err = os.Mkdir(wd+"/testing", 0777)
|
||||||
|
if err != nil && !os.IsExist(err) {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
_, err = os.Open(wd + "/testing/" + appImageName)
|
||||||
|
if os.IsNotExist(err) {
|
||||||
|
downloadTestAppImage(t, wd+"/testing")
|
||||||
|
_, err = os.Open(wd + "/testing/" + appImageName)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
} else if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
ai := goappimage.NewAppImage(wd + "/testing/" + appImageName)
|
||||||
|
aiFil, err := os.Open(wd + "/testing/" + appImageName)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer aiFil.Close()
|
||||||
|
aiFil.Seek(ai.Offset, 0)
|
||||||
|
os.Remove(wd + "/testing/" + appImageName + ".squashfs")
|
||||||
|
aiSquash, err := os.Create(wd + "/testing/" + appImageName + ".squashfs")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
_, err = io.Copy(aiSquash, aiFil)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user