1
0
mirror of https://github.com/gryf/wmaker.git synced 2026-02-14 12:55:47 +01:00

WINGs: Improve search path logic in WMPathForResourceOfType

The man page says environment variables are used, and if they don't exist
it falls back to defaults, yet this was not true in WINGS.

This changes implements the checks for the default paths used when the env
variables are not defined; these default paths have been fixed (+lib) to
match the GNUstep layout ('fhs'), expect for the very last path which keeps
the legacy layout.

For the user Apps folder, rely on wusergnusteppath() (~/GNUstep) to build
the path.

The previous code was only partially functional as the hard-coded paths
did not exist in any of GNUstep standard file system layout and the
GNUSTEP_*_ROOT environment variables were not provided by GNUstep for a
while. This means it would never work no matter how environment variables
were set when using layouts: 'debian', 'fhs', 'next', 'Apple', 'mac',
'fhs-system', or 'standalone'.
This commit is contained in:
John D Pell
2021-08-08 09:36:10 +02:00
committed by Carlos R. Mafra
parent c060477d57
commit bfab769065
2 changed files with 38 additions and 25 deletions

View File

@@ -131,7 +131,9 @@ error:
char *WMPathForResourceOfType(const char *resource, const char *ext)
{
const char *gslocapps, *gssysapps, *gsuserapps;
char *path, *appdir;
char buffer[PATH_MAX];
size_t slen;
path = appdir = NULL;
@@ -141,11 +143,11 @@ char *WMPathForResourceOfType(const char *resource, const char *ext)
* - resourcePath/ext
* - dirname(argv[0])/ext
* - WMAKER_USER_ROOT/Applications/ApplicationName.app/ext
* - ~/GNUstep/Applications/ApplicationName.app/ext
* - GNUSTEP_LOCAL_ROOT/Applications/ApplicationName.app/ext
* - /usr/local/GNUstep/Applications/ApplicationName.app/ext
* - GNUSTEP_SYSTEM_ROOT/Applications/ApplicationName.app/ext
* - /usr/GNUstep/Applications/ApplicationName.app/ext
* - GNUSTEP_USER_APPS/ApplicationName.app/ext
* - GNUSTEP_LOCAL_APPS/ApplicationName.app/ext
* - /usr/local/lib/GNUstep/Applications/ApplicationName.app/ext
* - GNUSTEP_SYSTEM_APPS/ApplicationName.app/ext
* - /usr/lib/GNUstep/Applications/ApplicationName.app/ext
*/
if (WMApplication.resourcePath) {
@@ -170,32 +172,40 @@ char *WMPathForResourceOfType(const char *resource, const char *ext)
}
}
slen = strlen(WMApplication.applicationName) + sizeof("Applications/.app");
snprintf(buffer, sizeof(buffer), "Applications/%s.app", WMApplication.applicationName);
path = checkFile(GETENV("WMAKER_USER_ROOT"), buffer, ext, resource);
if (path)
goto out;
slen = strlen(WMApplication.applicationName) + sizeof("/.app");
appdir = wmalloc(slen);
if (snprintf(appdir, slen, "Applications/%s.app", WMApplication.applicationName) >= slen)
if (snprintf(appdir, slen, "/%s.app", WMApplication.applicationName) >= slen)
goto out;
path = checkFile(getenv("WMAKER_USER_ROOT"), appdir, ext, resource);
gsuserapps = GETENV("GNUSTEP_USER_APPS");
if (!gsuserapps) {
snprintf(buffer, sizeof(buffer), "%s/Applications", wusergnusteppath());
gsuserapps = buffer;
}
path = checkFile(gsuserapps, appdir, ext, resource);
if (path)
goto out;
path = checkFile(wusergnusteppath(), appdir, ext, resource);
gslocapps = GETENV("GNUSTEP_LOCAL_APPS");
if (!gslocapps)
gslocapps = "/usr/local/lib/GNUstep/Applications";
path = checkFile(gslocapps, appdir, ext, resource);
if (path)
goto out;
path = checkFile(getenv("GNUSTEP_LOCAL_ROOT"), appdir, ext, resource);
gssysapps = GETENV("GNUSTEP_SYSTEM_APPS");
if (!gssysapps)
gssysapps = "/usr/lib/GNUstep/Applications";
path = checkFile(gssysapps, appdir, ext, resource);
if (path)
goto out;
path = checkFile("/usr/local/GNUstep", appdir, ext, resource);
if (path)
goto out;
path = checkFile(getenv("GNUSTEP_SYSTEM_ROOT"), appdir, ext, resource);
if (path)
goto out;
path = checkFile("/usr/GNUstep", appdir, ext, resource); /* falls through */
path = checkFile("/usr/GNUstep/System/Applications", appdir, ext, resource); /* falls through */
out:
if (appdir)