You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by "B. W. Fitzpatrick" <fi...@red-bean.com> on 2002/05/31 05:40:11 UTC

[PATCH] svn_dir_make_recursive

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

Re: [PATCH] svn_dir_make_recursive

Posted by cm...@collab.net.
Greg Stein <gs...@lyra.org> writes:

> On Thu, May 30, 2002 at 10:42:34PM -0700, Justin Erenkrantz wrote:
> > On Fri, May 31, 2002 at 12:40:11AM -0500, B. W. Fitzpatrick wrote:
> > > 
> > > 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.
> > 
> > I'd be game to seeing this in APR.  The only problem is that
> > you need any APR way to remove the path components.  -- justin
> 
> I'd also prefer to see it in APR. Note that we have pure-portable functions
> already in APR (see apr_file_read/write_full()).
> 
> Truth to tell, we have a copule functions that would be nice to see in APR.
> Some of them have apr_ prefixes (apr_check_dir_empty and
> apr_hash_sorted_keys). Some others, we've kept as svn_ prefixes, but could
> really go into APR (or one day, create high-level file funcs in apr-util).

Well, I dunno about Greg's "copule" functions (and I don't wanna
know!), but I, too would like to see this apr-ized.  And after it is,
Fitz, can you please change `svnlook diff' (I think it's actually
print_diff_tree() in svnlook/main.c) to use it?  I seem to recall that
I'm basically doing this very thing in that code.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: [PATCH] svn_dir_make_recursive

Posted by Greg Stein <gs...@lyra.org>.
On Thu, May 30, 2002 at 10:42:34PM -0700, Justin Erenkrantz wrote:
> On Fri, May 31, 2002 at 12:40:11AM -0500, B. W. Fitzpatrick wrote:
> > 
> > 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.
> 
> I'd be game to seeing this in APR.  The only problem is that
> you need any APR way to remove the path components.  -- justin

I'd also prefer to see it in APR. Note that we have pure-portable functions
already in APR (see apr_file_read/write_full()).

Truth to tell, we have a copule functions that would be nice to see in APR.
Some of them have apr_ prefixes (apr_check_dir_empty and
apr_hash_sorted_keys). Some others, we've kept as svn_ prefixes, but could
really go into APR (or one day, create high-level file funcs in apr-util).

Cheers,
-g

-- 
Greg Stein, http://www.lyra.org/

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: [PATCH] svn_dir_make_recursive

Posted by Justin Erenkrantz <je...@apache.org>.
On Fri, May 31, 2002 at 12:40:11AM -0500, B. W. Fitzpatrick wrote:
> 
> 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.

I'd be game to seeing this in APR.  The only problem is that
you need any APR way to remove the path components.  -- justin

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org