svn_error_t * svn_fs_bdb__locks_get(svn_fs_t *fs, const char *path, svn_fs_get_locks_callback_t get_locks_func, void *get_locks_baton, trail_t *trail, apr_pool_t *pool) { base_fs_data_t *bfd = fs->fsap_data; DBC *cursor; DBT key, value; int db_err, db_c_err; apr_pool_t *subpool = svn_pool_create(pool); const char *lock_token; svn_lock_t *lock; svn_error_t *err; const char *lookup_path = path; /* First, try to lookup PATH itself. */ err = svn_fs_bdb__lock_token_get(&lock_token, fs, path, trail, pool); if (err && ((err->apr_err == SVN_ERR_FS_LOCK_EXPIRED) || (err->apr_err == SVN_ERR_FS_BAD_LOCK_TOKEN) || (err->apr_err == SVN_ERR_FS_NO_SUCH_LOCK))) { svn_error_clear(err); } else if (err) { return err; } else { SVN_ERR(get_lock(&lock, fs, path, lock_token, trail, pool)); if (lock && get_locks_func) SVN_ERR(get_locks_func(get_locks_baton, lock, pool)); } /* Now go hunt for possible children of PATH. */ if (strcmp(path, "/") != 0) lookup_path = apr_pstrcat(pool, path, "/", NULL); svn_fs_base__trail_debug(trail, "lock-tokens", "cursor"); db_err = bfd->lock_tokens->cursor(bfd->lock_tokens, trail->db_txn, &cursor, 0); SVN_ERR(BDB_WRAP(fs, "creating cursor for reading lock tokens", db_err)); /* Since the key is going to be returned as well as the value make sure BDB malloc's the returned key. */ svn_fs_base__str_to_dbt(&key, lookup_path); key.flags |= DB_DBT_MALLOC; /* Get the first matching key that is either equal or greater than the one passed in, by passing in the DB_RANGE_SET flag. */ db_err = svn_bdb_dbc_get(cursor, &key, svn_fs_base__result_dbt(&value), DB_SET_RANGE); /* As long as the prefix of the returned KEY matches LOOKUP_PATH we know it is either LOOKUP_PATH or a decendant thereof. */ while ((! db_err) && strncmp(lookup_path, key.data, strlen(lookup_path)) == 0) { const char *child_path; svn_pool_clear(subpool); svn_fs_base__track_dbt(&key, subpool); svn_fs_base__track_dbt(&value, subpool); /* Create a usable path and token in temporary memory. */ child_path = apr_pstrmemdup(subpool, key.data, key.size); lock_token = apr_pstrmemdup(subpool, value.data, value.size); /* Get the lock for CHILD_PATH. */ err = get_lock(&lock, fs, child_path, lock_token, trail, subpool); if (err) { svn_bdb_dbc_close(cursor); return err; } /* Lock is verified, hand it off to our callback. */ if (lock && get_locks_func) { err = get_locks_func(get_locks_baton, lock, subpool); if (err) { svn_bdb_dbc_close(cursor); return err; } } svn_fs_base__result_dbt(&key); svn_fs_base__result_dbt(&value); db_err = svn_bdb_dbc_get(cursor, &key, &value, DB_NEXT); } svn_pool_destroy(subpool); db_c_err = svn_bdb_dbc_close(cursor); if (db_err && (db_err != DB_NOTFOUND)) SVN_ERR(BDB_WRAP(fs, "fetching lock tokens", db_err)); if (db_c_err) SVN_ERR(BDB_WRAP(fs, "fetching lock tokens (closing cursor)", db_c_err)); return SVN_NO_ERROR; }
svn_error_t * svn_fs_bdb__locks_get(svn_fs_t *fs, const char *path, svn_depth_t depth, svn_fs_get_locks_callback_t get_locks_func, void *get_locks_baton, trail_t *trail, apr_pool_t *pool) { base_fs_data_t *bfd = fs->fsap_data; DBC *cursor; DBT key, value; int db_err, db_c_err; apr_pool_t *subpool = svn_pool_create(pool); const char *lock_token; svn_lock_t *lock; svn_error_t *err; const char *lookup_path = path; /* First, try to lookup PATH itself. */ err = svn_fs_bdb__lock_token_get(&lock_token, fs, path, trail, pool); if (err && ((err->apr_err == SVN_ERR_FS_LOCK_EXPIRED) || (err->apr_err == SVN_ERR_FS_BAD_LOCK_TOKEN) || (err->apr_err == SVN_ERR_FS_NO_SUCH_LOCK))) { svn_error_clear(err); } else if (err) { return svn_error_trace(err); } else { SVN_ERR(get_lock(&lock, fs, path, lock_token, trail, pool)); if (lock && get_locks_func) SVN_ERR(get_locks_func(get_locks_baton, lock, pool)); } /* If we're only looking at PATH itself (depth = empty), stop here. */ if (depth == svn_depth_empty) return SVN_NO_ERROR; /* Now go hunt for possible children of PATH. */ svn_fs_base__trail_debug(trail, "lock-tokens", "cursor"); db_err = bfd->lock_tokens->cursor(bfd->lock_tokens, trail->db_txn, &cursor, 0); SVN_ERR(BDB_WRAP(fs, "creating cursor for reading lock tokens", db_err)); /* Since the key is going to be returned as well as the value make sure BDB malloc's the returned key. */ svn_fs_base__str_to_dbt(&key, lookup_path); key.flags |= DB_DBT_MALLOC; /* Get the first matching key that is either equal or greater than the one passed in, by passing in the DB_RANGE_SET flag. */ db_err = svn_bdb_dbc_get(cursor, &key, svn_fs_base__result_dbt(&value), DB_SET_RANGE); if (!svn_fspath__is_root(path, strlen(path))) lookup_path = apr_pstrcat(pool, path, "/", (char *)NULL); /* As long as the prefix of the returned KEY matches LOOKUP_PATH we know it is either LOOKUP_PATH or a decendant thereof. */ while ((! db_err) && strncmp(lookup_path, key.data, strlen(lookup_path)) == 0) { const char *child_path; svn_pool_clear(subpool); svn_fs_base__track_dbt(&key, subpool); svn_fs_base__track_dbt(&value, subpool); /* Create a usable path and token in temporary memory. */ child_path = apr_pstrmemdup(subpool, key.data, key.size); lock_token = apr_pstrmemdup(subpool, value.data, value.size); if ((depth == svn_depth_files) || (depth == svn_depth_immediates)) { /* On the assumption that we only store locks for files, depth=files and depth=immediates should boil down to the same set of results. So just see if CHILD_PATH is an immediate child of PATH. If not, we don't care about this item. */ const char *rel_path = svn_fspath__is_child(path, child_path, subpool); if (!rel_path || (svn_path_component_count(rel_path) != 1)) goto loop_it; } /* Get the lock for CHILD_PATH. */ err = get_lock(&lock, fs, child_path, lock_token, trail, subpool); if (err) { svn_bdb_dbc_close(cursor); return svn_error_trace(err); } /* Lock is verified, hand it off to our callback. */ if (lock && get_locks_func) { err = get_locks_func(get_locks_baton, lock, subpool); if (err) { svn_bdb_dbc_close(cursor); return svn_error_trace(err); } } loop_it: svn_fs_base__result_dbt(&key); svn_fs_base__result_dbt(&value); db_err = svn_bdb_dbc_get(cursor, &key, &value, DB_NEXT); } svn_pool_destroy(subpool); db_c_err = svn_bdb_dbc_close(cursor); if (db_err && (db_err != DB_NOTFOUND)) SVN_ERR(BDB_WRAP(fs, "fetching lock tokens", db_err)); if (db_c_err) SVN_ERR(BDB_WRAP(fs, "fetching lock tokens (closing cursor)", db_c_err)); return SVN_NO_ERROR; }