Skip to content

Commit

Permalink
chdir() before using xdg-utils, because it doesn't handle paths with …
Browse files Browse the repository at this point in the history
…spaces.
  • Loading branch information
icculus committed Jul 8, 2009
1 parent 4919825 commit db4554e
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions platform_unix.c
Expand Up @@ -1175,6 +1175,38 @@ static boolean unix_launchBrowser(const char *url)
const char *argv[] = { url, NULL };
return unix_launchXdgUtil("xdg-open", argv);
} // unix_launchBrowser


boolean xdgDesktopMenuItem(const char *action, const char *data)
{
// xdg-utils, being shell scripts, don't do well with paths containing
// spaces. We attempt to mitigate this by chdir()'ing to the directory
// with the file to install.
const char *ptr = strrchr(data, '/');
boolean retval = false;
if (ptr == NULL)
{
const char *argv[] = { action, data, NULL };
retval = unix_launchXdgUtil("xdg-desktop-menu", argv);
}
else
{
char *working_dir = MojoPlatform_currentWorkingDir();
if (working_dir != NULL)
{
char *cpy = xstrdup(data);
char *fname = cpy + ((size_t)(ptr-data));
const char *argv[] = { action, fname+1, NULL };
*(fname++) = '\0';
chdir(cpy);
retval = unix_launchXdgUtil("xdg-desktop-menu", argv);
chdir(working_dir);
free(cpy);
free(working_dir);
} // if
} // else
return retval;
} // xdgDesktopMenuItem
#endif


Expand Down Expand Up @@ -1202,8 +1234,7 @@ boolean MojoPlatform_installDesktopMenuItem(const char *data)
STUBBED("desktop menu support");
return false;
#else
const char *argv[] = { "install", data, NULL };
return unix_launchXdgUtil("xdg-desktop-menu", argv);
return xdgDesktopMenuItem("install", data);
#endif
} // MojoPlatform_installDesktopMenuItem

Expand All @@ -1215,8 +1246,7 @@ boolean MojoPlatform_uninstallDesktopMenuItem(const char *data)
STUBBED("desktop menu support");
return false;
#else
const char *argv[] = { "uninstall", data, NULL };
return unix_launchXdgUtil("xdg-desktop-menu", argv);
return xdgDesktopMenuItem("uninstall", data);
#endif
} // MojoPlatform_uninstallDesktopMenuItem

Expand Down

0 comments on commit db4554e

Please sign in to comment.