Permalink
Browse files

Use subdirectories for temporary files

  • Loading branch information...
1 parent ad151fc commit 3a365cb9a8daf921858e661d1180aabb4a1f4eb8 @jgehring committed Mar 8, 2012
Showing with 35 additions and 13 deletions.
  1. +7 −6 src/delta.c
  2. +3 −2 src/path_hash.c
  3. +18 −0 src/utils.c
  4. +7 −5 src/utils.h
View
@@ -41,6 +41,7 @@
#include "property.h"
#include "rhash.h"
#include "session.h"
+#include "utils.h"
#include "delta.h"
@@ -237,8 +238,8 @@ static svn_error_t *delta_write_properties(de_node_baton_t *node)
}
/* Create a new temporary file */
- filename = apr_psprintf(node->pool, "%s/XXXXXX", opts->temp_dir);
- status = apr_file_mktemp(&file, filename, APR_CREATE | APR_READ | APR_WRITE | APR_EXCL, pool);
+ filename = apr_psprintf(node->pool, "%s/pr/XXXXXX", opts->temp_dir);
+ status = utils_mkstemp(&file, filename, pool);
if (status) {
DEBUG_MSG("delta_write_properties(%s): Error creating temporary file in %s\n", node->path, opts->temp_dir);
return svn_error_wrap_apr(status, "Unable to create temporary file in %s", opts->temp_dir);
@@ -503,8 +504,8 @@ static svn_error_t *delta_deltify_node(de_node_baton_t *node)
}
/* Open temporary output file */
- node->delta_filename = apr_psprintf(node->pool, "%s/XXXXXX", opts->temp_dir);
- status = apr_file_mktemp(&dest_file, node->delta_filename, APR_CREATE | APR_READ | APR_WRITE | APR_EXCL, pool);
+ node->delta_filename = apr_psprintf(node->pool, "%s/df/XXXXXX", opts->temp_dir);
+ status = utils_mkstemp(&dest_file, node->delta_filename, pool);
if (status) {
DEBUG_MSG("delta_deltify_node(%s): Error creating temporary file in %s\n", node->path, opts->temp_dir);
return svn_error_wrap_apr(status, "Unable to create temporary file in %s", opts->temp_dir);
@@ -1217,8 +1218,8 @@ static svn_error_t *de_apply_textdelta(void *file_baton, const char *base_checks
DEBUG_MSG("de_apply_textdelta(%s)\n", node->path);
/* Create a new temporary file to write to */
- node->filename = apr_psprintf(node->pool, "%s/XXXXXX", opts->temp_dir);
- status = apr_file_mktemp(&dest_file, node->filename, APR_CREATE | APR_READ | APR_WRITE | APR_EXCL, pool);
+ node->filename = apr_psprintf(node->pool, "%s/td/XXXXXX", opts->temp_dir);
+ status = utils_mkstemp(&dest_file, node->filename, pool);
if (status) {
DEBUG_MSG("de_apply_textdelta(%s): Error creating temporary file in %s\n", node->path, opts->temp_dir);
return svn_error_wrap_apr(status, "Unable to create temporary file in %s", opts->temp_dir);
View
@@ -692,8 +692,9 @@ static char *path_hash_write_deltas(apr_pool_t *pool)
#endif
apr_pool_t *delta_pool = svn_pool_create(pool);
- filename = apr_psprintf(pool, "%s/XXXXXX", ph_temp_dir);
- status = apr_file_mktemp(&aprfile, filename, APR_CREATE | APR_READ | APR_WRITE | APR_EXCL | APR_BINARY, pool);
+ filename = apr_psprintf(pool, "%s/ph/XXXXXX", ph_temp_dir);
+ status = utils_mkstemp(&aprfile, filename, pool);
+
DEBUG_MSG("path_hash: temp_file = %s : %d\n", filename, status);
if (status) {
fprintf(stderr, _("ERROR: Unable to create temporary file (%d)\n"), status);
View
@@ -50,6 +50,7 @@
#include <windows.h>
#else
#include <sys/time.h>
+ #include <sys/stat.h>
#endif
@@ -176,6 +177,23 @@ void utils_handle_error(svn_error_t *error, FILE *stream, svn_boolean_t fatal, c
}
+/* Creates a temporary file with a multi-directory template */
+extern int utils_mkstemp(apr_file_t **file, char *name, apr_pool_t *pool)
+{
+ apr_status_t status;
+ char *dir;
+
+ /* Create intermediate directories if needed */
+ dir = svn_path_dirname(name, pool);
+ status = apr_dir_make_recursive(dir, APR_UREAD | APR_UWRITE | APR_UEXECUTE, pool);
+ if (status != APR_SUCCESS) {
+ return status;
+ }
+
+ return apr_file_mktemp(file, name, APR_CREATE | APR_READ | APR_WRITE | APR_EXCL | APR_BINARY, pool);
+}
+
+
/* Returns the file descriptor of an APR file */
int utils_apr_file_fd(struct apr_file_t *file)
{
View
@@ -48,19 +48,21 @@ extern float stopwatch_elapsed(stopwatch_t *watch);
#endif /* USE_TIMING */
/* Returns a canonicalized path that has been allocated using strdup() */
-extern char *utils_canonicalize_pstrdup(struct apr_pool_t *pool, char *path);
+extern char *utils_canonicalize_pstrdup(apr_pool_t *pool, char *path);
+/* Creates a temporary file with a multi-directory template */
+extern int utils_mkstemp(apr_file_t **file, char *name, apr_pool_t *pool);
/* Returns the file descriptor of an APR file */
-extern int utils_apr_file_fd(struct apr_file_t *file);
+extern int utils_apr_file_fd(apr_file_t *file);
/* Recursively removes the contents of a directory and the directory */
/* itself it 'rmdir' is non-zero */
-extern void utils_rrmdir(struct apr_pool_t *pool, const char *path, char rmdir);
+extern void utils_rrmdir(apr_pool_t *pool, const char *path, char rmdir);
/* Path splitting and joining */
-extern void utils_path_split(struct apr_pool_t *pool, const char *path, const char **dir, const char **base);
-extern const char *utils_path_join(struct apr_pool_t *pool, const char *dir, const char *base);
+extern void utils_path_split(apr_pool_t *pool, const char *path, const char **dir, const char **base);
+extern const char *utils_path_join(apr_pool_t *pool, const char *dir, const char *base);

0 comments on commit 3a365cb

Please sign in to comment.