Revision: 2620
          http://tmux.svn.sourceforge.net/tmux/?rev=2620&view=rev
Author:   tcunha
Date:     2011-10-23 15:08:58 +0000 (Sun, 23 Oct 2011)
Log Message:
-----------
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).

Modified Paths:
--------------
    trunk/cmd-load-buffer.c
    trunk/cmd-save-buffer.c
    trunk/tmux.c
    trunk/tmux.h

Modified: trunk/cmd-load-buffer.c
===================================================================
--- trunk/cmd-load-buffer.c     2011-10-23 15:05:20 UTC (rev 2619)
+++ trunk/cmd-load-buffer.c     2011-10-23 15:08:58 UTC (rev 2620)
@@ -48,8 +48,9 @@
 {
        struct args     *args = self->args;
        struct client   *c = ctx->cmdclient;
+       struct session  *s;
        FILE            *f;
-       const char      *path;
+       const char      *path, *newpath, *wd;
        char            *pdata, *new_pdata, *cause;
        size_t           psize;
        u_int            limit;
@@ -93,6 +94,19 @@
                return (1);
        }
 
+       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;
+       }
        if ((f = fopen(path, "rb")) == NULL) {
                ctx->error(ctx, "%s: %s", path, strerror(errno));
                return (-1);

Modified: trunk/cmd-save-buffer.c
===================================================================
--- trunk/cmd-save-buffer.c     2011-10-23 15:05:20 UTC (rev 2619)
+++ trunk/cmd-save-buffer.c     2011-10-23 15:08:58 UTC (rev 2620)
@@ -45,8 +45,9 @@
 {
        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 @@
                }
                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");

Modified: trunk/tmux.c
===================================================================
--- trunk/tmux.c        2011-10-23 15:05:20 UTC (rev 2619)
+++ trunk/tmux.c        2011-10-23 15:08:58 UTC (rev 2620)
@@ -127,6 +127,22 @@
        return (0);
 }
 
+const char*
+get_full_path(const char *wd, const char *path)
+{
+       static char     newpath[MAXPATHLEN];
+       char            oldpath[MAXPATHLEN];
+
+       if (getcwd(oldpath, sizeof oldpath) == NULL)
+               return (NULL);
+       if (chdir(wd) != 0)
+               return (NULL);
+       if (realpath(path, newpath) != 0)
+               return (NULL);
+       chdir(oldpath);
+       return (newpath);
+}
+
 void
 parseenvironment(void)
 {

Modified: trunk/tmux.h
===================================================================
--- trunk/tmux.h        2011-10-23 15:05:20 UTC (rev 2619)
+++ trunk/tmux.h        2011-10-23 15:08:58 UTC (rev 2620)
@@ -1341,6 +1341,7 @@
 const char     *getshell(void);
 int             checkshell(const char *);
 int             areshell(const char *);
+const char*     get_full_path(const char *, const char *);
 void            setblocking(int, int);
 __dead void     shell_exec(const char *, const char *);
 

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
The demand for IT networking professionals continues to grow, and the
demand for specialized networking skills is growing even more rapidly.
Take a complimentary Learning@Cisco Self-Assessment and learn 
about Cisco certifications, training, and career opportunities. 
http://p.sf.net/sfu/cisco-dev2dev
_______________________________________________
tmux-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tmux-cvs

Reply via email to