mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Dont build paths manually in cmd_funcs.c
Some time ago we introduced get_expanded_path(). No need to build paths manually anymore to get ~.
This commit is contained in:
parent
537b14da50
commit
cb0adae63a
@ -1117,20 +1117,11 @@ cmd_export(ProfWin* window, const char* const command, gchar** args)
|
|||||||
cons_show("");
|
cons_show("");
|
||||||
return TRUE;
|
return TRUE;
|
||||||
} else {
|
} else {
|
||||||
GString* fname = g_string_new("");
|
|
||||||
GSList* list = NULL;
|
|
||||||
int fd;
|
int fd;
|
||||||
|
GSList* list = NULL;
|
||||||
|
char* path = get_expanded_path(args[0]);
|
||||||
|
|
||||||
/* deal with the ~ convention for $HOME */
|
fd = open(path, O_WRONLY | O_CREAT, 00600);
|
||||||
if (args[0][0] == '~') {
|
|
||||||
fname = g_string_append(fname, getenv("HOME"));
|
|
||||||
fname = g_string_append(fname, args[0] + 1);
|
|
||||||
} else {
|
|
||||||
fname = g_string_append(fname, args[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
fd = open(fname->str, O_WRONLY | O_CREAT, 00600);
|
|
||||||
g_string_free(fname, TRUE);
|
|
||||||
|
|
||||||
if (-1 == fd) {
|
if (-1 == fd) {
|
||||||
cons_show("error: cannot open %s: %s", args[0], strerror(errno));
|
cons_show("error: cannot open %s: %s", args[0], strerror(errno));
|
||||||
@ -6863,20 +6854,12 @@ cmd_plugins_sourcepath(ProfWin* window, const char* const command, gchar** args)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (g_strcmp0(args[1], "set") == 0) {
|
if (g_strcmp0(args[1], "set") == 0) {
|
||||||
char* path = args[2];
|
if (args[2] == NULL) {
|
||||||
if (path == NULL) {
|
|
||||||
cons_bad_cmd_usage(command);
|
cons_bad_cmd_usage(command);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// expand ~ to $HOME
|
char *path = get_expanded_path(args[2]);
|
||||||
if (path[0] == '~' && path[1] == '/') {
|
|
||||||
if (asprintf(&path, "%s/%s", getenv("HOME"), path + 2) == -1) {
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
path = strdup(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!is_dir(path)) {
|
if (!is_dir(path)) {
|
||||||
cons_show("Plugins sourcepath must be a directory.");
|
cons_show("Plugins sourcepath must be a directory.");
|
||||||
@ -6897,8 +6880,9 @@ cmd_plugins_sourcepath(ProfWin* window, const char* const command, gchar** args)
|
|||||||
gboolean
|
gboolean
|
||||||
cmd_plugins_install(ProfWin* window, const char* const command, gchar** args)
|
cmd_plugins_install(ProfWin* window, const char* const command, gchar** args)
|
||||||
{
|
{
|
||||||
char* path = args[1];
|
char *path;
|
||||||
if (path == NULL) {
|
|
||||||
|
if (args[1] == NULL) {
|
||||||
char* sourcepath = prefs_get_string(PREF_PLUGINS_SOURCEPATH);
|
char* sourcepath = prefs_get_string(PREF_PLUGINS_SOURCEPATH);
|
||||||
if (sourcepath) {
|
if (sourcepath) {
|
||||||
path = strdup(sourcepath);
|
path = strdup(sourcepath);
|
||||||
@ -6907,12 +6891,8 @@ cmd_plugins_install(ProfWin* window, const char* const command, gchar** args)
|
|||||||
cons_show("Either a path must be provided or the sourcepath property must be set, see /help plugins");
|
cons_show("Either a path must be provided or the sourcepath property must be set, see /help plugins");
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
} else if (path[0] == '~' && path[1] == '/') {
|
|
||||||
if (asprintf(&path, "%s/%s", getenv("HOME"), path + 2) == -1) {
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
path = strdup(path);
|
path = get_expanded_path(args[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_regular_file(path)) {
|
if (is_regular_file(path)) {
|
||||||
@ -6972,8 +6952,9 @@ cmd_plugins_install(ProfWin* window, const char* const command, gchar** args)
|
|||||||
gboolean
|
gboolean
|
||||||
cmd_plugins_update(ProfWin* window, const char* const command, gchar** args)
|
cmd_plugins_update(ProfWin* window, const char* const command, gchar** args)
|
||||||
{
|
{
|
||||||
char* path = args[1];
|
char* path;
|
||||||
if (path == NULL) {
|
|
||||||
|
if (args[1] == NULL) {
|
||||||
char* sourcepath = prefs_get_string(PREF_PLUGINS_SOURCEPATH);
|
char* sourcepath = prefs_get_string(PREF_PLUGINS_SOURCEPATH);
|
||||||
if (sourcepath) {
|
if (sourcepath) {
|
||||||
path = strdup(sourcepath);
|
path = strdup(sourcepath);
|
||||||
@ -6982,12 +6963,8 @@ cmd_plugins_update(ProfWin* window, const char* const command, gchar** args)
|
|||||||
cons_show("Either a path must be provided or the sourcepath property must be set, see /help plugins");
|
cons_show("Either a path must be provided or the sourcepath property must be set, see /help plugins");
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
} else if (path[0] == '~' && path[1] == '/') {
|
|
||||||
if (asprintf(&path, "%s/%s", getenv("HOME"), path + 2) == -1) {
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
path = strdup(path);
|
path = get_expanded_path(args[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (access(path, R_OK) != 0) {
|
if (access(path, R_OK) != 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user