#include <assert.h>
#include <apr_pools.h>
#include <apr_file_io.h>
#include "svn_io.h"
#include "svn_types.h"
#include "svn_error.h"
#include "svn_path.h"
#include "wc.h"
#include "svn_private_config.h"
svn_error_t *
svn_wc__ensure_directory(const char *path, apr_pool_t *pool)
{
svn_node_kind_t kind;
svn_error_t *err = svn_io_check_path(path, &kind, pool);
if (err)
return err;
if (kind != svn_node_none && kind != svn_node_dir)
{
return svn_error_createf(APR_ENOTDIR, NULL,
_("'%s' is not a directory"),
svn_path_local_style(path, pool));
}
else if (kind == svn_node_none)
{
err = svn_io_dir_make(path, APR_OS_DEFAULT, pool);
if (err && !APR_STATUS_IS_ENOENT(err->apr_err))
{
return err;
}
else if (err && APR_STATUS_IS_ENOENT(err->apr_err))
{
const char *shorter = svn_path_dirname(path, pool);
svn_error_clear(err);
if (shorter[0] == '\0')
{
return svn_error_create(0, NULL,
_("Unable to make any directories"));
}
else
{
err = svn_wc__ensure_directory(shorter, pool);
if (err)
return (err);
else
return svn_wc__ensure_directory(path, pool);
}
}
if (err)
return err;
}
else
assert(kind == svn_node_dir);
return SVN_NO_ERROR;
}
const svn_version_t *
svn_wc_version(void)
{
SVN_VERSION_BODY;
}
svn_wc_notify_t *
svn_wc_create_notify(const char *path, svn_wc_notify_action_t action,
apr_pool_t *pool)
{
svn_wc_notify_t *ret = apr_palloc(pool, sizeof(*ret));
ret->path = path;
ret->action = action;
ret->kind = svn_node_unknown;
ret->mime_type = NULL;
ret->lock = NULL;
ret->err = SVN_NO_ERROR;
ret->content_state = ret->prop_state = svn_wc_notify_state_unknown;
ret->lock_state = svn_wc_notify_lock_state_unknown;
ret->revision = SVN_INVALID_REVNUM;
return ret;
}
static apr_status_t err_cleanup(void *data)
{
svn_error_clear(data);
return APR_SUCCESS;
}
svn_wc_notify_t *
svn_wc_dup_notify(const svn_wc_notify_t *notify, apr_pool_t *pool)
{
svn_wc_notify_t *ret = apr_palloc(pool, sizeof(*ret));
*ret = *notify;
if (ret->path)
ret->path = apr_pstrdup(pool, ret->path);
if (ret->mime_type)
ret->mime_type = apr_pstrdup(pool, ret->mime_type);
if (ret->lock)
ret->lock = svn_lock_dup(ret->lock, pool);
if (ret->err)
{
ret->err = svn_error_dup(ret->err);
apr_pool_cleanup_register(pool, ret->err, err_cleanup,
apr_pool_cleanup_null);
}
return ret;
}
svn_wc_external_item_t *
svn_wc_external_item_dup(const svn_wc_external_item_t *item, apr_pool_t *pool)
{
svn_wc_external_item_t *new_item = apr_palloc(pool, sizeof(*new_item));
*new_item = *item;
if (new_item->target_dir)
new_item->target_dir = apr_pstrdup(pool, new_item->target_dir);
if (new_item->url)
new_item->url = apr_pstrdup(pool, new_item->url);
return new_item;
}
void svn_wc__compat_call_notify_func(void *baton,
const svn_wc_notify_t *n,
apr_pool_t *pool)
{
svn_wc__compat_notify_baton_t *nb = baton;
if (nb->func)
(*nb->func)(nb->baton, n->path, n->action, n->kind, n->mime_type,
n->content_state, n->prop_state, n->revision);
}