Skip to content

Commit 0d520df

Browse files
xordspar0probonopd
andauthored
Enable portable home/config dirs for extract-and-run (AppImage#5)
* Enable portable home/config dirs for extract-and-run * Make the build work with Alpine 3.17 --------- Co-authored-by: probonopd <[email protected]>
1 parent ef45c4f commit 0d520df

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

src/runtime/runtime.c

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,6 +1434,27 @@ char* appimage_hexlify(const char* bytes, const size_t numBytes) {
14341434
return hexlified;
14351435
}
14361436

1437+
void set_portable_home_and_config(char* basepath) {
1438+
char portable_home_dir[PATH_MAX];
1439+
char portable_config_dir[PATH_MAX];
1440+
1441+
/* If there is a directory with the same name as the AppImage plus ".home", then export $HOME */
1442+
strcpy(portable_home_dir, basepath);
1443+
strcat(portable_home_dir, ".home");
1444+
if (is_writable_directory(portable_home_dir)) {
1445+
fprintf(stderr, "Setting $HOME to %s\n", portable_home_dir);
1446+
setenv("HOME", portable_home_dir, 1);
1447+
}
1448+
1449+
/* If there is a directory with the same name as the AppImage plus ".config", then export $XDG_CONFIG_HOME */
1450+
strcpy(portable_config_dir, basepath);
1451+
strcat(portable_config_dir, ".config");
1452+
if (is_writable_directory(portable_config_dir)) {
1453+
fprintf(stderr, "Setting $XDG_CONFIG_HOME to %s\n", portable_config_dir);
1454+
setenv("XDG_CONFIG_HOME", portable_config_dir, 1);
1455+
}
1456+
}
1457+
14371458
int main(int argc, char* argv[]) {
14381459
const bool verbose = (getenv("VERBOSE") != NULL);
14391460
if (verbose) {
@@ -1614,6 +1635,8 @@ int main(int argc, char* argv[]) {
16141635
setenv("ARGV0", argv0_path, 1);
16151636
setenv("APPDIR", prefix, 1);
16161637

1638+
set_portable_home_and_config(fullpath);
1639+
16171640
execv(apprun_path, new_argv);
16181641

16191642
int error = errno;
@@ -1803,24 +1826,7 @@ int main(int argc, char* argv[]) {
18031826
setenv("ARGV0", argv0_path, 1);
18041827
setenv("APPDIR", mount_dir, 1);
18051828

1806-
char portable_home_dir[PATH_MAX];
1807-
char portable_config_dir[PATH_MAX];
1808-
1809-
/* If there is a directory with the same name as the AppImage plus ".home", then export $HOME */
1810-
strcpy(portable_home_dir, fullpath);
1811-
strcat(portable_home_dir, ".home");
1812-
if (is_writable_directory(portable_home_dir)) {
1813-
fprintf(stderr, "Setting $HOME to %s\n", portable_home_dir);
1814-
setenv("HOME", portable_home_dir, 1);
1815-
}
1816-
1817-
/* If there is a directory with the same name as the AppImage plus ".config", then export $XDG_CONFIG_HOME */
1818-
strcpy(portable_config_dir, fullpath);
1819-
strcat(portable_config_dir, ".config");
1820-
if (is_writable_directory(portable_config_dir)) {
1821-
fprintf(stderr, "Setting $XDG_CONFIG_HOME to %s\n", portable_config_dir);
1822-
setenv("XDG_CONFIG_HOME", portable_config_dir, 1);
1823-
}
1829+
set_portable_home_and_config(fullpath);
18241830

18251831
/* Original working directory */
18261832
char cwd[1024];

0 commit comments

Comments
 (0)