Skip to content

Commit

Permalink
Fixes #2
Browse files Browse the repository at this point in the history
After some debugging in aisap-zig, I've discovered that the "can only read files"
error was due to trying to read from a symlink without first resolving
and has now been fixed
  • Loading branch information
mgord9518 committed Aug 13, 2023
1 parent 94d807b commit 463e8d4
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 8 deletions.
13 changes: 11 additions & 2 deletions appimage.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type AppImage struct {

// Current version of aisap
const (
Version = "0.9.3-alpha"
Version = "0.9.4-alpha"
)

// Create a new AppImage object from a path
Expand Down Expand Up @@ -352,9 +352,18 @@ func (ai *AppImage) getEntry() (io.Reader, error) {
return nil, NoDesktopFile
}

return ai.reader.Open(fp[0])
entry, err := ai.reader.Open(fp[0])

r := entry.(*squashfs.File)

if r.IsSymlink() {
r = r .GetSymlinkFile()
}

return r, err
}


return r, err
}

Expand Down
2 changes: 1 addition & 1 deletion zig/build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.{
.name = "aisap",
.version = "0.9.3",
.version = "0.9.4",
}
27 changes: 23 additions & 4 deletions zig/lib/AppImage.zig
Original file line number Diff line number Diff line change
Expand Up @@ -396,10 +396,19 @@ pub const AppImage = struct {
}
};

// TODO: Use this to replace the Go implemenation
// Once the Zig version is up to par, the Zig -> C bindings will call to
// the parent pointer's methods. This cannot currently be done as Go
// doesn't allow Go pointers to be passed to C
pub fn open(ai: *AppImage, path: []const u8) !SquashFs.Inode {
var root_inode = ai.image.getRootInode();
var it = try root_inode.walk(ai.allocator);
while (try it.next()) |entry| {
if (!std.mem.eql(u8, entry.path, path)) continue;

return entry.inode();
}

// TODO: error
unreachable;
}

pub fn init(allocator: std.mem.Allocator, path: []const u8) !AppImage {
// Create the AppImage type for the C binding
var ai = AppImage{
Expand All @@ -424,6 +433,7 @@ pub const AppImage = struct {

// Skip any files not ending in `.desktop`
const extension = split_it.first();

if (!std.mem.eql(u8, extension, "desktop")) continue;

// Also skip any files without an extension
Expand All @@ -432,8 +442,17 @@ pub const AppImage = struct {
// Read the first 4KiB of the desktop entry, it really should be a
// lot smaller than this, but just in case.
var entry_buf = try allocator.alloc(u8, 1024 * 4);

var inode = entry.inode();

// If the entry is a symlink, follow it before attempting to read
if (inode.kind == .sym_link) {
var path_buf: [std.os.PATH_MAX]u8 = undefined;
const real_inode_path = try inode.readLink(&path_buf);

inode = try ai.open(real_inode_path);
}

// When reading, save the last byte for null terminator
const read_bytes = try inode.read(entry_buf[0 .. entry_buf.len - 2]);

Expand Down
2 changes: 1 addition & 1 deletion zig/squashfuse-zig

0 comments on commit 463e8d4

Please sign in to comment.