示例#1
0
/* Open a file somewhere in the adm area for directory PATH.
 * First, add the adm subdir as the next component of PATH, then add
 * each of the varargs (they are char *'s), then add EXTENSION if it
 * is non-null, then open the resulting file as *STREAM.
 *
 * If FLAGS indicates writing, open the file in the adm tmp area.
 * This means the file will probably need to be renamed from there,
 * either by passing the sync flag to close_adm_file() later, or with
 * an explicit call to sync_adm_file().
 */
static svn_error_t *
open_adm_file(svn_stream_t **stream,
              const char **selected_path,
              const char *path,
              const char *extension,
              svn_boolean_t for_writing,
              apr_pool_t *result_pool,
              apr_pool_t *scratch_pool,
              ...)
{
  svn_error_t *err;
  va_list ap;

  /* If we're writing, always do it to a tmp file. */
  if (for_writing)
    {
      /* Extend with tmp name. */
      va_start(ap, scratch_pool);
      path = v_extend_with_adm_name(path, extension, TRUE, result_pool, ap);
      va_end(ap);

      err = svn_stream_open_writable(stream, path, result_pool, scratch_pool);
    }
  else
    {
      /* Extend with regular adm name. */
      va_start(ap, scratch_pool);
      path = v_extend_with_adm_name(path, extension, FALSE, result_pool, ap);
      va_end(ap);

      err = svn_stream_open_readonly(stream, path, result_pool, scratch_pool);
    }

  if (selected_path)
    *selected_path = path;  /* note: built in result_pool */

  if (for_writing && err && APR_STATUS_IS_EEXIST(err->apr_err))
    {
      /* Exclusive open failed, delete and retry */
      svn_error_clear(err);
      SVN_ERR(svn_io_remove_file(path, scratch_pool));
      err = svn_stream_open_writable(stream, path, result_pool, scratch_pool);
    }

  /* Examine the error from the first and/or second attempt at opening. */
  if (for_writing && err && APR_STATUS_IS_ENOENT(err->apr_err))
    {
      /* If we receive a failure to open a file in our temporary directory,
       * it may be because our temporary directories aren't created.
       * Older SVN clients did not create these directories.
       * 'svn cleanup' will fix this problem.
       */
      err = svn_error_quick_wrap(err,
                                 _("Your .svn/tmp directory may be missing or "
                                   "corrupt; run 'svn cleanup' and try again"));
    }

  return err;
}
示例#2
0
  /**
   * closes and deletes temporary files that diff has been using
   */
  static void
  diffCleanup(apr_file_t * outfile, const char * outfileName,
              apr_file_t * errfile, const char * errfileName,
              apr_pool_t *pool)
  {
    if (outfile != nullptr)
      apr_file_close(outfile);

    if (errfile != nullptr)
      apr_file_close(errfile);

    if (outfileName != nullptr)
      svn_error_clear(svn_io_remove_file(outfileName, pool));

    if (errfileName != nullptr)
      svn_error_clear(svn_io_remove_file(errfileName, pool));
  }
