Skip to content

Commit

Permalink
Fix error when no existing profile
Browse files Browse the repository at this point in the history
  • Loading branch information
mgord9518 committed Jul 2, 2024
1 parent 2ac5894 commit 73af6e8
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 17 deletions.
9 changes: 3 additions & 6 deletions cmd/aisap/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,6 @@ func main() {
return
}

perms, err := ai.Permissions()
if err != nil {
cli.Fatal(invalidPerms, err)
return
}

if *extractIcon != "" {
if *verbose {
Expand Down Expand Up @@ -126,6 +121,8 @@ func main() {
return
}

perms, err := ai.Permissions()

if *profile != "" {
f, err := os.Open(*profile)
if err != nil {
Expand Down Expand Up @@ -288,7 +285,7 @@ func main() {

err = ai.Sandbox(perms, flag.Args()[1:])
if err != nil {
fmt.Fprintln(os.Stdout, "sandbox error:", err)
cli.Fatal("sandbox error:", err);
return
}
}
Expand Down
14 changes: 5 additions & 9 deletions include/aisap.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ typedef struct aisap_appimage {

// For Zig implemenation, points to Zig AppImage
void* _zig_parent;
} aisap_appimage ;
} aisap_appimage;

typedef enum aisap_socket {
AISAP_SOCKET_ALSA,
AISAP_SOCKET_AUDIO,
AISAP_SOCKET_CGROUP,
AISAP_SOCKET_DBUS,
AISAP_SOCKET_IPC,
Expand Down Expand Up @@ -70,15 +69,12 @@ typedef uint8_t aisap_error;
extern "C" {
#endif

// Zig-implemented C functions
// `aisap_appimage_new` initializes both the Zig and Go AppImage structs, so
// until I can get the rest of the functions ported over you'll still be able
// to call all of them
// Inits a new `aisap_appimage`
// `path` is a null-terminated string
extern aisap_appimage aisap_appimage_new(const char* path, aisap_error* err);

// Like `aisap_appimage_new`, but takes a path length instead of a
// null-terminated path. For this function, path does NOT have to be null-
// terminated
// Like `aisap_appimage_new`, but takes a path length instead of requiring a
// null-terminated path
extern aisap_appimage aisap_appimage_newn(const char* path, size_t path_len, aisap_error* err);

extern void aisap_appimage_destroy(aisap_appimage* ai);
Expand Down
4 changes: 2 additions & 2 deletions zig/lib/appimage.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1064,14 +1064,14 @@ pub const AppImage = struct {
}

/// Returns a `char**` for use in C
pub fn wrapArgsZ(ai: *AppImage, allocator: std.mem.Allocator) ![*:null]?[*:0]const u8 {
pub fn wrapArgsZ(ai: *AppImage, allocator: std.mem.Allocator, perms: Permissions) ![*:null]?[*:0]const u8 {
var list = std.ArrayList(?[*:0]const u8).init(allocator);

var arena = std.heap.ArenaAllocator.init(allocator);
const arena_allocator = arena.allocator();
defer arena.deinit();

const args_slice = try ai.wrapArgs(arena_allocator);
const args_slice = try ai.wrapArgs(arena_allocator, perms);

for (args_slice) |arg| {
try list.append(try allocator.dupeZ(u8, arg));
Expand Down
1 change: 1 addition & 0 deletions zig/lib/c_api.zig
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ export fn aisap_appimage_md5(
// Returned memory must be freed
export fn aisap_appimage_wrapargs(
c_ai: *c.aisap_appimage,
//perms: *c.aisap_permissions,
err: *CAppImageError,
) [*:null]?[*:0]const u8 {
const ai = getParent(c_ai);
Expand Down

0 comments on commit 73af6e8

Please sign in to comment.