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

Old Hundred Eyes review of svn_io_temp_dir requested

From: <kfogel_at_collab.net>
Date: 2003-11-10 18:32:55 CET

Sander Striker had an idea: it would be great it if people could
glance over


to see if the function misses any standard tmp dir locations... In
fact, to make it *really* easy, I'll just paste the whole function in
right here. Thanks, -Karl

svn_error_t *
svn_io_temp_dir (const char **dir,
                 apr_pool_t *pool)
#if 1 /* TODO: Remove this code when APR 0.9.6 is released. */
  apr_status_t apr_err;
  static const char *try_dirs[] = { "/tmp", "/usr/tmp", "/var/tmp" };
  static const char *try_envs[] = { "TMP", "TEMP", "TMPDIR" };
  const char *temp_dir;
  char *cwd;
  apr_size_t i;

  /* Our goal is to find a temporary directory suitable for writing
     into. We'll only pay the price once if we're successful -- we
     cache our successful find. Here's the order in which we'll try
     various paths:

       "C:\TEMP" (windows only)

     NOTE: This algorithm is basically the same one used by Python
     2.2's tempfile.py module. */

  /* Try the environment first. */
  for (i = 0; i < (sizeof(try_envs) / sizeof(const char *)); i++)
      char *value;
      apr_err = apr_env_get(&value, try_envs[i], pool);
      if ((apr_err == APR_SUCCESS) && value)
          apr_size_t len = strlen(value);
          if (len && (len < APR_PATH_MAX) && test_tempdir(value, pool))
              temp_dir = value;
              goto end;
#ifdef SVN_WIN32
  /* Next, on Win32, try the C:\TEMP directory. */
  if (test_tempdir("C:\\TEMP", pool))
      temp_dir = "C:\\TEMP";
      goto end;
#endif /* SVN_WIN32 */
  /* Next, try a set of hard-coded paths. */
  for (i = 0; i < (sizeof(try_dirs) / sizeof(const char *)); i++)
      if (test_tempdir(try_dirs[i], pool))
          temp_dir = try_dirs[i];
          goto end;

  /* Finally, try the current working directory. */
  if (APR_SUCCESS == apr_filepath_get(&cwd, APR_FILEPATH_NATIVE, pool))
      if (test_tempdir(cwd, pool))
          temp_dir = cwd;
          goto end;

  return svn_error_create
           (APR_EGENERAL, NULL,
            "svn_io_temp_dir: Unable to find a suitable temporary directory");

  *dir = svn_path_canonicalize(temp_dir, pool);
  return SVN_NO_ERROR;

  apr_status_t apr_err = apr_temp_dir_get (dir, pool);

  if (apr_err)
    return svn_error_create
      (apr_err, NULL,
       "svn_io_temp_dir: Unable to find a suitable temporary directory");

  *dir = svn_path_canonicalize (*dir, pool);

  return SVN_NO_ERROR;

To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Mon Nov 10 19:14:26 2003

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.