示例#3
0
svn_error_t *
svn_wc__remove_adm_file(const svn_wc_adm_access_t *adm_access,
                        const char *filename,
                        apr_pool_t *scratch_pool)
{
  const char *path = svn_wc__adm_child(svn_wc_adm_access_path(adm_access),
                                       filename, scratch_pool);

  return svn_io_remove_file(path, scratch_pool);
}
示例#4
0
文件: activity.c 项目: vocho/openqnx
dav_error *
dav_svn__store_activity(const dav_svn_repos *repos,
                        const char *activity_id,
                        const char *txn_name)
{
  const char *final_path, *tmp_path, *activity_contents;
  svn_error_t *err;
  apr_file_t *activity_file;

  /* Create activities directory if it does not yet exist. */
  err = svn_io_make_dir_recursively(repos->activities_db, repos->pool);
  if (err != NULL)
    return dav_svn__convert_err(err, HTTP_INTERNAL_SERVER_ERROR,
                                "could not initialize activity db.",
                                repos->pool);

  final_path = activity_pathname(repos, activity_id);
  err = svn_io_open_unique_file2(&activity_file, &tmp_path, final_path,
                                 ".tmp", svn_io_file_del_none, repos->pool);
  if (err)
    {
      svn_error_t *serr = svn_error_quick_wrap(err, "Can't open activity db");
      return dav_svn__convert_err(serr, HTTP_INTERNAL_SERVER_ERROR,
                                  "could not open files.",
                                  repos->pool);
    }

  activity_contents = apr_psprintf(repos->pool, "%s\n%s\n",
                                   txn_name, activity_id);
  err = svn_io_file_write_full(activity_file, activity_contents,
                               strlen(activity_contents), NULL, repos->pool);
  if (err)
    {
      svn_error_t *serr = svn_error_quick_wrap(err,
                                               "Can't write to activity db");

      /* Try to remove the tmp file, but we already have an error... */
      svn_error_clear(svn_io_file_close(activity_file, repos->pool));
      svn_error_clear(svn_io_remove_file(tmp_path, repos->pool));
      return dav_svn__convert_err(serr, HTTP_INTERNAL_SERVER_ERROR,
                                  "could not write files.",
                                  repos->pool);
    }

  err = svn_io_file_close(activity_file, repos->pool);
  if (err)
    {
      svn_error_clear(svn_io_remove_file(tmp_path, repos->pool));
      return dav_svn__convert_err(err, HTTP_INTERNAL_SERVER_ERROR,
                                  "could not close files.",
                                  repos->pool);
    }

  err = svn_io_file_rename(tmp_path, final_path, repos->pool);
  if (err)
    {
      svn_error_clear(svn_io_remove_file(tmp_path, repos->pool));
      return dav_svn__convert_err(err, HTTP_INTERNAL_SERVER_ERROR,
                                  "could not replace files.",
                                  repos->pool);
    }

  return NULL;
}
示例#5
0
文件: activity.c 项目: vocho/openqnx
dav_error *
dav_svn__delete_activity(const dav_svn_repos *repos, const char *activity_id)
{
  dav_error *err = NULL;
  const char *pathname;
  svn_fs_txn_t *txn;
  const char *txn_name;
  svn_error_t *serr;

  /* gstein sez: If the activity ID is not in the database, return a
     404.  If the transaction is not present or is immutable, return a
     204.  For all other failures, return a 500. */

  pathname = activity_pathname(repos, activity_id);
  txn_name = read_txn(pathname, repos->pool);
  if (txn_name == NULL)
    {
      return dav_new_error(repos->pool, HTTP_NOT_FOUND, 0,
                           "could not find activity.");
    }

  /* After this point, we have to cleanup the value and database. */

  /* An empty txn_name indicates the transaction has been committed,
     so don't try to clean it up. */
  if (*txn_name)
    {
      /* Now, we attempt to delete TXN_NAME from the Subversion
         repository.  If we fail only because the transaction doesn't
         exist, don't sweat it (but then, also don't try to remove it). */
      if ((serr = svn_fs_open_txn(&txn, repos->fs, txn_name, repos->pool)))
        {
          if (serr->apr_err == SVN_ERR_FS_NO_SUCH_TRANSACTION)
            {
              svn_error_clear(serr);
              serr = SVN_NO_ERROR;
            }
          else
            {
              err = dav_svn__convert_err(serr, HTTP_INTERNAL_SERVER_ERROR,
                                         "could not open transaction.",
                                         repos->pool);
              return err;
            }
        }
      else
        {
          serr = svn_fs_abort_txn(txn, repos->pool);
          if (serr)
            {
              err = dav_svn__convert_err(serr, HTTP_INTERNAL_SERVER_ERROR,
                                         "could not abort transaction.",
                                         repos->pool);
              return err;
            }
        }
    }

  /* Finally, we remove the activity from the activities database. */
  serr = svn_io_remove_file(pathname, repos->pool);
  if (serr)
    err = dav_svn__convert_err(serr, HTTP_INTERNAL_SERVER_ERROR,
                               "unable to remove activity.",
                               repos->pool);

  return err;
}
示例#6
0
 ~pysvn_apr_file()
 {
     close();
     if( m_filename )
         svn_error_clear( svn_io_remove_file( m_filename, m_pool ) );
 }