Removed close function from squashfs.File

This seems to cause issues in ver specific circumstances and ultimately, isn't needed.
This commit is contained in:
Caleb Gardner
2021-01-06 12:56:09 -06:00
parent 97b12090c6
commit 35d22b4bd0
5 changed files with 9 additions and 39 deletions
-6
View File
@@ -145,12 +145,6 @@ func (d *dataReader) readCurBlock() error {
return err return err
} }
//Close frees up the curData from memory
func (d *dataReader) Close() error {
d.curData = nil
return nil
}
func (d *dataReader) Read(p []byte) (int, error) { func (d *dataReader) Read(p []byte) (int, error) {
if d.curData == nil { if d.curData == nil {
err := d.readCurBlock() err := d.readCurBlock()
-17
View File
@@ -356,7 +356,6 @@ func (f *File) ExtractWithOptions(path string, dereferenceSymlink, unbreakSymlin
return return
} }
finishChan := make(chan []error) finishChan := make(chan []error)
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 == "" {
@@ -408,7 +407,6 @@ func (f *File) ExtractWithOptions(path string, dereferenceSymlink, unbreakSymlin
errs = append(errs, err) errs = append(errs, err)
return return
} }
f.Close()
fil.Chown(int(f.r.idTable[f.in.Header.UID]), int(f.r.idTable[f.in.Header.GID])) fil.Chown(int(f.r.idTable[f.in.Header.UID]), int(f.r.idTable[f.in.Header.GID]))
//don't mention anything when it fails. Because it fails often. Probably has something to do about uid & gid 0 //don't mention anything when it fails. Because it fails often. Probably has something to do about uid & gid 0
// if err != nil { // if err != nil {
@@ -480,21 +478,6 @@ func (f *File) ExtractWithOptions(path string, dereferenceSymlink, unbreakSymlin
return return
} }
//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.
func (f *File) Close() error {
if f.IsDir() {
return errNotFile
}
if f.Reader != nil {
if closer, is := f.Reader.(io.Closer); is {
closer.Close()
}
f.Reader = nil
}
return nil
}
//Read from the file. Doesn't do anything fancy, just pases it to the underlying io.Reader. If a directory, return io.EOF. //Read from the file. Doesn't do anything fancy, just pases it to the underlying io.Reader. If a directory, return io.EOF.
func (f *File) Read(p []byte) (int, error) { func (f *File) Read(p []byte) (int, error) {
if f.IsDir() { if f.IsDir() {
-9
View File
@@ -57,15 +57,6 @@ func (r *Reader) newFileReader(in *inode.Inode) (*fileReader, error) {
return &rdr, nil return &rdr, nil
} }
//Close runs Close on the data reader and frees the fragmentdata
func (f *fileReader) Close() error {
if f.data != nil {
f.data.Close()
}
f.fragmentData = nil
return nil
}
func (f *fileReader) Read(p []byte) (int, error) { func (f *fileReader) Read(p []byte) (int, error) {
if f.fragOnly { if f.fragOnly {
n, err := bytes.NewBuffer(f.fragmentData[f.read:]).Read(p) n, err := bytes.NewBuffer(f.fragmentData[f.read:]).Read(p)
+4 -3
View File
@@ -11,8 +11,8 @@ 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/srevinsaju/Firefox-Appimage/releases/download/firefox-v84.0.r20201221152838/firefox-84.0.r20201221152838-x86_64.AppImage"
appImageName = "Cool-Retro-Term.AppImage" appImageName = "firefox-84.0.r20201221152838-x86_64.AppImage"
squashfsName = "balenaEtcher-1.5.113-x64.AppImage.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
) )
@@ -68,7 +68,8 @@ func TestAppImage(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
errs := rdr.ExtractTo(wd + "/testing/cool-retro") os.RemoveAll(wd + "testing/firefox")
errs := rdr.ExtractTo(wd + "/testing/firefox")
if len(errs) > 0 { if len(errs) > 0 {
t.Fatal(errs) t.Fatal(errs)
} }
+5 -4
View File
@@ -14,12 +14,12 @@ import (
//If AllowErrors is true, when errors are encountered, it just prints to the log instead of failing. //If AllowErrors is true, when errors are encountered, it just prints to the log instead of failing.
type Writer struct { type Writer struct {
files map[string][]*File files map[string][]*File
directories []string symlinkTable map[string]string //[oldpath]newpath
symlinkTable map[string]string //symlinkTable holds info about symlink'd to files that had to be moved from their original position. [originalpath]newpath
symTableTemp map[string]string symTableTemp map[string]string
directories []string
compression int
ResolveSymlinks bool ResolveSymlinks bool
AllowErrors bool AllowErrors bool
compression int
} }
//NewWriter creates a new squashfs.Writer with the default settings (gzip compression, autoresolving symlinks, and allowErrors) //NewWriter creates a new squashfs.Writer with the default settings (gzip compression, autoresolving symlinks, and allowErrors)
@@ -51,8 +51,8 @@ func NewWriterWithOptions(resolveSymlinks, allowErrors bool, compressionType int
} }
type fileError struct { type fileError struct {
files []*File
err error err error
files []*File
} }
//convertFile converts the given os.File to a squashfs.File. Returns the errors and converted file to the channels. //convertFile converts the given os.File to a squashfs.File. Returns the errors and converted file to the channels.
@@ -163,6 +163,7 @@ func (w *Writer) AddFilesToPath(squashfsPath string, files ...*os.File) error {
for _, fil := range files { for _, fil := range files {
go w.convertFile(squashfsPath, fil, false, fileErrChan) go w.convertFile(squashfsPath, fil, false, fileErrChan)
} }
return errors.New("Not yet ready")
} }
//AddFiles adds all files given to the root directory //AddFiles adds all files given to the root directory