[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: [PATCH] Re: [PATCH] Quote filename passed to $EDITOR

From: Marcus Comstedt <marcus_at_mc.pp.se>
Date: 2002-07-24 01:48:00 CEST

Karl Fogel <kfogel@newton.ch.collab.net> writes:

> Marcus, the patch doesn't have a log message.
>
> Can you repost it with a log message? (If your mailer allows you to
> put the patch inline, instead of as an attachment, that would be great
> too, but not a big deal either way).

Certainly.

---8<--- log message ---8<---

* subversion/clients/cmdline/util.c
  (svn_cl__edit_externally): Avoid the need to put base_dir into the
  tmpfile filename by doing a cd there first. Fixes issue #809.
  Fixed problem in cleanup code with using tmpfile_native, which may
  not have been initialized yet.
  Fixed one spelling error.

---8<---
        ^^^ no pun intended, really. :-)

---8<--- patch ---8<---
Index: subversion/clients/cmdline/util.c
===================================================================
--- subversion/clients/cmdline/util.c
+++ subversion/clients/cmdline/util.c Tue Jul 23 23:16:05 2002
@@ -351,11 +351,12 @@
   const char *cmd;
   apr_file_t *tmp_file;
   const char *tmpfile_name;
- const char *contents_native, *tmpfile_native;
+ const char *contents_native, *tmpfile_native, *base_dir_native;
   apr_status_t apr_err, apr_err2;
   apr_size_t written;
   apr_finfo_t finfo_before, finfo_after;
- svn_error_t *err = SVN_NO_ERROR;
+ svn_error_t *err = SVN_NO_ERROR, *err2;
+ char *old_cwd;
   int sys_err;
 
   /* Try to find an editor in the environment. */
@@ -375,12 +376,33 @@
   /* Convert file contents from UTF-8 */
   SVN_ERR (svn_utf_cstring_from_utf8 (&contents_native, contents, pool));
 
- /* Ask the working copy for a temporary file based on BASE_DIR */
- SVN_ERR (svn_io_open_unique_file
- (&tmp_file, &tmpfile_name,
- svn_path_join (base_dir, "msg", pool), ".tmp", FALSE, pool));
+ /* Move to BASE_DIR to avoid getting characters that need quoting
+ into tmpfile_name */
+ apr_err = apr_filepath_get (&old_cwd, APR_FILEPATH_NATIVE, pool);
+ if (apr_err)
+ {
+ return svn_error_create
+ (apr_err, 0, NULL, pool, "failed to get current working directory");
+ }
+ SVN_ERR (svn_utf_cstring_from_utf8 (&base_dir_native, base_dir, pool));
+ apr_err = apr_filepath_set (base_dir_native, pool);
+ if (apr_err)
+ {
+ return svn_error_createf
+ (apr_err, 0, NULL, pool,
+ "failed to change working directory to '%s'", base_dir);
+ }
+
+ /*** From here on, any problems that occur require us to cd back!! ***/
 
- /*** From here one, any problems that occur require us to cleanup
+ /* Ask the working copy for a temporary file */
+ err = svn_io_open_unique_file
+ (&tmp_file, &tmpfile_name,
+ "msg", ".tmp", FALSE, pool);
+ if (err)
+ goto cleanup2;
+
+ /*** From here on, any problems that occur require us to cleanup
        the file we just created!! ***/
 
   /* Dump initial CONTENTS to TMP_FILE. */
@@ -416,7 +438,7 @@
     }
 
   /* Now, run the editor command line. */
- cmd = apr_psprintf (pool, "%s \"%s\"", editor, tmpfile_native);
+ cmd = apr_psprintf (pool, "%s %s", editor, tmpfile_native);
   sys_err = system (cmd);
   if (sys_err != 0)
     {
@@ -457,12 +479,24 @@
 
  cleanup:
 
- apr_err = apr_file_remove (tmpfile_native, pool);
+ err2 = svn_io_remove_file (tmpfile_name, pool);
 
   /* Only report remove error if there was no previous error. */
- if (! err && apr_err)
- err = svn_error_createf (apr_err, 0, NULL, pool,
- "failed to remove '%s'", tmpfile_name);
+ if (! err && err2)
+ err = err2;
+
+ cleanup2:
+
+ /* If we against all probability can't cd back, all further relative
+ file references would be screwed up, so we have to abort. */
+ apr_err = apr_filepath_set (old_cwd, pool);
+ if (apr_err)
+ {
+ svn_handle_error (svn_error_create
+ (apr_err, 0, NULL, pool,
+ "failed to restore current working directory"),
+ stderr, TRUE /* fatal */);
+ }
 
   return err;
 }

---8<---

  // Marcus

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Wed Jul 24 01:54:33 2002

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.