Skip to content

Commit

Permalink
Fixes #195 and #125 (#197)
Browse files Browse the repository at this point in the history
* Added SquashfsReader()

* Fixed #195 and #125

* Added more comments to SquashfsReader
  • Loading branch information
CalebQ42 authored Apr 17, 2022
1 parent dbb75b3 commit 9231e4d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/appimaged/desktop.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func writeDesktopFile(ai AppImage) {
time.Sleep(1 * time.Second)
add := ""
args, err := ai.Args()
if err == nil {
if err == nil && len(args) > 0 {
add = " " + strings.Join(args, " ")
}
cfg.Section("Desktop Entry").Key("Exec").SetValue(arg0abs + " wrap \"" + ai.Path + "\"" + add) // Resolve to a full path
Expand Down
18 changes: 9 additions & 9 deletions src/appimaged/prerequisites.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,16 +207,16 @@ func stopSystemdService(servicename string) {
*/

func exitIfBinfmtExists(path string) {
cmd := exec.Command("/bin/sh", "-c", "echo -1 | sudo tee "+path)
cmd.Run()
// if err != nil {
// helpers.PrintError("prerequisites: exitIfBinfmtExists", err)
// If these binfmts are not there, that is actually not an error and should not be reported as that
// }
if _, err := os.Stat(path); err == nil {
log.Println("ERROR:", path, "exists. Please remove it by running")
println("echo -1 | sudo tee", path)
os.Exit(1)
//If path exists, try to get sudo and remove it.
cmd := exec.Command("/bin/sh", "-c", "echo -1 | sudo tee "+path)
cmd.Run()
if _, err := os.Stat(path); err == nil {
//It still exists, so we panic and quit.
log.Println("ERROR:", path, "exists. Please remove it by running")
println("echo -1 | sudo tee", path)
os.Exit(1)
}
}
}

Expand Down
22 changes: 20 additions & 2 deletions src/goappimage/appimage.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bufio"
"bytes"
"errors"
"fmt"
"io"
"os"
"os/exec"
Expand All @@ -13,6 +12,7 @@ import (
"strings"
"time"

"github.com/CalebQ42/squashfs"
"github.com/probonopd/go-appimage/internal/helpers"
"gopkg.in/ini.v1"
)
Expand Down Expand Up @@ -149,6 +149,25 @@ func (ai AppImage) determineImageType() int {
return -1
}

//SquashfsReader allows direct access to an AppImage's squashfs.
//Only works on type 2 AppImages
func (ai AppImage) SquashfsReader() (*squashfs.Reader, error) {
if ai.imageType != 2 {
return nil, errors.New("not a type 2 appimage")
}
aiFil, err := os.Open(ai.Path)
if err != nil {
return nil, err
}
stat, _ := aiFil.Stat()
aiRdr := io.NewSectionReader(aiFil, ai.offset, stat.Size()-ai.offset)
squashRdr, err := squashfs.NewSquashfsReader(aiRdr)
if err != nil {
return nil, err
}
return squashRdr, nil
}

//Type is the type of the AppImage. Should be either 1 or 2.
func (ai AppImage) Type() int {
return ai.imageType
Expand Down Expand Up @@ -216,7 +235,6 @@ func (ai AppImage) Args() ([]string, error) {
return nil, errors.New("desktop file wasn't parsed")
}
var exec = ai.Desktop.Section("Desktop Entry").Key("Exec").Value()
fmt.Println("exec:", exec)
if exec == "" {
return nil, errors.New("exec key not present")
}
Expand Down

0 comments on commit 9231e4d

Please sign in to comment.