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

[PATCH] svn_dir_make_recursive

From: B. W. Fitzpatrick <fitz_at_red-bean.com>
Date: 2002-05-31 07:40:11 CEST

OK, I lied. It's not really a patch (and it's not in subversion style,
but I can tweak it easily).

My question is: where in the hell can I put this?

I could apr-ize it and put it next to apr_dir_make, but this function
isn't really platform dependent.

apr-util? But that doesn't really have a place for it either...

libsvn_subr/path.c doesn't seem right...

Any suggestions? It's a useful enough bit of code IMO.

-Fitz

/** Creates a new directory on the file system, but behaves like
 * 'mkdir -p'. Creates intermediate directories as required. No error
 * will be reported if PATH already exists.
 *
 * @param path the path for the directory to be created. (use / on all systems)
 * @param perm Permissions for the new direcoty.
 * @param cont the pool to use. */
static svn_error_t *
svn_dir_make_recursive(const char *path,
                     apr_fileperms_t perm,
                     apr_pool_t *pool);

--------------------8-<-------cut-here---------8-<-----------------------

static svn_error_t *
svn_dir_make_recursive(const char *path,
                     apr_fileperms_t perm,
                     apr_pool_t *pool)
{
    apr_status_t apr_err = 0;
    char *dir;
    
    /* Try to make PATH right out */
    apr_err = apr_dir_make (path, perm, pool);

    /* It's OK if PATH exists */
    if (apr_err == EEXIST)
        return svn_error_create (SVN_NO_ERROR, 0, NULL, pool, path);
    
    if (apr_err == ENOENT) {
        /* Missing an intermediate dir */
        svn_error_t *svn_err;
        
        dir = svn_path_remove_component_nts(path, pool);
        svn_err = svn_dir_make_recursive(dir, perm, pool);
        
        if (!svn_err->src_err) {
            apr_err = apr_dir_make (path, perm, pool);
            return svn_error_create (apr_err, 0, NULL, pool, path);
        }

        return svn_err;
    }

    return svn_error_create (apr_err, 0, NULL, pool, path);
}

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Sat Jun 1 14:14:27 2002

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