Skip to content

Fix TARGET_APPIMAGE issues #128

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 32 additions & 41 deletions src/runtime/runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -716,20 +716,12 @@ void print_help(const char* appimage_path) {
"for information on how to obtain and build the source code\n", appimage_path);
}

void portable_option(const char* arg, const char* appimage_path, const char* name) {
void portable_option(const char* arg, const char* fullpath, const char* name) {
char option[32];
sprintf(option, "appimage-portable-%s", name);

if (arg && strcmp(arg, option) == 0) {
char portable_dir[PATH_MAX];
char fullpath[PATH_MAX];

ssize_t length = readlink(appimage_path, fullpath, sizeof(fullpath));
if (length < 0) {
fprintf(stderr, "Error getting realpath for %s\n", appimage_path);
exit(EXIT_FAILURE);
}
fullpath[length] = '\0';

sprintf(portable_dir, "%s.%s", fullpath, name);
if (!mkdir(portable_dir, S_IRWXU))
Expand Down Expand Up @@ -1488,6 +1480,35 @@ int main(int argc, char* argv[]) {
strcpy(argv0_path, getenv("TARGET_APPIMAGE"));
}

// figure out file type
struct stat stat_buf;

if (lstat(appimage_path, &stat_buf) < 0) {
fprintf(stderr, "Error, cannot stat %s\n", appimage_path);
exit(EXIT_EXECERROR);
}

// calculate full path of AppImage
char fullpath[PATH_MAX];

if (S_ISLNK(stat_buf.st_mode)) {
// If we are operating on a link
ssize_t len = readlink(appimage_path, fullpath, sizeof(fullpath));
if (len < 0) {
fprintf(stderr, "Error getting realpath for %s\n", appimage_path);
exit(EXIT_EXECERROR);
}
fullpath[len] = '\0';
} else {
char* abspath = realpath(appimage_path, NULL);
if (abspath == NULL) {
fprintf(stderr, "Error getting realpath for %s\n", appimage_path);
exit(EXIT_EXECERROR);
}
strcpy(fullpath, abspath);
free(abspath);
}

// temporary directories are required in a few places
// therefore we implement the detection of the temp base dir at the top of the code to avoid redundancy
char temp_base[PATH_MAX] = P_tmpdir;
Expand All @@ -1510,15 +1531,6 @@ int main(int argc, char* argv[]) {

/* Print the help and then exit */
if (arg && strcmp(arg, "appimage-help") == 0) {
char fullpath[PATH_MAX];

ssize_t length = readlink(appimage_path, fullpath, sizeof(fullpath));
if (length < 0) {
fprintf(stderr, "Error getting realpath for %s\n", appimage_path);
exit(EXIT_EXECERROR);
}
fullpath[length] = '\0';

print_help(fullpath);
exit(0);
}
Expand Down Expand Up @@ -1557,27 +1569,6 @@ int main(int argc, char* argv[]) {
exit(0);
}

// calculate full path of AppImage
char fullpath[PATH_MAX];

if (getenv("TARGET_APPIMAGE") == NULL) {
// If we are operating on this file itself
ssize_t len = readlink(appimage_path, fullpath, sizeof(fullpath));
if (len < 0) {
perror("Failed to obtain absolute path");
exit(EXIT_EXECERROR);
}
fullpath[len] = '\0';
} else {
char* abspath = realpath(appimage_path, NULL);
if (abspath == NULL) {
perror("Failed to obtain absolute path");
exit(EXIT_EXECERROR);
}
strcpy(fullpath, abspath);
free(abspath);
}

if (getenv("APPIMAGE_EXTRACT_AND_RUN") != NULL || (arg && strcmp(arg, "appimage-extract-and-run") == 0)) {
char* hexlified_digest = NULL;

Expand Down Expand Up @@ -1695,8 +1686,8 @@ int main(int argc, char* argv[]) {
exit(0);
}

portable_option(arg, appimage_path, "home");
portable_option(arg, appimage_path, "config");
portable_option(arg, fullpath, "home");
portable_option(arg, fullpath, "config");

// If there is an argument starting with appimage- (but not appimage-mount which is handled further down)
// then stop here and print an error message
Expand Down