diff options
author | Tiago Cunha <tcunha@gmx.com> | 2011-10-23 15:08:58 +0000 |
---|---|---|
committer | Tiago Cunha <tcunha@gmx.com> | 2011-10-23 15:08:58 +0000 |
commit | a8ca1340ad1217a6512ce21586f05102c4000cc9 (patch) | |
tree | c18aaadc2f5aaf691313bb87f6c6551d1e599222 /cmd-save-buffer.c | |
parent | 7d169a3679b254c657823906fb61505bccc26aa3 (diff) |
Sync OpenBSD patchset 968:
Try to resolve relative paths for loadb and saveb (first using client
working directory if any then default-path or session wd).
Diffstat (limited to 'cmd-save-buffer.c')
-rw-r--r-- | cmd-save-buffer.c | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/cmd-save-buffer.c b/cmd-save-buffer.c index 9e6096d1..9c2461e1 100644 --- a/cmd-save-buffer.c +++ b/cmd-save-buffer.c @@ -45,8 +45,9 @@ cmd_save_buffer_exec(struct cmd *self, struct cmd_ctx *ctx) { struct args *args = self->args; struct client *c = ctx->cmdclient; + struct session *s; struct paste_buffer *pb; - const char *path; + const char *path, *newpath, *wd; char *cause; int buffer; mode_t mask; @@ -80,6 +81,20 @@ cmd_save_buffer_exec(struct cmd *self, struct cmd_ctx *ctx) } bufferevent_write(c->stdout_event, pb->data, pb->size); } else { + if (c != NULL) + wd = c->cwd; + else if ((s = cmd_current_session(ctx, 0)) != NULL) { + wd = options_get_string(&s->options, "default-path"); + if (*wd == '\0') + wd = s->cwd; + } else + wd = NULL; + if (wd != NULL && *wd != '\0') { + newpath = get_full_path(wd, path); + if (newpath != NULL) + path = newpath; + } + mask = umask(S_IRWXG | S_IRWXO); if (args_has(self->args, 'a')) f = fopen(path, "ab"); |