From 35d22b4bd04a499d8766bfca7f74731cabd4805c Mon Sep 17 00:00:00 2001 From: Caleb Gardner Date: Wed, 6 Jan 2021 12:56:09 -0600 Subject: [PATCH] Removed close function from squashfs.File This seems to cause issues in ver specific circumstances and ultimately, isn't needed. --- datareader.go | 6 ------ file.go | 17 ----------------- filereader.go | 9 --------- squash_test.go | 7 ++++--- writer.go | 9 +++++---- 5 files changed, 9 insertions(+), 39 deletions(-) diff --git a/datareader.go b/datareader.go index 131c620..7475501 100644 --- a/datareader.go +++ b/datareader.go @@ -145,12 +145,6 @@ func (d *dataReader) readCurBlock() error { 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) { if d.curData == nil { err := d.readCurBlock() diff --git a/file.go b/file.go index 112c8aa..56aaf0f 100644 --- a/file.go +++ b/file.go @@ -356,7 +356,6 @@ func (f *File) ExtractWithOptions(path string, dereferenceSymlink, unbreakSymlin return } finishChan := make(chan []error) - defer close(finishChan) for _, child := range children { go func(child *File) { if f.name == "" { @@ -408,7 +407,6 @@ func (f *File) ExtractWithOptions(path string, dereferenceSymlink, unbreakSymlin errs = append(errs, err) return } - f.Close() 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 // if err != nil { @@ -480,21 +478,6 @@ func (f *File) ExtractWithOptions(path string, dereferenceSymlink, unbreakSymlin 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. func (f *File) Read(p []byte) (int, error) { if f.IsDir() { diff --git a/filereader.go b/filereader.go index b6111bd..22eb0a2 100644 --- a/filereader.go +++ b/filereader.go @@ -57,15 +57,6 @@ func (r *Reader) newFileReader(in *inode.Inode) (*fileReader, error) { 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) { if f.fragOnly { n, err := bytes.NewBuffer(f.fragmentData[f.read:]).Read(p) diff --git a/squash_test.go b/squash_test.go index 2b44be7..34f8339 100644 --- a/squash_test.go +++ b/squash_test.go @@ -11,8 +11,8 @@ import ( ) const ( - 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" + downloadURL = "https://github.com/srevinsaju/Firefox-Appimage/releases/download/firefox-v84.0.r20201221152838/firefox-84.0.r20201221152838-x86_64.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 ) @@ -68,7 +68,8 @@ func TestAppImage(t *testing.T) { if err != nil { 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 { t.Fatal(errs) } diff --git a/writer.go b/writer.go index 16a7ea6..b8ed0ba 100644 --- a/writer.go +++ b/writer.go @@ -14,12 +14,12 @@ import ( //If AllowErrors is true, when errors are encountered, it just prints to the log instead of failing. type Writer struct { files map[string][]*File - directories []string - symlinkTable map[string]string //symlinkTable holds info about symlink'd to files that had to be moved from their original position. [originalpath]newpath + symlinkTable map[string]string //[oldpath]newpath symTableTemp map[string]string + directories []string + compression int ResolveSymlinks bool AllowErrors bool - compression int } //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 { - files []*File err error + files []*File } //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 { go w.convertFile(squashfsPath, fil, false, fileErrChan) } + return errors.New("Not yet ready") } //AddFiles adds all files given to the root directory