1251881Speter/** 2251881Speter * @copyright 3251881Speter * ==================================================================== 4251881Speter * Licensed to the Apache Software Foundation (ASF) under one 5251881Speter * or more contributor license agreements. See the NOTICE file 6251881Speter * distributed with this work for additional information 7251881Speter * regarding copyright ownership. The ASF licenses this file 8251881Speter * to you under the Apache License, Version 2.0 (the 9251881Speter * "License"); you may not use this file except in compliance 10251881Speter * with the License. You may obtain a copy of the License at 11251881Speter * 12251881Speter * http://www.apache.org/licenses/LICENSE-2.0 13251881Speter * 14251881Speter * Unless required by applicable law or agreed to in writing, 15251881Speter * software distributed under the License is distributed on an 16251881Speter * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17251881Speter * KIND, either express or implied. See the License for the 18251881Speter * specific language governing permissions and limitations 19251881Speter * under the License. 20251881Speter * ==================================================================== 21251881Speter * @endcopyright 22251881Speter * 23251881Speter * @file svn_io.h 24251881Speter * @brief General file I/O for Subversion 25251881Speter */ 26251881Speter 27251881Speter/* ==================================================================== */ 28251881Speter 29251881Speter 30251881Speter#ifndef SVN_IO_H 31251881Speter#define SVN_IO_H 32251881Speter 33251881Speter#include <apr.h> 34251881Speter#include <apr_pools.h> 35251881Speter#include <apr_time.h> 36251881Speter#include <apr_hash.h> 37251881Speter#include <apr_tables.h> 38251881Speter#include <apr_file_io.h> 39251881Speter#include <apr_file_info.h> 40251881Speter#include <apr_thread_proc.h> /* for apr_proc_t, apr_exit_why_e */ 41251881Speter 42251881Speter#include "svn_types.h" 43251881Speter#include "svn_string.h" 44251881Speter#include "svn_checksum.h" 45251881Speter 46251881Speter#ifdef __cplusplus 47251881Speterextern "C" { 48251881Speter#endif /* __cplusplus */ 49251881Speter 50251881Speter 51251881Speter 52251881Speter/** Used as an argument when creating temporary files to indicate 53251881Speter * when a file should be removed. 54251881Speter * 55251881Speter * @since New in 1.4. 56251881Speter * 57251881Speter * Not specifying any of these means no removal at all. */ 58251881Spetertypedef enum svn_io_file_del_t 59251881Speter{ 60251881Speter /** No deletion ever */ 61251881Speter svn_io_file_del_none = 0, 62251881Speter /** Remove when the file is closed */ 63251881Speter svn_io_file_del_on_close, 64251881Speter /** Remove when the associated pool is cleared */ 65251881Speter svn_io_file_del_on_pool_cleanup 66251881Speter} svn_io_file_del_t; 67251881Speter 68251881Speter/** A set of directory entry data elements as returned by svn_io_get_dirents 69251881Speter * 70251881Speter * Note that the first two fields are exactly identical to svn_io_dirent_t 71251881Speter * to allow returning a svn_io_dirent2_t as a svn_io_dirent_t. 72251881Speter * 73251881Speter * Use svn_io_dirent2_create() to create new svn_dirent2_t instances or 74251881Speter * svn_io_dirent2_dup() to duplicate an existing instance. 75251881Speter * 76251881Speter * @since New in 1.7. 77251881Speter */ 78251881Spetertypedef struct svn_io_dirent2_t { 79251881Speter /* New fields must be added at the end to preserve binary compatibility */ 80251881Speter 81251881Speter /** The kind of this entry. */ 82251881Speter svn_node_kind_t kind; 83251881Speter 84251881Speter /** If @c kind is #svn_node_file, whether this entry is a special file; 85251881Speter * else FALSE. 86251881Speter * 87251881Speter * @see svn_io_check_special_path(). 88251881Speter */ 89251881Speter svn_boolean_t special; 90251881Speter 91251881Speter /** The filesize of this entry or undefined for a directory */ 92251881Speter svn_filesize_t filesize; 93251881Speter 94251881Speter /** The time the file was last modified */ 95251881Speter apr_time_t mtime; 96251881Speter 97251881Speter /* Don't forget to update svn_io_dirent2_dup() when adding new fields */ 98251881Speter} svn_io_dirent2_t; 99251881Speter 100251881Speter 101251881Speter/** Creates a new #svn_io_dirent2_t structure 102251881Speter * 103251881Speter * @since New in 1.7. 104251881Speter */ 105251881Spetersvn_io_dirent2_t * 106251881Spetersvn_io_dirent2_create(apr_pool_t *result_pool); 107251881Speter 108251881Speter/** Duplicates a @c svn_io_dirent2_t structure into @a result_pool. 109251881Speter * 110251881Speter * @since New in 1.7. 111251881Speter */ 112251881Spetersvn_io_dirent2_t * 113251881Spetersvn_io_dirent2_dup(const svn_io_dirent2_t *item, 114251881Speter apr_pool_t *result_pool); 115251881Speter 116251881Speter/** Represents the kind and special status of a directory entry. 117251881Speter * 118251881Speter * Note that the first two fields are exactly identical to svn_io_dirent2_t 119251881Speter * to allow returning a svn_io_dirent2_t as a svn_io_dirent_t. 120251881Speter * 121251881Speter * @since New in 1.3. 122251881Speter */ 123251881Spetertypedef struct svn_io_dirent_t { 124251881Speter /** The kind of this entry. */ 125251881Speter svn_node_kind_t kind; 126251881Speter /** If @c kind is #svn_node_file, whether this entry is a special file; 127251881Speter * else FALSE. 128251881Speter * 129251881Speter * @see svn_io_check_special_path(). 130251881Speter */ 131251881Speter svn_boolean_t special; 132251881Speter} svn_io_dirent_t; 133251881Speter 134251881Speter/** Determine the @a kind of @a path. @a path should be UTF-8 encoded. 135251881Speter * 136251881Speter * If @a path is a file, set @a *kind to #svn_node_file. 137251881Speter * 138251881Speter * If @a path is a directory, set @a *kind to #svn_node_dir. 139251881Speter * 140251881Speter * If @a path does not exist, set @a *kind to #svn_node_none. 141251881Speter * 142251881Speter * If @a path exists but is none of the above, set @a *kind to 143251881Speter * #svn_node_unknown. 144251881Speter * 145251881Speter * If @a path is not a valid pathname, set @a *kind to #svn_node_none. If 146251881Speter * unable to determine @a path's kind for any other reason, return an error, 147251881Speter * with @a *kind's value undefined. 148251881Speter * 149251881Speter * Use @a pool for temporary allocations. 150251881Speter * 151251881Speter * @see svn_node_kind_t 152251881Speter */ 153251881Spetersvn_error_t * 154251881Spetersvn_io_check_path(const char *path, 155251881Speter svn_node_kind_t *kind, 156251881Speter apr_pool_t *pool); 157251881Speter 158251881Speter/** 159251881Speter * Like svn_io_check_path(), but also set *is_special to @c TRUE if 160251881Speter * the path is not a normal file. 161251881Speter * 162251881Speter * @since New in 1.1. 163251881Speter */ 164251881Spetersvn_error_t * 165251881Spetersvn_io_check_special_path(const char *path, 166251881Speter svn_node_kind_t *kind, 167251881Speter svn_boolean_t *is_special, 168251881Speter apr_pool_t *pool); 169251881Speter 170251881Speter/** Like svn_io_check_path(), but resolve symlinks. This returns the 171251881Speter same varieties of @a kind as svn_io_check_path(). */ 172251881Spetersvn_error_t * 173251881Spetersvn_io_check_resolved_path(const char *path, 174251881Speter svn_node_kind_t *kind, 175251881Speter apr_pool_t *pool); 176251881Speter 177251881Speter 178251881Speter/** Open a new file (for reading and writing) with a unique name based on 179251881Speter * utf-8 encoded @a filename, in the directory @a dirpath. The file handle is 180251881Speter * returned in @a *file, and the name, which ends with @a suffix, is returned 181251881Speter * in @a *unique_name, also utf8-encoded. Either @a file or @a unique_name 182251881Speter * may be @c NULL. If @a file is @c NULL, the file will be created but not 183251881Speter * open. 184251881Speter * 185251881Speter * If @a delete_when is #svn_io_file_del_on_close, then the @c APR_DELONCLOSE 186251881Speter * flag will be used when opening the file. The @c APR_BUFFERED flag will 187251881Speter * always be used. 188251881Speter * 189251881Speter * The first attempt will just append @a suffix. If the result is not 190251881Speter * a unique name, then subsequent attempts will append a dot, 191251881Speter * followed by an iteration number ("2", then "3", and so on), 192251881Speter * followed by the suffix. For example, successive calls to 193251881Speter * 194251881Speter * svn_io_open_uniquely_named(&f, &u, "tests/t1/A/D/G", "pi", ".tmp", ...) 195251881Speter * 196251881Speter * will open 197251881Speter * 198251881Speter * tests/t1/A/D/G/pi.tmp 199251881Speter * tests/t1/A/D/G/pi.2.tmp 200251881Speter * tests/t1/A/D/G/pi.3.tmp 201251881Speter * tests/t1/A/D/G/pi.4.tmp 202251881Speter * tests/t1/A/D/G/pi.5.tmp 203251881Speter * ... 204251881Speter * 205251881Speter * Assuming @a suffix is non-empty, @a *unique_name will never be exactly 206251881Speter * the same as @a filename, even if @a filename does not exist. 207251881Speter * 208251881Speter * If @a dirpath is NULL, then the directory returned by svn_io_temp_dir() 209251881Speter * will be used. 210251881Speter * 211251881Speter * If @a filename is NULL, then "tempfile" will be used. 212251881Speter * 213251881Speter * If @a suffix is NULL, then ".tmp" will be used. 214251881Speter * 215251881Speter * Allocates @a *file and @a *unique_name in @a result_pool. All 216251881Speter * intermediate allocations will be performed in @a scratch_pool. 217251881Speter * 218251881Speter * If no unique name can be found, #SVN_ERR_IO_UNIQUE_NAMES_EXHAUSTED is 219251881Speter * the error returned. 220251881Speter * 221251881Speter * Claim of Historical Inevitability: this function was written 222251881Speter * because 223251881Speter * 224251881Speter * - tmpnam() is not thread-safe. 225251881Speter * - tempname() tries standard system tmp areas first. 226251881Speter * 227251881Speter * @since New in 1.6 228251881Speter */ 229251881Spetersvn_error_t * 230251881Spetersvn_io_open_uniquely_named(apr_file_t **file, 231251881Speter const char **unique_name, 232251881Speter const char *dirpath, 233251881Speter const char *filename, 234251881Speter const char *suffix, 235251881Speter svn_io_file_del_t delete_when, 236251881Speter apr_pool_t *result_pool, 237251881Speter apr_pool_t *scratch_pool); 238251881Speter 239251881Speter 240251881Speter/** Create a writable file, with an arbitrary and unique name, in the 241251881Speter * directory @a dirpath. Set @a *temp_path to its full path, and set 242251881Speter * @a *file to the file handle, both allocated from @a result_pool. Either 243251881Speter * @a file or @a temp_path may be @c NULL. If @a file is @c NULL, the file 244251881Speter * will be created but not open. 245251881Speter * 246251881Speter * If @a dirpath is @c NULL, use the path returned from svn_io_temp_dir(). 247251881Speter * (Note that when using the system-provided temp directory, it may not 248251881Speter * be possible to atomically rename the resulting file due to cross-device 249251881Speter * issues.) 250251881Speter * 251251881Speter * The file will be deleted according to @a delete_when. If @a delete_when 252251881Speter * is @c svn_io_file_del_on_close and @a file is @c NULL, the file will be 253251881Speter * deleted before this function returns. 254251881Speter * 255251881Speter * When passing @c svn_io_file_del_none please don't forget to eventually 256251881Speter * remove the temporary file to avoid filling up the system temp directory. 257251881Speter * It is often appropriate to bind the lifetime of the temporary file to 258251881Speter * the lifetime of a pool by using @c svn_io_file_del_on_pool_cleanup. 259251881Speter * 260251881Speter * Temporary allocations will be performed in @a scratch_pool. 261251881Speter * 262251881Speter * @since New in 1.6 263251881Speter * @see svn_stream_open_unique() 264251881Speter */ 265251881Spetersvn_error_t * 266251881Spetersvn_io_open_unique_file3(apr_file_t **file, 267251881Speter const char **temp_path, 268251881Speter const char *dirpath, 269251881Speter svn_io_file_del_t delete_when, 270251881Speter apr_pool_t *result_pool, 271251881Speter apr_pool_t *scratch_pool); 272251881Speter 273251881Speter 274251881Speter/** Like svn_io_open_uniquely_named(), but takes a joined dirpath and 275251881Speter * filename, and a single pool. 276251881Speter * 277251881Speter * @since New in 1.4 278251881Speter * 279251881Speter * @deprecated Provided for backward compatibility with the 1.5 API 280251881Speter */ 281251881SpeterSVN_DEPRECATED 282251881Spetersvn_error_t * 283251881Spetersvn_io_open_unique_file2(apr_file_t **f, 284251881Speter const char **unique_name_p, 285251881Speter const char *path, 286251881Speter const char *suffix, 287251881Speter svn_io_file_del_t delete_when, 288251881Speter apr_pool_t *pool); 289251881Speter 290251881Speter/** Like svn_io_open_unique_file2, but can't delete on pool cleanup. 291251881Speter * 292251881Speter * @deprecated Provided for backward compatibility with the 1.3 API 293251881Speter * 294251881Speter * @note In 1.4 the API was extended to require either @a f or 295251881Speter * @a unique_name_p (the other can be NULL). Before that, both were 296251881Speter * required. 297251881Speter */ 298251881SpeterSVN_DEPRECATED 299251881Spetersvn_error_t * 300251881Spetersvn_io_open_unique_file(apr_file_t **f, 301251881Speter const char **unique_name_p, 302251881Speter const char *path, 303251881Speter const char *suffix, 304251881Speter svn_boolean_t delete_on_close, 305251881Speter apr_pool_t *pool); 306251881Speter 307251881Speter 308251881Speter/** 309251881Speter * Like svn_io_open_unique_file(), except that instead of creating a 310251881Speter * file, a symlink is generated that references the path @a dest. 311251881Speter * 312251881Speter * @since New in 1.1. 313251881Speter */ 314251881Spetersvn_error_t * 315251881Spetersvn_io_create_unique_link(const char **unique_name_p, 316251881Speter const char *path, 317251881Speter const char *dest, 318251881Speter const char *suffix, 319251881Speter apr_pool_t *pool); 320251881Speter 321251881Speter 322251881Speter/** 323251881Speter * Set @a *dest to the path that the symlink at @a path references. 324251881Speter * Allocate the string from @a pool. 325251881Speter * 326251881Speter * @since New in 1.1. 327251881Speter */ 328251881Spetersvn_error_t * 329251881Spetersvn_io_read_link(svn_string_t **dest, 330251881Speter const char *path, 331251881Speter apr_pool_t *pool); 332251881Speter 333251881Speter 334251881Speter/** Set @a *dir to a directory path (allocated in @a pool) deemed 335251881Speter * usable for the creation of temporary files and subdirectories. 336251881Speter */ 337251881Spetersvn_error_t * 338251881Spetersvn_io_temp_dir(const char **dir, 339251881Speter apr_pool_t *pool); 340251881Speter 341251881Speter 342251881Speter/** Copy @a src to @a dst atomically, in a "byte-for-byte" manner. 343251881Speter * Overwrite @a dst if it exists, else create it. Both @a src and @a dst 344251881Speter * are utf8-encoded filenames. If @a copy_perms is TRUE, set @a dst's 345251881Speter * permissions to match those of @a src. 346251881Speter */ 347251881Spetersvn_error_t * 348251881Spetersvn_io_copy_file(const char *src, 349251881Speter const char *dst, 350251881Speter svn_boolean_t copy_perms, 351251881Speter apr_pool_t *pool); 352251881Speter 353251881Speter 354251881Speter/** Copy permission flags from @a src onto the file at @a dst. Both 355251881Speter * filenames are utf8-encoded filenames. 356251881Speter * 357251881Speter * @since New in 1.6. 358251881Speter */ 359251881Spetersvn_error_t * 360251881Spetersvn_io_copy_perms(const char *src, 361251881Speter const char *dst, 362251881Speter apr_pool_t *pool); 363251881Speter 364251881Speter 365251881Speter/** 366251881Speter * Copy symbolic link @a src to @a dst atomically. Overwrite @a dst 367251881Speter * if it exists, else create it. Both @a src and @a dst are 368251881Speter * utf8-encoded filenames. After copying, the @a dst link will point 369251881Speter * to the same thing @a src does. 370251881Speter * 371251881Speter * @since New in 1.1. 372251881Speter */ 373251881Spetersvn_error_t * 374251881Spetersvn_io_copy_link(const char *src, 375251881Speter const char *dst, 376251881Speter apr_pool_t *pool); 377251881Speter 378251881Speter 379251881Speter/** Recursively copy directory @a src into @a dst_parent, as a new entry named 380251881Speter * @a dst_basename. If @a dst_basename already exists in @a dst_parent, 381251881Speter * return error. @a copy_perms will be passed through to svn_io_copy_file() 382251881Speter * when any files are copied. @a src, @a dst_parent, and @a dst_basename are 383251881Speter * all utf8-encoded. 384251881Speter * 385251881Speter * If @a cancel_func is non-NULL, invoke it with @a cancel_baton at 386251881Speter * various points during the operation. If it returns any error 387251881Speter * (typically #SVN_ERR_CANCELLED), return that error immediately. 388251881Speter */ 389251881Spetersvn_error_t * 390251881Spetersvn_io_copy_dir_recursively(const char *src, 391251881Speter const char *dst_parent, 392251881Speter const char *dst_basename, 393251881Speter svn_boolean_t copy_perms, 394251881Speter svn_cancel_func_t cancel_func, 395251881Speter void *cancel_baton, 396251881Speter apr_pool_t *pool); 397251881Speter 398251881Speter 399251881Speter/** Create directory @a path on the file system, creating intermediate 400251881Speter * directories as required, like <tt>mkdir -p</tt>. Report no error if @a 401251881Speter * path already exists. @a path is utf8-encoded. 402251881Speter * 403251881Speter * This is essentially a wrapper for apr_dir_make_recursive(), passing 404251881Speter * @c APR_OS_DEFAULT as the permissions. 405251881Speter */ 406251881Spetersvn_error_t * 407251881Spetersvn_io_make_dir_recursively(const char *path, 408251881Speter apr_pool_t *pool); 409251881Speter 410251881Speter 411251881Speter/** Set @a *is_empty_p to @c TRUE if directory @a path is empty, else to 412251881Speter * @c FALSE if it is not empty. @a path must be a directory, and is 413251881Speter * utf8-encoded. Use @a pool for temporary allocation. 414251881Speter */ 415251881Spetersvn_error_t * 416251881Spetersvn_io_dir_empty(svn_boolean_t *is_empty_p, 417251881Speter const char *path, 418251881Speter apr_pool_t *pool); 419251881Speter 420251881Speter 421251881Speter/** Append @a src to @a dst. @a dst will be appended to if it exists, else it 422251881Speter * will be created. Both @a src and @a dst are utf8-encoded. 423251881Speter */ 424251881Spetersvn_error_t * 425251881Spetersvn_io_append_file(const char *src, 426251881Speter const char *dst, 427251881Speter apr_pool_t *pool); 428251881Speter 429251881Speter 430251881Speter/** Make a file as read-only as the operating system allows. 431251881Speter * @a path is the utf8-encoded path to the file. If @a ignore_enoent is 432251881Speter * @c TRUE, don't fail if the target file doesn't exist. 433251881Speter * 434251881Speter * If @a path is a symlink, do nothing. 435251881Speter * 436251881Speter * @note If @a path is a directory, act on it as though it were a 437251881Speter * file, as described above, but note that you probably don't want to 438251881Speter * call this function on directories. We have left it effective on 439251881Speter * directories for compatibility reasons, but as its name implies, it 440251881Speter * should be used only for files. 441251881Speter */ 442251881Spetersvn_error_t * 443251881Spetersvn_io_set_file_read_only(const char *path, 444251881Speter svn_boolean_t ignore_enoent, 445251881Speter apr_pool_t *pool); 446251881Speter 447251881Speter 448251881Speter/** Make a file as writable as the operating system allows. 449251881Speter * @a path is the utf8-encoded path to the file. If @a ignore_enoent is 450251881Speter * @c TRUE, don't fail if the target file doesn't exist. 451251881Speter * @warning On Unix this function will do the equivalent of chmod a+w path. 452251881Speter * If this is not what you want you should not use this function, but rather 453251881Speter * use apr_file_perms_set(). 454251881Speter * 455251881Speter * If @a path is a symlink, do nothing. 456251881Speter * 457251881Speter * @note If @a path is a directory, act on it as though it were a 458251881Speter * file, as described above, but note that you probably don't want to 459251881Speter * call this function on directories. We have left it effective on 460251881Speter * directories for compatibility reasons, but as its name implies, it 461251881Speter * should be used only for files. 462251881Speter */ 463251881Spetersvn_error_t * 464251881Spetersvn_io_set_file_read_write(const char *path, 465251881Speter svn_boolean_t ignore_enoent, 466251881Speter apr_pool_t *pool); 467251881Speter 468251881Speter 469251881Speter/** Similar to svn_io_set_file_read_* functions. 470251881Speter * Change the read-write permissions of a file. 471251881Speter * @since New in 1.1. 472251881Speter * 473251881Speter * When making @a path read-write on operating systems with unix style 474251881Speter * permissions, set the permissions on @a path to the permissions that 475251881Speter * are set when a new file is created (effectively honoring the user's 476251881Speter * umask). 477251881Speter * 478251881Speter * When making the file read-only on operating systems with unix style 479251881Speter * permissions, remove all write permissions. 480251881Speter * 481251881Speter * On other operating systems, toggle the file's "writability" as much as 482251881Speter * the operating system allows. 483251881Speter * 484251881Speter * @a path is the utf8-encoded path to the file. If @a enable_write 485251881Speter * is @c TRUE, then make the file read-write. If @c FALSE, make it 486251881Speter * read-only. If @a ignore_enoent is @c TRUE, don't fail if the target 487251881Speter * file doesn't exist. 488251881Speter * 489251881Speter * @deprecated Provided for backward compatibility with the 1.3 API. 490251881Speter */ 491251881SpeterSVN_DEPRECATED 492251881Spetersvn_error_t * 493251881Spetersvn_io_set_file_read_write_carefully(const char *path, 494251881Speter svn_boolean_t enable_write, 495251881Speter svn_boolean_t ignore_enoent, 496251881Speter apr_pool_t *pool); 497251881Speter 498251881Speter/** Set @a path's "executability" (but do nothing if it is a symlink). 499251881Speter * 500251881Speter * @a path is the utf8-encoded path to the file. If @a executable 501251881Speter * is @c TRUE, then make the file executable. If @c FALSE, make it 502251881Speter * non-executable. If @a ignore_enoent is @c TRUE, don't fail if the target 503251881Speter * file doesn't exist. 504251881Speter * 505251881Speter * When making the file executable on operating systems with unix style 506251881Speter * permissions, never add an execute permission where there is not 507251881Speter * already a read permission: that is, only make the file executable 508251881Speter * for the user, group or world if the corresponding read permission 509251881Speter * is already set for user, group or world. 510251881Speter * 511251881Speter * When making the file non-executable on operating systems with unix style 512251881Speter * permissions, remove all execute permissions. 513251881Speter * 514251881Speter * On other operating systems, toggle the file's "executability" as much as 515251881Speter * the operating system allows. 516251881Speter * 517251881Speter * @note If @a path is a directory, act on it as though it were a 518251881Speter * file, as described above, but note that you probably don't want to 519251881Speter * call this function on directories. We have left it effective on 520251881Speter * directories for compatibility reasons, but as its name implies, it 521251881Speter * should be used only for files. 522251881Speter */ 523251881Spetersvn_error_t * 524251881Spetersvn_io_set_file_executable(const char *path, 525251881Speter svn_boolean_t executable, 526251881Speter svn_boolean_t ignore_enoent, 527251881Speter apr_pool_t *pool); 528251881Speter 529251881Speter/** Determine whether a file is executable by the current user. 530251881Speter * Set @a *executable to @c TRUE if the file @a path is executable by the 531251881Speter * current user, otherwise set it to @c FALSE. 532251881Speter * 533251881Speter * On Windows and on platforms without userids, always returns @c FALSE. 534251881Speter */ 535251881Spetersvn_error_t * 536251881Spetersvn_io_is_file_executable(svn_boolean_t *executable, 537251881Speter const char *path, 538251881Speter apr_pool_t *pool); 539251881Speter 540251881Speter 541251881Speter/** Read a line from @a file into @a buf, but not exceeding @a *limit bytes. 542251881Speter * Does not include newline, instead '\\0' is put there. 543251881Speter * Length (as in strlen) is returned in @a *limit. 544251881Speter * @a buf should be pre-allocated. 545251881Speter * @a file should be already opened. 546251881Speter * 547251881Speter * When the file is out of lines, @c APR_EOF will be returned. 548251881Speter */ 549251881Spetersvn_error_t * 550251881Spetersvn_io_read_length_line(apr_file_t *file, 551251881Speter char *buf, 552251881Speter apr_size_t *limit, 553251881Speter apr_pool_t *pool); 554251881Speter 555251881Speter 556251881Speter/** Set @a *apr_time to the time of last modification of the contents of the 557251881Speter * file @a path. @a path is utf8-encoded. 558251881Speter * 559251881Speter * @note This is the APR mtime which corresponds to the traditional mtime 560251881Speter * on Unix, and the last write time on Windows. 561251881Speter */ 562251881Spetersvn_error_t * 563251881Spetersvn_io_file_affected_time(apr_time_t *apr_time, 564251881Speter const char *path, 565251881Speter apr_pool_t *pool); 566251881Speter 567251881Speter/** Set the timestamp of file @a path to @a apr_time. @a path is 568251881Speter * utf8-encoded. 569251881Speter * 570251881Speter * @note This is the APR mtime which corresponds to the traditional mtime 571251881Speter * on Unix, and the last write time on Windows. 572251881Speter */ 573251881Spetersvn_error_t * 574251881Spetersvn_io_set_file_affected_time(apr_time_t apr_time, 575251881Speter const char *path, 576251881Speter apr_pool_t *pool); 577251881Speter 578251881Speter/** Sleep to ensure that any files modified after we exit have a different 579251881Speter * timestamp than the one we recorded. If @a path is not NULL, check if we 580251881Speter * can determine how long we should wait for a new timestamp on the filesystem 581251881Speter * containing @a path, an existing file or directory. If @a path is NULL or we 582251881Speter * can't determine the timestamp resolution, sleep until the next second. 583251881Speter * 584251881Speter * Use @a pool for any necessary allocations. @a pool can be null if @a path 585251881Speter * is NULL. 586251881Speter * 587251881Speter * Errors while retrieving the timestamp resolution will result in sleeping 588251881Speter * to the next second, to keep the working copy stable in error conditions. 589251881Speter * 590251881Speter * @since New in 1.6. 591251881Speter */ 592251881Spetervoid 593251881Spetersvn_io_sleep_for_timestamps(const char *path, apr_pool_t *pool); 594251881Speter 595251881Speter/** Set @a *different_p to TRUE if @a file1 and @a file2 have different 596251881Speter * sizes, else set to FALSE. Both @a file1 and @a file2 are utf8-encoded. 597251881Speter * 598251881Speter * Setting @a *different_p to zero does not mean the files definitely 599251881Speter * have the same size, it merely means that the sizes are not 600251881Speter * definitely different. That is, if the size of one or both files 601251881Speter * cannot be determined, then the sizes are not known to be different, 602251881Speter * so @a *different_p is set to FALSE. 603251881Speter */ 604251881Spetersvn_error_t * 605251881Spetersvn_io_filesizes_different_p(svn_boolean_t *different_p, 606251881Speter const char *file1, 607251881Speter const char *file2, 608251881Speter apr_pool_t *pool); 609251881Speter 610251881Speter/** Set @a *different_p12 to non-zero if @a file1 and @a file2 have different 611251881Speter * sizes, else set to zero. Do the similar for @a *different_p23 with 612251881Speter * @a file2 and @a file3, and @a *different_p13 for @a file1 and @a file3. 613251881Speter * The filenames @a file1, @a file2 and @a file3 are utf8-encoded. 614251881Speter * 615251881Speter * Setting @a *different_p12 to zero does not mean the files definitely 616251881Speter * have the same size, it merely means that the sizes are not 617251881Speter * definitely different. That is, if the size of one or both files 618251881Speter * cannot be determined (due to stat() returning an error), then the sizes 619251881Speter * are not known to be different, so @a *different_p12 is set to 0. 620251881Speter * 621251881Speter * @since New in 1.8. 622251881Speter */ 623251881Spetersvn_error_t * 624251881Spetersvn_io_filesizes_three_different_p(svn_boolean_t *different_p12, 625251881Speter svn_boolean_t *different_p23, 626251881Speter svn_boolean_t *different_p13, 627251881Speter const char *file1, 628251881Speter const char *file2, 629251881Speter const char *file3, 630251881Speter apr_pool_t *scratch_pool); 631251881Speter 632251881Speter/** Return in @a *checksum the checksum of type @a kind of @a file 633251881Speter * Use @a pool for temporary allocations and to allocate @a *checksum. 634251881Speter * 635251881Speter * @since New in 1.6. 636251881Speter */ 637251881Spetersvn_error_t * 638251881Spetersvn_io_file_checksum2(svn_checksum_t **checksum, 639251881Speter const char *file, 640251881Speter svn_checksum_kind_t kind, 641251881Speter apr_pool_t *pool); 642251881Speter 643251881Speter 644251881Speter/** Put the md5 checksum of @a file into @a digest. 645251881Speter * @a digest points to @c APR_MD5_DIGESTSIZE bytes of storage. 646251881Speter * Use @a pool only for temporary allocations. 647251881Speter * 648251881Speter * @deprecated Provided for backward compatibility with the 1.5 API. 649251881Speter */ 650251881SpeterSVN_DEPRECATED 651251881Spetersvn_error_t * 652251881Spetersvn_io_file_checksum(unsigned char digest[], 653251881Speter const char *file, 654251881Speter apr_pool_t *pool); 655251881Speter 656251881Speter 657251881Speter/** Set @a *same to TRUE if @a file1 and @a file2 have the same 658251881Speter * contents, else set it to FALSE. Use @a pool for temporary allocations. 659251881Speter */ 660251881Spetersvn_error_t * 661251881Spetersvn_io_files_contents_same_p(svn_boolean_t *same, 662251881Speter const char *file1, 663251881Speter const char *file2, 664251881Speter apr_pool_t *pool); 665251881Speter 666251881Speter/** Set @a *same12 to TRUE if @a file1 and @a file2 have the same 667251881Speter * contents, else set it to FALSE. Do the similar for @a *same23 668251881Speter * with @a file2 and @a file3, and @a *same13 for @a file1 and @a 669251881Speter * file3. The filenames @a file1, @a file2 and @a file3 are 670251881Speter * utf8-encoded. Use @a scratch_pool for temporary allocations. 671251881Speter * 672251881Speter * @since New in 1.8. 673251881Speter */ 674251881Spetersvn_error_t * 675251881Spetersvn_io_files_contents_three_same_p(svn_boolean_t *same12, 676251881Speter svn_boolean_t *same23, 677251881Speter svn_boolean_t *same13, 678251881Speter const char *file1, 679251881Speter const char *file2, 680251881Speter const char *file3, 681251881Speter apr_pool_t *scratch_pool); 682251881Speter 683251881Speter/** Create file at utf8-encoded @a file with contents @a contents. 684251881Speter * @a file must not already exist. 685251881Speter * Use @a pool for memory allocations. 686251881Speter */ 687251881Spetersvn_error_t * 688251881Spetersvn_io_file_create(const char *file, 689251881Speter const char *contents, 690251881Speter apr_pool_t *pool); 691251881Speter 692251881Speter/** 693251881Speter * Lock file at @a lock_file. If @a exclusive is TRUE, 694251881Speter * obtain exclusive lock, otherwise obtain shared lock. 695251881Speter * Lock will be automatically released when @a pool is cleared or destroyed. 696251881Speter * Use @a pool for memory allocations. 697251881Speter * 698251881Speter * @deprecated Provided for backward compatibility with the 1.0 API. 699251881Speter */ 700251881SpeterSVN_DEPRECATED 701251881Spetersvn_error_t * 702251881Spetersvn_io_file_lock(const char *lock_file, 703251881Speter svn_boolean_t exclusive, 704251881Speter apr_pool_t *pool); 705251881Speter 706251881Speter/** 707251881Speter * Lock file at @a lock_file. If @a exclusive is TRUE, 708251881Speter * obtain exclusive lock, otherwise obtain shared lock. 709251881Speter * 710251881Speter * If @a nonblocking is TRUE, do not wait for the lock if it 711251881Speter * is not available: throw an error instead. 712251881Speter * 713251881Speter * Lock will be automatically released when @a pool is cleared or destroyed. 714251881Speter * Use @a pool for memory allocations. 715251881Speter * 716251881Speter * @since New in 1.1. 717251881Speter */ 718251881Spetersvn_error_t * 719251881Spetersvn_io_file_lock2(const char *lock_file, 720251881Speter svn_boolean_t exclusive, 721251881Speter svn_boolean_t nonblocking, 722251881Speter apr_pool_t *pool); 723251881Speter 724251881Speter/** 725251881Speter * Lock the file @a lockfile_handle. If @a exclusive is TRUE, 726251881Speter * obtain exclusive lock, otherwise obtain shared lock. 727251881Speter * 728251881Speter * If @a nonblocking is TRUE, do not wait for the lock if it 729251881Speter * is not available: throw an error instead. 730251881Speter * 731251881Speter * Lock will be automatically released when @a pool is cleared or destroyed. 732251881Speter * You may also explicitly call svn_io_unlock_open_file(). 733251881Speter * Use @a pool for memory allocations. @a pool must be the pool that 734251881Speter * @a lockfile_handle has been created in or one of its sub-pools. 735251881Speter * 736251881Speter * @since New in 1.8. 737251881Speter */ 738251881Spetersvn_error_t * 739251881Spetersvn_io_lock_open_file(apr_file_t *lockfile_handle, 740251881Speter svn_boolean_t exclusive, 741251881Speter svn_boolean_t nonblocking, 742251881Speter apr_pool_t *pool); 743251881Speter 744251881Speter/** 745251881Speter * Unlock the file @a lockfile_handle. 746251881Speter * 747251881Speter * Use @a pool for memory allocations. @a pool must be the pool that 748251881Speter * was passed to svn_io_lock_open_file(). 749251881Speter * 750251881Speter * @since New in 1.8. 751251881Speter */ 752251881Spetersvn_error_t * 753251881Spetersvn_io_unlock_open_file(apr_file_t *lockfile_handle, 754251881Speter apr_pool_t *pool); 755251881Speter 756251881Speter/** 757251881Speter * Flush any unwritten data from @a file to disk. Use @a pool for 758251881Speter * memory allocations. 759251881Speter * 760251881Speter * @since New in 1.1. 761251881Speter */ 762251881Spetersvn_error_t * 763251881Spetersvn_io_file_flush_to_disk(apr_file_t *file, 764251881Speter apr_pool_t *pool); 765251881Speter 766251881Speter/** Copy the file whose basename (or relative path) is @a file within 767251881Speter * directory @a src_path to the same basename (or relative path) within 768251881Speter * directory @a dest_path. Overwrite the destination file if it already 769251881Speter * exists. The destination directory (including any directory 770251881Speter * components in @a name) must already exist. Set the destination 771251881Speter * file's permissions to match those of the source. Use @a pool for 772251881Speter * memory allocations. 773251881Speter */ 774251881Spetersvn_error_t * 775251881Spetersvn_io_dir_file_copy(const char *src_path, 776251881Speter const char *dest_path, 777251881Speter const char *file, 778251881Speter apr_pool_t *pool); 779251881Speter 780251881Speter 781251881Speter/** Generic byte-streams 782251881Speter * 783251881Speter * @defgroup svn_io_byte_streams Generic byte streams 784251881Speter * @{ 785251881Speter */ 786251881Speter 787251881Speter/** An abstract stream of bytes--either incoming or outgoing or both. 788251881Speter * 789251881Speter * The creator of a stream sets functions to handle read and write. 790251881Speter * Both of these handlers accept a baton whose value is determined at 791251881Speter * stream creation time; this baton can point to a structure 792251881Speter * containing data associated with the stream. If a caller attempts 793251881Speter * to invoke a handler which has not been set, it will generate a 794251881Speter * runtime assertion failure. The creator can also set a handler for 795251881Speter * close requests so that it can flush buffered data or whatever; 796251881Speter * if a close handler is not specified, a close request on the stream 797251881Speter * will simply be ignored. Note that svn_stream_close() does not 798251881Speter * deallocate the memory used to allocate the stream structure; free 799251881Speter * the pool you created the stream in to free that memory. 800251881Speter * 801251881Speter * The read and write handlers accept length arguments via pointer. 802251881Speter * On entry to the handler, the pointed-to value should be the amount 803251881Speter * of data which can be read or the amount of data to write. When the 804251881Speter * handler returns, the value is reset to the amount of data actually 805251881Speter * read or written. Handlers are obliged to complete a read or write 806251881Speter * to the maximum extent possible; thus, a short read with no 807251881Speter * associated error implies the end of the input stream, and a short 808251881Speter * write should never occur without an associated error. 809251881Speter * 810251881Speter * In Subversion 1.7 reset support was added as an optional feature of 811251881Speter * streams. If a stream implements resetting it allows reading the data 812251881Speter * again after a successful call to svn_stream_reset(). 813251881Speter */ 814251881Spetertypedef struct svn_stream_t svn_stream_t; 815251881Speter 816251881Speter 817251881Speter 818251881Speter/** Read handler function for a generic stream. @see svn_stream_t. */ 819251881Spetertypedef svn_error_t *(*svn_read_fn_t)(void *baton, 820251881Speter char *buffer, 821251881Speter apr_size_t *len); 822251881Speter 823251881Speter/** Skip data handler function for a generic stream. @see svn_stream_t 824251881Speter * and svn_stream_skip(). 825251881Speter * @since New in 1.7. 826251881Speter */ 827251881Spetertypedef svn_error_t *(*svn_stream_skip_fn_t)(void *baton, 828251881Speter apr_size_t len); 829251881Speter 830251881Speter/** Write handler function for a generic stream. @see svn_stream_t. */ 831251881Spetertypedef svn_error_t *(*svn_write_fn_t)(void *baton, 832251881Speter const char *data, 833251881Speter apr_size_t *len); 834251881Speter 835251881Speter/** Close handler function for a generic stream. @see svn_stream_t. */ 836251881Spetertypedef svn_error_t *(*svn_close_fn_t)(void *baton); 837251881Speter 838251881Speter/** An opaque type which represents a mark on a stream. There is no 839251881Speter * concrete definition of this type, it is a named type for stream 840251881Speter * implementation specific baton pointers. 841251881Speter * 842251881Speter * @see svn_stream_mark(). 843251881Speter * @since New in 1.7. 844251881Speter */ 845251881Spetertypedef struct svn_stream_mark_t svn_stream_mark_t; 846251881Speter 847251881Speter/** Mark handler function for a generic stream. @see svn_stream_t and 848251881Speter * svn_stream_mark(). 849251881Speter * 850251881Speter * @since New in 1.7. 851251881Speter */ 852251881Spetertypedef svn_error_t *(*svn_stream_mark_fn_t)(void *baton, 853251881Speter svn_stream_mark_t **mark, 854251881Speter apr_pool_t *pool); 855251881Speter 856251881Speter/** Seek handler function for a generic stream. @see svn_stream_t and 857251881Speter * svn_stream_seek(). 858251881Speter * 859251881Speter * @since New in 1.7. 860251881Speter */ 861251881Spetertypedef svn_error_t *(*svn_stream_seek_fn_t)(void *baton, 862251881Speter const svn_stream_mark_t *mark); 863251881Speter 864251881Speter/** Create a generic stream. @see svn_stream_t. */ 865251881Spetersvn_stream_t * 866251881Spetersvn_stream_create(void *baton, 867251881Speter apr_pool_t *pool); 868251881Speter 869251881Speter/** Set @a stream's baton to @a baton */ 870251881Spetervoid 871251881Spetersvn_stream_set_baton(svn_stream_t *stream, 872251881Speter void *baton); 873251881Speter 874251881Speter/** Set @a stream's read function to @a read_fn */ 875251881Spetervoid 876251881Spetersvn_stream_set_read(svn_stream_t *stream, 877251881Speter svn_read_fn_t read_fn); 878251881Speter 879251881Speter/** Set @a stream's skip function to @a skip_fn 880251881Speter * 881251881Speter * @since New in 1.7 882251881Speter */ 883251881Spetervoid 884251881Spetersvn_stream_set_skip(svn_stream_t *stream, 885251881Speter svn_stream_skip_fn_t skip_fn); 886251881Speter 887251881Speter/** Set @a stream's write function to @a write_fn */ 888251881Spetervoid 889251881Spetersvn_stream_set_write(svn_stream_t *stream, 890251881Speter svn_write_fn_t write_fn); 891251881Speter 892251881Speter/** Set @a stream's close function to @a close_fn */ 893251881Spetervoid 894251881Spetersvn_stream_set_close(svn_stream_t *stream, 895251881Speter svn_close_fn_t close_fn); 896251881Speter 897251881Speter/** Set @a stream's mark function to @a mark_fn 898251881Speter * 899251881Speter * @since New in 1.7. 900251881Speter */ 901251881Spetervoid 902251881Spetersvn_stream_set_mark(svn_stream_t *stream, 903251881Speter svn_stream_mark_fn_t mark_fn); 904251881Speter 905251881Speter/** Set @a stream's seek function to @a seek_fn 906251881Speter * 907251881Speter * @since New in 1.7. 908251881Speter */ 909251881Spetervoid 910251881Spetersvn_stream_set_seek(svn_stream_t *stream, 911251881Speter svn_stream_seek_fn_t seek_fn); 912251881Speter 913251881Speter/** Create a stream that is empty for reading and infinite for writing. */ 914251881Spetersvn_stream_t * 915251881Spetersvn_stream_empty(apr_pool_t *pool); 916251881Speter 917251881Speter/** Return a stream allocated in @a pool which forwards all requests 918251881Speter * to @a stream. Destruction is explicitly excluded from forwarding. 919251881Speter * 920251881Speter * @see notes/destruction-of-stacked-resources 921251881Speter * 922251881Speter * @since New in 1.4. 923251881Speter */ 924251881Spetersvn_stream_t * 925251881Spetersvn_stream_disown(svn_stream_t *stream, 926251881Speter apr_pool_t *pool); 927251881Speter 928251881Speter 929251881Speter/** Create a stream to read the file at @a path. It will be opened using 930251881Speter * the APR_BUFFERED and APR_BINARY flag, and APR_OS_DEFAULT for the perms. 931251881Speter * If you'd like to use different values, then open the file yourself, and 932251881Speter * use the svn_stream_from_aprfile2() interface. 933251881Speter * 934251881Speter * The stream will be returned in @a stream, and allocated from @a result_pool. 935251881Speter * Temporary allocations will be performed in @a scratch_pool. 936251881Speter * 937251881Speter * @since New in 1.6 938251881Speter */ 939251881Spetersvn_error_t * 940251881Spetersvn_stream_open_readonly(svn_stream_t **stream, 941251881Speter const char *path, 942251881Speter apr_pool_t *result_pool, 943251881Speter apr_pool_t *scratch_pool); 944251881Speter 945251881Speter 946251881Speter/** Create a stream to write a file at @a path. The file will be *created* 947251881Speter * using the APR_BUFFERED and APR_BINARY flag, and APR_OS_DEFAULT for the 948251881Speter * perms. The file will be created "exclusively", so if it already exists, 949251881Speter * then an error will be thrown. If you'd like to use different values, or 950251881Speter * open an existing file, then open the file yourself, and use the 951251881Speter * svn_stream_from_aprfile2() interface. 952251881Speter * 953251881Speter * The stream will be returned in @a stream, and allocated from @a result_pool. 954251881Speter * Temporary allocations will be performed in @a scratch_pool. 955251881Speter * 956251881Speter * @since New in 1.6 957251881Speter */ 958251881Spetersvn_error_t * 959251881Spetersvn_stream_open_writable(svn_stream_t **stream, 960251881Speter const char *path, 961251881Speter apr_pool_t *result_pool, 962251881Speter apr_pool_t *scratch_pool); 963251881Speter 964251881Speter 965251881Speter/** Create a writable stream to a file in the directory @a dirpath. 966251881Speter * The file will have an arbitrary and unique name, and the full path 967251881Speter * will be returned in @a temp_path. The stream will be returned in 968251881Speter * @a stream. Both will be allocated from @a result_pool. 969251881Speter * 970251881Speter * If @a dirpath is @c NULL, use the path returned from svn_io_temp_dir(). 971251881Speter * (Note that when using the system-provided temp directory, it may not 972251881Speter * be possible to atomically rename the resulting file due to cross-device 973251881Speter * issues.) 974251881Speter * 975251881Speter * The file will be deleted according to @a delete_when. 976251881Speter * 977251881Speter * Temporary allocations will be performed in @a scratch_pool. 978251881Speter * 979251881Speter * @since New in 1.6 980251881Speter * @see svn_io_open_unique_file3() 981251881Speter */ 982251881Spetersvn_error_t * 983251881Spetersvn_stream_open_unique(svn_stream_t **stream, 984251881Speter const char **temp_path, 985251881Speter const char *dirpath, 986251881Speter svn_io_file_del_t delete_when, 987251881Speter apr_pool_t *result_pool, 988251881Speter apr_pool_t *scratch_pool); 989251881Speter 990251881Speter 991251881Speter/** Create a stream from an APR file. For convenience, if @a file is 992251881Speter * @c NULL, an empty stream created by svn_stream_empty() is returned. 993251881Speter * 994251881Speter * This function should normally be called with @a disown set to FALSE, 995251881Speter * in which case closing the stream will also close the underlying file. 996251881Speter * 997251881Speter * If @a disown is TRUE, the stream will disown the underlying file, 998251881Speter * meaning that svn_stream_close() will not close the file. 999251881Speter * 1000251881Speter * @since New in 1.4. 1001251881Speter */ 1002251881Spetersvn_stream_t * 1003251881Spetersvn_stream_from_aprfile2(apr_file_t *file, 1004251881Speter svn_boolean_t disown, 1005251881Speter apr_pool_t *pool); 1006251881Speter 1007251881Speter/** Similar to svn_stream_from_aprfile2(), except that the file will 1008251881Speter * always be disowned. 1009251881Speter * 1010251881Speter * @note The stream returned is not considered to "own" the underlying 1011251881Speter * file, meaning that svn_stream_close() on the stream will not 1012251881Speter * close the file. 1013251881Speter * 1014251881Speter * @deprecated Provided for backward compatibility with the 1.3 API. 1015251881Speter */ 1016251881SpeterSVN_DEPRECATED 1017251881Spetersvn_stream_t * 1018251881Spetersvn_stream_from_aprfile(apr_file_t *file, 1019251881Speter apr_pool_t *pool); 1020251881Speter 1021251881Speter/** Set @a *in to a generic stream connected to stdin, allocated in 1022251881Speter * @a pool. The stream and its underlying APR handle will be closed 1023251881Speter * when @a pool is cleared or destroyed. 1024251881Speter * 1025251881Speter * @since New in 1.7. 1026251881Speter */ 1027251881Spetersvn_error_t * 1028251881Spetersvn_stream_for_stdin(svn_stream_t **in, 1029251881Speter apr_pool_t *pool); 1030251881Speter 1031251881Speter/** Set @a *err to a generic stream connected to stderr, allocated in 1032251881Speter * @a pool. The stream and its underlying APR handle will be closed 1033251881Speter * when @a pool is cleared or destroyed. 1034251881Speter * 1035251881Speter * @since New in 1.7. 1036251881Speter */ 1037251881Spetersvn_error_t * 1038251881Spetersvn_stream_for_stderr(svn_stream_t **err, 1039251881Speter apr_pool_t *pool); 1040251881Speter 1041251881Speter/** Set @a *out to a generic stream connected to stdout, allocated in 1042251881Speter * @a pool. The stream and its underlying APR handle will be closed 1043251881Speter * when @a pool is cleared or destroyed. 1044251881Speter */ 1045251881Spetersvn_error_t * 1046251881Spetersvn_stream_for_stdout(svn_stream_t **out, 1047251881Speter apr_pool_t *pool); 1048251881Speter 1049251881Speter/** Return a generic stream connected to stringbuf @a str. Allocate the 1050251881Speter * stream in @a pool. 1051251881Speter */ 1052251881Spetersvn_stream_t * 1053251881Spetersvn_stream_from_stringbuf(svn_stringbuf_t *str, 1054251881Speter apr_pool_t *pool); 1055251881Speter 1056251881Speter/** Return a generic read-only stream connected to string @a str. 1057251881Speter * Allocate the stream in @a pool. 1058251881Speter */ 1059251881Spetersvn_stream_t * 1060251881Spetersvn_stream_from_string(const svn_string_t *str, 1061251881Speter apr_pool_t *pool); 1062251881Speter 1063251881Speter/** Return a generic stream which implements buffered reads and writes. 1064251881Speter * The stream will preferentially store data in-memory, but may use 1065251881Speter * disk storage as backup if the amount of data is large. 1066251881Speter * Allocate the stream in @a result_pool 1067251881Speter * 1068251881Speter * @since New in 1.8. 1069251881Speter */ 1070251881Spetersvn_stream_t * 1071251881Spetersvn_stream_buffered(apr_pool_t *result_pool); 1072251881Speter 1073251881Speter/** Return a stream that decompresses all data read and compresses all 1074251881Speter * data written. The stream @a stream is used to read and write all 1075251881Speter * compressed data. All compression data structures are allocated on 1076251881Speter * @a pool. If compression support is not compiled in then 1077251881Speter * svn_stream_compressed() returns @a stream unmodified. Make sure you 1078251881Speter * call svn_stream_close() on the stream returned by this function, 1079251881Speter * so that all data are flushed and cleaned up. 1080251881Speter * 1081251881Speter * @note From 1.4, compression support is always compiled in. 1082251881Speter */ 1083251881Spetersvn_stream_t * 1084251881Spetersvn_stream_compressed(svn_stream_t *stream, 1085251881Speter apr_pool_t *pool); 1086251881Speter 1087251881Speter/** Return a stream that calculates checksums for all data read 1088251881Speter * and written. The stream @a stream is used to read and write all data. 1089251881Speter * The stream and the resulting digests are allocated in @a pool. 1090251881Speter * 1091251881Speter * When the stream is closed, @a *read_checksum and @a *write_checksum 1092251881Speter * are set to point to the resulting checksums, of type @a read_checksum_kind 1093251881Speter * and @a write_checksum_kind, respectively. 1094251881Speter * 1095251881Speter * Both @a read_checksum and @a write_checksum can be @c NULL, in which case 1096251881Speter * the respective checksum isn't calculated. 1097251881Speter * 1098251881Speter * If @a read_all is TRUE, make sure that all data available on @a 1099251881Speter * stream is read (and checksummed) when the stream is closed. 1100251881Speter * 1101251881Speter * Read and write operations can be mixed without interfering. 1102251881Speter * 1103251881Speter * The @a stream passed into this function is closed when the created 1104251881Speter * stream is closed. 1105251881Speter * 1106251881Speter * @since New in 1.6. 1107251881Speter */ 1108251881Spetersvn_stream_t * 1109251881Spetersvn_stream_checksummed2(svn_stream_t *stream, 1110251881Speter svn_checksum_t **read_checksum, 1111251881Speter svn_checksum_t **write_checksum, 1112251881Speter svn_checksum_kind_t checksum_kind, 1113251881Speter svn_boolean_t read_all, 1114251881Speter apr_pool_t *pool); 1115251881Speter 1116251881Speter/** 1117251881Speter * Similar to svn_stream_checksummed2(), but always returning the MD5 1118251881Speter * checksum in @a read_digest and @a write_digest. 1119251881Speter * 1120251881Speter * @since New in 1.4. 1121251881Speter * @deprecated Provided for backward compatibility with the 1.5 API. 1122251881Speter */ 1123251881SpeterSVN_DEPRECATED 1124251881Spetersvn_stream_t * 1125251881Spetersvn_stream_checksummed(svn_stream_t *stream, 1126251881Speter const unsigned char **read_digest, 1127251881Speter const unsigned char **write_digest, 1128251881Speter svn_boolean_t read_all, 1129251881Speter apr_pool_t *pool); 1130251881Speter 1131251881Speter/** Read from a generic stream. @see svn_stream_t. */ 1132251881Spetersvn_error_t * 1133251881Spetersvn_stream_read(svn_stream_t *stream, 1134251881Speter char *buffer, 1135251881Speter apr_size_t *len); 1136251881Speter 1137251881Speter/** 1138251881Speter * Skip @a len bytes from a generic @a stream. If the stream is exhausted 1139251881Speter * before @a len bytes have been read, return an error. 1140251881Speter * 1141251881Speter * @note No assumption can be made on the semantics of this function 1142251881Speter * other than that the stream read pointer will be advanced by *len 1143251881Speter * bytes. Depending on the capabilities of the underlying stream 1144251881Speter * implementation, this may for instance be translated into a sequence 1145251881Speter * of reads or a simple seek operation. If the stream implementation has 1146251881Speter * not provided a skip function, this will read from the stream and 1147251881Speter * discard the data. 1148251881Speter */ 1149251881Spetersvn_error_t * 1150251881Spetersvn_stream_skip(svn_stream_t *stream, 1151251881Speter apr_size_t len); 1152251881Speter 1153251881Speter/** Write to a generic stream. @see svn_stream_t. */ 1154251881Spetersvn_error_t * 1155251881Spetersvn_stream_write(svn_stream_t *stream, 1156251881Speter const char *data, 1157251881Speter apr_size_t *len); 1158251881Speter 1159251881Speter/** Close a generic stream. @see svn_stream_t. */ 1160251881Spetersvn_error_t * 1161251881Spetersvn_stream_close(svn_stream_t *stream); 1162251881Speter 1163251881Speter/** Reset a generic stream back to its origin. (E.g. On a file this would be 1164251881Speter * implemented as a seek to position 0). This function returns a 1165251881Speter * #SVN_ERR_STREAM_SEEK_NOT_SUPPORTED error when the stream doesn't 1166251881Speter * implement resetting. 1167251881Speter * 1168251881Speter * @since New in 1.7. 1169251881Speter */ 1170251881Spetersvn_error_t * 1171251881Spetersvn_stream_reset(svn_stream_t *stream); 1172251881Speter 1173251881Speter/** Returns @c TRUE if the generic @a stream supports svn_stream_mark(). 1174251881Speter * 1175251881Speter * @see svn_stream_mark() 1176251881Speter * @since New in 1.7. 1177251881Speter */ 1178251881Spetersvn_boolean_t 1179251881Spetersvn_stream_supports_mark(svn_stream_t *stream); 1180251881Speter 1181251881Speter/** Set a @a mark at the current position of a generic @a stream, 1182251881Speter * which can later be sought back to using svn_stream_seek(). 1183251881Speter * The @a mark is allocated in @a pool. 1184251881Speter * 1185251881Speter * This function returns the #SVN_ERR_STREAM_SEEK_NOT_SUPPORTED error 1186251881Speter * if the stream doesn't implement seeking. 1187251881Speter * 1188251881Speter * @see svn_stream_seek() 1189251881Speter * @since New in 1.7. 1190251881Speter */ 1191251881Spetersvn_error_t * 1192251881Spetersvn_stream_mark(svn_stream_t *stream, 1193251881Speter svn_stream_mark_t **mark, 1194251881Speter apr_pool_t *pool); 1195251881Speter 1196251881Speter/** Seek to a @a mark in a generic @a stream. 1197251881Speter * This function returns the #SVN_ERR_STREAM_SEEK_NOT_SUPPORTED error 1198251881Speter * if the stream doesn't implement seeking. Passing NULL as @a mark, 1199251881Speter * seeks to the start of the stream. 1200251881Speter * 1201251881Speter * @see svn_stream_mark() 1202251881Speter * @since New in 1.7. 1203251881Speter */ 1204251881Spetersvn_error_t * 1205251881Spetersvn_stream_seek(svn_stream_t *stream, const svn_stream_mark_t *mark); 1206251881Speter 1207251881Speter/** Return a writable stream which, when written to, writes to both of the 1208251881Speter * underlying streams. Both of these streams will be closed upon closure of 1209251881Speter * the returned stream; use svn_stream_disown() if this is not the desired 1210251881Speter * behavior. One or both of @a out1 and @a out2 may be @c NULL. If both are 1211251881Speter * @c NULL, @c NULL is returned. 1212251881Speter * 1213251881Speter * @since New in 1.7. 1214251881Speter */ 1215251881Spetersvn_stream_t * 1216251881Spetersvn_stream_tee(svn_stream_t *out1, 1217251881Speter svn_stream_t *out2, 1218251881Speter apr_pool_t *pool); 1219251881Speter 1220251881Speter/** Write NULL-terminated string @a str to @a stream. 1221251881Speter * 1222251881Speter * @since New in 1.8. 1223251881Speter * 1224251881Speter */ 1225251881Spetersvn_error_t * 1226251881Spetersvn_stream_puts(svn_stream_t *stream, 1227251881Speter const char *str); 1228251881Speter 1229251881Speter/** Write to @a stream using a printf-style @a fmt specifier, passed through 1230251881Speter * apr_psprintf() using memory from @a pool. 1231251881Speter */ 1232251881Spetersvn_error_t * 1233251881Spetersvn_stream_printf(svn_stream_t *stream, 1234251881Speter apr_pool_t *pool, 1235251881Speter const char *fmt, 1236251881Speter ...) 1237251881Speter __attribute__((format(printf, 3, 4))); 1238251881Speter 1239251881Speter/** Write to @a stream using a printf-style @a fmt specifier, passed through 1240251881Speter * apr_psprintf() using memory from @a pool. The resulting string 1241251881Speter * will be translated to @a encoding before it is sent to @a stream. 1242251881Speter * 1243251881Speter * @note Use @c APR_LOCALE_CHARSET to translate to the encoding of the 1244251881Speter * current locale. 1245251881Speter * 1246251881Speter * @since New in 1.3. 1247251881Speter */ 1248251881Spetersvn_error_t * 1249251881Spetersvn_stream_printf_from_utf8(svn_stream_t *stream, 1250251881Speter const char *encoding, 1251251881Speter apr_pool_t *pool, 1252251881Speter const char *fmt, 1253251881Speter ...) 1254251881Speter __attribute__((format(printf, 4, 5))); 1255251881Speter 1256251881Speter/** Allocate @a *stringbuf in @a pool, and read into it one line (terminated 1257251881Speter * by @a eol) from @a stream. The line-terminator is read from the stream, 1258251881Speter * but is not added to the end of the stringbuf. Instead, the stringbuf 1259251881Speter * ends with a usual '\\0'. 1260251881Speter * 1261251881Speter * If @a stream runs out of bytes before encountering a line-terminator, 1262251881Speter * then set @a *eof to @c TRUE, otherwise set @a *eof to FALSE. 1263251881Speter */ 1264251881Spetersvn_error_t * 1265251881Spetersvn_stream_readline(svn_stream_t *stream, 1266251881Speter svn_stringbuf_t **stringbuf, 1267251881Speter const char *eol, 1268251881Speter svn_boolean_t *eof, 1269251881Speter apr_pool_t *pool); 1270251881Speter 1271251881Speter/** 1272251881Speter * Read the contents of the readable stream @a from and write them to the 1273251881Speter * writable stream @a to calling @a cancel_func before copying each chunk. 1274251881Speter * 1275251881Speter * @a cancel_func may be @c NULL. 1276251881Speter * 1277251881Speter * @note both @a from and @a to will be closed upon successful completion of 1278251881Speter * the copy (but an error may still be returned, based on trying to close 1279251881Speter * the two streams). If the closure is not desired, then you can use 1280251881Speter * svn_stream_disown() to protect either or both of the streams from 1281251881Speter * being closed. 1282251881Speter * 1283251881Speter * @since New in 1.6. 1284251881Speter */ 1285251881Spetersvn_error_t * 1286251881Spetersvn_stream_copy3(svn_stream_t *from, 1287251881Speter svn_stream_t *to, 1288251881Speter svn_cancel_func_t cancel_func, 1289251881Speter void *cancel_baton, 1290251881Speter apr_pool_t *pool); 1291251881Speter 1292251881Speter/** 1293251881Speter * Same as svn_stream_copy3() but the streams are not closed. 1294251881Speter * 1295251881Speter * @since New in 1.5. 1296251881Speter * @deprecated Provided for backward compatibility with the 1.5 API. 1297251881Speter */ 1298251881SpeterSVN_DEPRECATED 1299251881Spetersvn_error_t * 1300251881Spetersvn_stream_copy2(svn_stream_t *from, 1301251881Speter svn_stream_t *to, 1302251881Speter svn_cancel_func_t cancel_func, 1303251881Speter void *cancel_baton, 1304251881Speter apr_pool_t *pool); 1305251881Speter 1306251881Speter/** 1307251881Speter * Same as svn_stream_copy3(), but without the cancellation function 1308251881Speter * or stream closing. 1309251881Speter * 1310251881Speter * @since New in 1.1. 1311251881Speter * @deprecated Provided for backward compatibility with the 1.4 API. 1312251881Speter */ 1313251881SpeterSVN_DEPRECATED 1314251881Spetersvn_error_t * 1315251881Spetersvn_stream_copy(svn_stream_t *from, 1316251881Speter svn_stream_t *to, 1317251881Speter apr_pool_t *pool); 1318251881Speter 1319251881Speter 1320251881Speter/** Set @a *same to TRUE if @a stream1 and @a stream2 have the same 1321251881Speter * contents, else set it to FALSE. 1322251881Speter * 1323251881Speter * Both streams will be closed before this function returns (regardless of 1324251881Speter * the result, or any possible error). 1325251881Speter * 1326251881Speter * Use @a scratch_pool for temporary allocations. 1327251881Speter * 1328251881Speter * @since New in 1.7. 1329251881Speter */ 1330251881Spetersvn_error_t * 1331251881Spetersvn_stream_contents_same2(svn_boolean_t *same, 1332251881Speter svn_stream_t *stream1, 1333251881Speter svn_stream_t *stream2, 1334251881Speter apr_pool_t *pool); 1335251881Speter 1336251881Speter 1337251881Speter/** 1338251881Speter * Same as svn_stream_contents_same2(), but the streams will not be closed. 1339251881Speter * 1340251881Speter * @since New in 1.4. 1341251881Speter * @deprecated Provided for backward compatibility with the 1.6 API. 1342251881Speter */ 1343251881SpeterSVN_DEPRECATED 1344251881Spetersvn_error_t * 1345251881Spetersvn_stream_contents_same(svn_boolean_t *same, 1346251881Speter svn_stream_t *stream1, 1347251881Speter svn_stream_t *stream2, 1348251881Speter apr_pool_t *pool); 1349251881Speter 1350251881Speter 1351251881Speter/** Read the contents of @a stream into memory, returning the data in 1352251881Speter * @a result. The stream will be closed when it has been successfully and 1353251881Speter * completely read. 1354251881Speter * 1355251881Speter * The returned memory is allocated in @a result_pool, and any temporary 1356251881Speter * allocations are performed in @a scratch_pool. 1357251881Speter * 1358251881Speter * @note due to memory pseudo-reallocation behavior (due to pools), this 1359251881Speter * can be a memory-intensive operation for large files. 1360251881Speter * 1361251881Speter * @since New in 1.6 1362251881Speter */ 1363251881Spetersvn_error_t * 1364251881Spetersvn_string_from_stream(svn_string_t **result, 1365251881Speter svn_stream_t *stream, 1366251881Speter apr_pool_t *result_pool, 1367251881Speter apr_pool_t *scratch_pool); 1368251881Speter 1369251881Speter 1370251881Speter/** A function type provided for use as a callback from 1371251881Speter * @c svn_stream_lazyopen_create(). 1372251881Speter * 1373251881Speter * The callback function shall open a new stream and set @a *stream to 1374251881Speter * the stream object, allocated in @a result_pool. @a baton is the 1375251881Speter * callback baton that was passed to svn_stream_lazyopen_create(). 1376251881Speter * 1377251881Speter * @a result_pool is the result pool that was passed to 1378251881Speter * svn_stream_lazyopen_create(). The callback function may use 1379251881Speter * @a scratch_pool for temporary allocations; the caller may clear or 1380251881Speter * destroy @a scratch_pool any time after the function returns. 1381251881Speter * 1382251881Speter * @since New in 1.8. 1383251881Speter */ 1384251881Spetertypedef svn_error_t * 1385251881Speter(*svn_stream_lazyopen_func_t)(svn_stream_t **stream, 1386251881Speter void *baton, 1387251881Speter apr_pool_t *result_pool, 1388251881Speter apr_pool_t *scratch_pool); 1389251881Speter 1390251881Speter 1391251881Speter/** Return a generic stream which wraps another primary stream, 1392251881Speter * delaying the "opening" of that stream until the first time the 1393251881Speter * returned stream is accessed. 1394251881Speter * 1395251881Speter * @a open_func and @a open_baton are a callback function/baton pair 1396251881Speter * which will be invoked upon the first access of the returned 1397251881Speter * stream (read, write, mark, seek, skip, or possibly close). The 1398251881Speter * callback shall open the primary stream. 1399251881Speter * 1400251881Speter * If the only "access" the returned stream gets is to close it 1401251881Speter * then @a open_func will only be called if @a open_on_close is TRUE. 1402251881Speter * 1403251881Speter * @since New in 1.8. 1404251881Speter */ 1405251881Spetersvn_stream_t * 1406251881Spetersvn_stream_lazyopen_create(svn_stream_lazyopen_func_t open_func, 1407251881Speter void *open_baton, 1408251881Speter svn_boolean_t open_on_close, 1409251881Speter apr_pool_t *result_pool); 1410251881Speter 1411251881Speter/** @} */ 1412251881Speter 1413251881Speter/** Set @a *result to a string containing the contents of @a 1414251881Speter * filename, which is either "-" (indicating that stdin should be 1415251881Speter * read) or the utf8-encoded path of a real file. 1416251881Speter * 1417251881Speter * @warning Callers should be aware of possible unexpected results 1418251881Speter * when using this function to read from stdin where additional 1419251881Speter * stdin-reading processes abound. For example, if a program tries 1420251881Speter * both to invoke an external editor and to read from stdin, stdin 1421251881Speter * could be trashed and the editor might act funky or die outright. 1422251881Speter * 1423251881Speter * @note due to memory pseudo-reallocation behavior (due to pools), this 1424251881Speter * can be a memory-intensive operation for large files. 1425251881Speter * 1426251881Speter * @since New in 1.5. 1427251881Speter */ 1428251881Spetersvn_error_t * 1429251881Spetersvn_stringbuf_from_file2(svn_stringbuf_t **result, 1430251881Speter const char *filename, 1431251881Speter apr_pool_t *pool); 1432251881Speter 1433251881Speter/** Similar to svn_stringbuf_from_file2(), except that if @a filename 1434251881Speter * is "-", return the error #SVN_ERR_UNSUPPORTED_FEATURE and don't 1435251881Speter * touch @a *result. 1436251881Speter * 1437251881Speter * @deprecated Provided for backwards compatibility with the 1.4 API. 1438251881Speter */ 1439251881SpeterSVN_DEPRECATED 1440251881Spetersvn_error_t * 1441251881Spetersvn_stringbuf_from_file(svn_stringbuf_t **result, 1442251881Speter const char *filename, 1443251881Speter apr_pool_t *pool); 1444251881Speter 1445251881Speter/** Sets @a *result to a string containing the contents of the already opened 1446251881Speter * @a file. Reads from the current position in file to the end. Does not 1447251881Speter * close the file or reset the cursor position. 1448251881Speter * 1449251881Speter * @note due to memory pseudo-reallocation behavior (due to pools), this 1450251881Speter * can be a memory-intensive operation for large files. 1451251881Speter */ 1452251881Spetersvn_error_t * 1453251881Spetersvn_stringbuf_from_aprfile(svn_stringbuf_t **result, 1454251881Speter apr_file_t *file, 1455251881Speter apr_pool_t *pool); 1456251881Speter 1457251881Speter/** Remove file @a path, a utf8-encoded path. This wraps apr_file_remove(), 1458251881Speter * converting any error to a Subversion error. If @a ignore_enoent is TRUE, and 1459251881Speter * the file is not present (APR_STATUS_IS_ENOENT returns TRUE), then no 1460251881Speter * error will be returned. 1461251881Speter * 1462251881Speter * The file will be removed even if it is not writable. (On Windows and 1463251881Speter * OS/2, this function first clears the file's read-only bit.) 1464251881Speter * 1465251881Speter * @since New in 1.7. 1466251881Speter */ 1467251881Spetersvn_error_t * 1468251881Spetersvn_io_remove_file2(const char *path, 1469251881Speter svn_boolean_t ignore_enoent, 1470251881Speter apr_pool_t *scratch_pool); 1471251881Speter 1472251881Speter/** Similar to svn_io_remove_file2(), except with @a ignore_enoent set to FALSE. 1473251881Speter * 1474251881Speter * @deprecated Provided for backwards compatibility with the 1.6 API. 1475251881Speter */ 1476251881SpeterSVN_DEPRECATED 1477251881Spetersvn_error_t * 1478251881Spetersvn_io_remove_file(const char *path, 1479251881Speter apr_pool_t *pool); 1480251881Speter 1481251881Speter/** Recursively remove directory @a path. @a path is utf8-encoded. 1482251881Speter * If @a ignore_enoent is @c TRUE, don't fail if the target directory 1483251881Speter * doesn't exist. Use @a pool for temporary allocations. 1484251881Speter * 1485251881Speter * Because recursive delete of a directory tree can be a lengthy operation, 1486251881Speter * provide @a cancel_func and @a cancel_baton for interruptibility. 1487251881Speter * 1488251881Speter * @since New in 1.5. 1489251881Speter */ 1490251881Spetersvn_error_t * 1491251881Spetersvn_io_remove_dir2(const char *path, 1492251881Speter svn_boolean_t ignore_enoent, 1493251881Speter svn_cancel_func_t cancel_func, 1494251881Speter void *cancel_baton, 1495251881Speter apr_pool_t *pool); 1496251881Speter 1497251881Speter/** Similar to svn_io_remove_dir2(), but with @a ignore_enoent set to 1498251881Speter * @c FALSE and @a cancel_func and @a cancel_baton set to @c NULL. 1499251881Speter * 1500251881Speter * @deprecated Provided for backward compatibility with the 1.4 API 1501251881Speter */ 1502251881SpeterSVN_DEPRECATED 1503251881Spetersvn_error_t * 1504251881Spetersvn_io_remove_dir(const char *path, 1505251881Speter apr_pool_t *pool); 1506251881Speter 1507251881Speter/** Read all of the disk entries in directory @a path, a utf8-encoded 1508251881Speter * path. Set @a *dirents to a hash mapping dirent names (<tt>char *</tt>) to 1509251881Speter * undefined non-NULL values, allocated in @a pool. 1510251881Speter * 1511251881Speter * @note The `.' and `..' directories normally returned by 1512251881Speter * apr_dir_read() are NOT returned in the hash. 1513251881Speter * 1514251881Speter * @since New in 1.4. 1515251881Speter * @deprecated Provided for backward compatibility with the 1.6 API. 1516251881Speter */ 1517251881SpeterSVN_DEPRECATED 1518251881Spetersvn_error_t * 1519251881Spetersvn_io_get_dir_filenames(apr_hash_t **dirents, 1520251881Speter const char *path, 1521251881Speter apr_pool_t *pool); 1522251881Speter 1523251881Speter/** Read all of the disk entries in directory @a path, a utf8-encoded 1524251881Speter * path. Set @a *dirents to a hash mapping dirent names (<tt>char *</tt>) to 1525251881Speter * #svn_io_dirent2_t structures, allocated in @a pool. 1526251881Speter * 1527251881Speter * If @a only_check_type is set to @c TRUE, only the kind and special 1528251881Speter * fields of the svn_io_dirent2_t are filled. 1529251881Speter * 1530251881Speter * @note The `.' and `..' directories normally returned by 1531251881Speter * apr_dir_read() are NOT returned in the hash. 1532251881Speter * 1533251881Speter * @note The kind field in the @a dirents is set according to the mapping 1534251881Speter * as documented for svn_io_check_path(). 1535251881Speter * 1536251881Speter * @since New in 1.7. 1537251881Speter */ 1538251881Spetersvn_error_t * 1539251881Spetersvn_io_get_dirents3(apr_hash_t **dirents, 1540251881Speter const char *path, 1541251881Speter svn_boolean_t only_check_type, 1542251881Speter apr_pool_t *result_pool, 1543251881Speter apr_pool_t *scratch_pool); 1544251881Speter 1545251881Speter 1546251881Speter/** Similar to svn_io_get_dirents3, but returns a mapping to svn_io_dirent_t 1547251881Speter * structures instead of svn_io_dirent2_t and with only a single pool. 1548251881Speter * 1549251881Speter * @since New in 1.3. 1550251881Speter * @deprecated Provided for backward compatibility with the 1.6 API. 1551251881Speter */ 1552251881SpeterSVN_DEPRECATED 1553251881Spetersvn_error_t * 1554251881Spetersvn_io_get_dirents2(apr_hash_t **dirents, 1555251881Speter const char *path, 1556251881Speter apr_pool_t *pool); 1557251881Speter 1558251881Speter/** Similar to svn_io_get_dirents2(), but @a *dirents is a hash table 1559251881Speter * with #svn_node_kind_t values. 1560251881Speter * 1561251881Speter * @deprecated Provided for backwards compatibility with the 1.2 API. 1562251881Speter */ 1563251881SpeterSVN_DEPRECATED 1564251881Spetersvn_error_t * 1565251881Spetersvn_io_get_dirents(apr_hash_t **dirents, 1566251881Speter const char *path, 1567251881Speter apr_pool_t *pool); 1568251881Speter 1569251881Speter/** Create a svn_io_dirent2_t instance for path. Specialized variant of 1570251881Speter * svn_io_stat() that directly translates node_kind and special. 1571251881Speter * 1572251881Speter * If @a verify_truename is @c TRUE, an additional check is performed to 1573251881Speter * verify the truename of the last path component on case insensitive 1574251881Speter * filesystems. This check is expensive compared to a just a stat, 1575251881Speter * but certainly cheaper than a full truename calculation using 1576251881Speter * apr_filepath_merge() which verifies all path components. 1577251881Speter * 1578251881Speter * If @a ignore_enoent is set to @c TRUE, set *dirent_p->kind to 1579251881Speter * svn_node_none instead of returning an error. 1580251881Speter * 1581251881Speter * @since New in 1.8. 1582251881Speter */ 1583251881Spetersvn_error_t * 1584251881Spetersvn_io_stat_dirent2(const svn_io_dirent2_t **dirent_p, 1585251881Speter const char *path, 1586251881Speter svn_boolean_t verify_truename, 1587251881Speter svn_boolean_t ignore_enoent, 1588251881Speter apr_pool_t *result_pool, 1589251881Speter apr_pool_t *scratch_pool); 1590251881Speter 1591251881Speter 1592251881Speter/** Similar to svn_io_stat_dirent2, but always passes FALSE for 1593251881Speter * verify_truename. 1594251881Speter * 1595251881Speter * @since New in 1.7. 1596251881Speter * @deprecated Provided for backwards compatibility with the 1.7 API. 1597251881Speter */ 1598251881SpeterSVN_DEPRECATED 1599251881Spetersvn_error_t * 1600251881Spetersvn_io_stat_dirent(const svn_io_dirent2_t **dirent_p, 1601251881Speter const char *path, 1602251881Speter svn_boolean_t ignore_enoent, 1603251881Speter apr_pool_t *result_pool, 1604251881Speter apr_pool_t *scratch_pool); 1605251881Speter 1606251881Speter 1607251881Speter/** Callback function type for svn_io_dir_walk() */ 1608251881Spetertypedef svn_error_t * (*svn_io_walk_func_t)(void *baton, 1609251881Speter const char *path, 1610251881Speter const apr_finfo_t *finfo, 1611251881Speter apr_pool_t *pool); 1612251881Speter 1613251881Speter/** Recursively walk the directory rooted at @a dirname, a 1614251881Speter * utf8-encoded path, invoking @a walk_func (with @a walk_baton) for 1615251881Speter * each item in the tree. For a given directory, invoke @a walk_func 1616251881Speter * on the directory itself before invoking it on any children thereof. 1617251881Speter * 1618251881Speter * Deliver to @a walk_func the information specified by @a wanted, 1619251881Speter * which is a combination of @c APR_FINFO_* flags, plus the 1620251881Speter * information specified by @c APR_FINFO_TYPE and @c APR_FINFO_NAME. 1621251881Speter * 1622251881Speter * Use @a pool for all allocations. 1623251881Speter * 1624251881Speter * @note This function does not currently pass all file types to @a 1625251881Speter * walk_func -- only APR_DIR, APR_REG, and APR_LNK. We reserve the 1626251881Speter * right to pass additional file types through this interface in the 1627251881Speter * future, though, so implementations of this callback should 1628251881Speter * explicitly test FINFO->filetype. See the APR library's 1629251881Speter * apr_filetype_e enum for the various filetypes and their meanings. 1630251881Speter * 1631251881Speter * @since New in 1.7. 1632251881Speter */ 1633251881Spetersvn_error_t * 1634251881Spetersvn_io_dir_walk2(const char *dirname, 1635251881Speter apr_int32_t wanted, 1636251881Speter svn_io_walk_func_t walk_func, 1637251881Speter void *walk_baton, 1638251881Speter apr_pool_t *pool); 1639251881Speter 1640251881Speter/** Similar to svn_io_dir_walk(), but only calls @a walk_func for 1641251881Speter * files of type APR_DIR (directory) and APR_REG (regular file). 1642251881Speter * 1643251881Speter * @deprecated Provided for backwards compatibility with the 1.6 API. 1644251881Speter */ 1645251881SpeterSVN_DEPRECATED 1646251881Spetersvn_error_t * 1647251881Spetersvn_io_dir_walk(const char *dirname, 1648251881Speter apr_int32_t wanted, 1649251881Speter svn_io_walk_func_t walk_func, 1650251881Speter void *walk_baton, 1651251881Speter apr_pool_t *pool); 1652251881Speter 1653251881Speter/** 1654251881Speter * Start @a cmd with @a args, using utf8-encoded @a path as working 1655251881Speter * directory. Return the process handle for the invoked program in @a 1656251881Speter * *cmd_proc. 1657251881Speter * 1658251881Speter * If @a infile_pipe is TRUE, connect @a cmd's stdin to a pipe; 1659251881Speter * otherwise, connect it to @a infile (which may be NULL). If 1660251881Speter * @a outfile_pipe is TRUE, connect @a cmd's stdout to a pipe; otherwise, 1661251881Speter * connect it to @a outfile (which may be NULL). If @a errfile_pipe 1662251881Speter * is TRUE, connect @a cmd's stderr to a pipe; otherwise, connect it 1663251881Speter * to @a errfile (which may be NULL). (Callers must pass FALSE for 1664251881Speter * each of these boolean values for which the corresponding file 1665251881Speter * handle is non-NULL.) 1666251881Speter * 1667251881Speter * @a args is a list of utf8-encoded <tt>const char *</tt> arguments, 1668251881Speter * terminated by @c NULL. @a args[0] is the name of the program, though it 1669251881Speter * need not be the same as @a cmd. 1670251881Speter * 1671251881Speter * If @a inherit is TRUE, the invoked program inherits its environment from 1672251881Speter * the caller and @a cmd, if not absolute, is searched for in PATH. 1673251881Speter * 1674251881Speter * If @a inherit is FALSE @a cmd must be an absolute path and the invoked 1675251881Speter * program inherits the environment defined by @a env or runs with an empty 1676251881Speter * environment in @a env is NULL. 1677251881Speter * 1678251881Speter * @note On some platforms, failure to execute @a cmd in the child process 1679251881Speter * will result in error output being written to @a errfile, if non-NULL, and 1680251881Speter * a non-zero exit status being returned to the parent process. 1681251881Speter * 1682251881Speter * @note An APR bug affects Windows: passing a NULL @a env does not 1683251881Speter * guarantee the invoked program to run with an empty environment when 1684251881Speter * @a inherits is FALSE, the program may inherit its parent's environment. 1685251881Speter * Explicitly pass an empty @a env to get an empty environment. 1686251881Speter * 1687251881Speter * @since New in 1.8. 1688251881Speter */ 1689251881Spetersvn_error_t *svn_io_start_cmd3(apr_proc_t *cmd_proc, 1690251881Speter const char *path, 1691251881Speter const char *cmd, 1692251881Speter const char *const *args, 1693251881Speter const char *const *env, 1694251881Speter svn_boolean_t inherit, 1695251881Speter svn_boolean_t infile_pipe, 1696251881Speter apr_file_t *infile, 1697251881Speter svn_boolean_t outfile_pipe, 1698251881Speter apr_file_t *outfile, 1699251881Speter svn_boolean_t errfile_pipe, 1700251881Speter apr_file_t *errfile, 1701251881Speter apr_pool_t *pool); 1702251881Speter 1703251881Speter 1704251881Speter/** 1705251881Speter * Similar to svn_io_start_cmd3() but with @a env always set to NULL. 1706251881Speter * 1707251881Speter * @deprecated Provided for backward compatibility with the 1.7 API 1708251881Speter * @since New in 1.7. 1709251881Speter */ 1710251881SpeterSVN_DEPRECATED 1711251881Spetersvn_error_t *svn_io_start_cmd2(apr_proc_t *cmd_proc, 1712251881Speter const char *path, 1713251881Speter const char *cmd, 1714251881Speter const char *const *args, 1715251881Speter svn_boolean_t inherit, 1716251881Speter svn_boolean_t infile_pipe, 1717251881Speter apr_file_t *infile, 1718251881Speter svn_boolean_t outfile_pipe, 1719251881Speter apr_file_t *outfile, 1720251881Speter svn_boolean_t errfile_pipe, 1721251881Speter apr_file_t *errfile, 1722251881Speter apr_pool_t *pool); 1723251881Speter 1724251881Speter/** 1725251881Speter * Similar to svn_io_start_cmd2() but with @a infile_pipe, @a 1726251881Speter * outfile_pipe, and @a errfile_pipe always FALSE. 1727251881Speter * 1728251881Speter * @deprecated Provided for backward compatibility with the 1.6 API 1729251881Speter * @since New in 1.3. 1730251881Speter */ 1731251881SpeterSVN_DEPRECATED 1732251881Spetersvn_error_t * 1733251881Spetersvn_io_start_cmd(apr_proc_t *cmd_proc, 1734251881Speter const char *path, 1735251881Speter const char *cmd, 1736251881Speter const char *const *args, 1737251881Speter svn_boolean_t inherit, 1738251881Speter apr_file_t *infile, 1739251881Speter apr_file_t *outfile, 1740251881Speter apr_file_t *errfile, 1741251881Speter apr_pool_t *pool); 1742251881Speter 1743251881Speter/** 1744251881Speter * Wait for the process @a *cmd_proc to complete and optionally retrieve 1745251881Speter * its exit code. @a cmd is used only in error messages. 1746251881Speter * 1747251881Speter * If @a exitcode is not NULL, set @a *exitcode to the exit code of the 1748251881Speter * process and do not consider any exit code to be an error. If @a exitcode 1749251881Speter * is NULL, then if the exit code of the process is non-zero then return an 1750251881Speter * #SVN_ERR_EXTERNAL_PROGRAM error. 1751251881Speter * 1752251881Speter * If @a exitwhy is not NULL, set @a *exitwhy to indicate why the process 1753251881Speter * terminated and do not consider any reason to be an error. If @a exitwhy 1754251881Speter * is NULL, then if the termination reason is not @c APR_PROC_CHECK_EXIT() 1755251881Speter * then return an #SVN_ERR_EXTERNAL_PROGRAM error. 1756251881Speter * 1757251881Speter * @since New in 1.3. 1758251881Speter */ 1759251881Spetersvn_error_t * 1760251881Spetersvn_io_wait_for_cmd(apr_proc_t *cmd_proc, 1761251881Speter const char *cmd, 1762251881Speter int *exitcode, 1763251881Speter apr_exit_why_e *exitwhy, 1764251881Speter apr_pool_t *pool); 1765251881Speter 1766251881Speter/** Run a command to completion, by first calling svn_io_start_cmd() and 1767251881Speter * then calling svn_io_wait_for_cmd(). The parameters correspond to 1768251881Speter * the same-named parameters of those two functions. 1769251881Speter */ 1770251881Spetersvn_error_t * 1771251881Spetersvn_io_run_cmd(const char *path, 1772251881Speter const char *cmd, 1773251881Speter const char *const *args, 1774251881Speter int *exitcode, 1775251881Speter apr_exit_why_e *exitwhy, 1776251881Speter svn_boolean_t inherit, 1777251881Speter apr_file_t *infile, 1778251881Speter apr_file_t *outfile, 1779251881Speter apr_file_t *errfile, 1780251881Speter apr_pool_t *pool); 1781251881Speter 1782251881Speter/** Invoke the configured @c diff program, with @a user_args (an array 1783251881Speter * of utf8-encoded @a num_user_args arguments) if they are specified 1784251881Speter * (that is, if @a user_args is non-NULL), or "-u" if they are not. 1785251881Speter * If @a user_args is NULL, the value of @a num_user_args is ignored. 1786251881Speter * 1787251881Speter * Diff runs in utf8-encoded @a dir, and its exit status is stored in 1788251881Speter * @a exitcode, if it is not @c NULL. 1789251881Speter * 1790251881Speter * If @a label1 and/or @a label2 are not NULL they will be passed to the diff 1791251881Speter * process as the arguments of "-L" options. @a label1 and @a label2 are also 1792251881Speter * in utf8, and will be converted to native charset along with the other args. 1793251881Speter * 1794251881Speter * @a from is the first file passed to diff, and @a to is the second. The 1795251881Speter * stdout of diff will be sent to @a outfile, and the stderr to @a errfile. 1796251881Speter * 1797251881Speter * @a diff_cmd must be non-NULL. 1798251881Speter * 1799251881Speter * Do all allocation in @a pool. 1800251881Speter * @since New in 1.6.0. 1801251881Speter */ 1802251881Spetersvn_error_t * 1803251881Spetersvn_io_run_diff2(const char *dir, 1804251881Speter const char *const *user_args, 1805251881Speter int num_user_args, 1806251881Speter const char *label1, 1807251881Speter const char *label2, 1808251881Speter const char *from, 1809251881Speter const char *to, 1810251881Speter int *exitcode, 1811251881Speter apr_file_t *outfile, 1812251881Speter apr_file_t *errfile, 1813251881Speter const char *diff_cmd, 1814251881Speter apr_pool_t *pool); 1815251881Speter 1816251881Speter/** Similar to svn_io_run_diff2() but with @a diff_cmd encoded in internal 1817251881Speter * encoding used by APR. 1818251881Speter * 1819251881Speter * @deprecated Provided for backwards compatibility with the 1.5 API. */ 1820251881SpeterSVN_DEPRECATED 1821251881Spetersvn_error_t * 1822251881Spetersvn_io_run_diff(const char *dir, 1823251881Speter const char *const *user_args, 1824251881Speter int num_user_args, 1825251881Speter const char *label1, 1826251881Speter const char *label2, 1827251881Speter const char *from, 1828251881Speter const char *to, 1829251881Speter int *exitcode, 1830251881Speter apr_file_t *outfile, 1831251881Speter apr_file_t *errfile, 1832251881Speter const char *diff_cmd, 1833251881Speter apr_pool_t *pool); 1834251881Speter 1835251881Speter 1836251881Speter 1837251881Speter/** Invoke the configured @c diff3 program, in utf8-encoded @a dir 1838251881Speter * like this: 1839251881Speter * 1840251881Speter * diff3 -E -m @a mine @a older @a yours > @a merged 1841251881Speter * 1842251881Speter * (See the diff3 documentation for details.) 1843251881Speter * 1844251881Speter * If @a user_args is non-NULL, replace "-E" with the <tt>const char*</tt> 1845251881Speter * elements that @a user_args contains. 1846251881Speter * 1847251881Speter * @a mine, @a older and @a yours are utf8-encoded paths (relative to 1848251881Speter * @a dir or absolute) to three files that already exist. 1849251881Speter * 1850251881Speter * @a merged is an open file handle, and is left open after the merge 1851251881Speter * result is written to it. (@a merged should *not* be the same file 1852251881Speter * as @a mine, or nondeterministic things may happen!) 1853251881Speter * 1854251881Speter * @a mine_label, @a older_label, @a yours_label are utf8-encoded label 1855251881Speter * parameters for diff3's -L option. Any of them may be @c NULL, in 1856251881Speter * which case the corresponding @a mine, @a older, or @a yours parameter is 1857251881Speter * used instead. 1858251881Speter * 1859251881Speter * Set @a *exitcode to diff3's exit status. If @a *exitcode is anything 1860251881Speter * other than 0 or 1, then return #SVN_ERR_EXTERNAL_PROGRAM. (Note the 1861251881Speter * following from the diff3 info pages: "An exit status of 0 means 1862251881Speter * `diff3' was successful, 1 means some conflicts were found, and 2 1863251881Speter * means trouble.") 1864251881Speter * 1865251881Speter * @a diff3_cmd must be non-NULL. 1866251881Speter * 1867251881Speter * Do all allocation in @a pool. 1868251881Speter * 1869251881Speter * @since New in 1.4. 1870251881Speter */ 1871251881Spetersvn_error_t * 1872251881Spetersvn_io_run_diff3_3(int *exitcode, 1873251881Speter const char *dir, 1874251881Speter const char *mine, 1875251881Speter const char *older, 1876251881Speter const char *yours, 1877251881Speter const char *mine_label, 1878251881Speter const char *older_label, 1879251881Speter const char *yours_label, 1880251881Speter apr_file_t *merged, 1881251881Speter const char *diff3_cmd, 1882251881Speter const apr_array_header_t *user_args, 1883251881Speter apr_pool_t *pool); 1884251881Speter 1885251881Speter/** Similar to svn_io_run_diff3_3(), but with @a diff3_cmd encoded in 1886251881Speter * internal encoding used by APR. 1887251881Speter * 1888251881Speter * @deprecated Provided for backwards compatibility with the 1.5 API. 1889251881Speter * @since New in 1.4. 1890251881Speter */ 1891251881SpeterSVN_DEPRECATED 1892251881Spetersvn_error_t * 1893251881Spetersvn_io_run_diff3_2(int *exitcode, 1894251881Speter const char *dir, 1895251881Speter const char *mine, 1896251881Speter const char *older, 1897251881Speter const char *yours, 1898251881Speter const char *mine_label, 1899251881Speter const char *older_label, 1900251881Speter const char *yours_label, 1901251881Speter apr_file_t *merged, 1902251881Speter const char *diff3_cmd, 1903251881Speter const apr_array_header_t *user_args, 1904251881Speter apr_pool_t *pool); 1905251881Speter 1906251881Speter/** Similar to svn_io_run_diff3_2(), but with @a user_args set to @c NULL. 1907251881Speter * 1908251881Speter * @deprecated Provided for backwards compatibility with the 1.3 API. 1909251881Speter */ 1910251881SpeterSVN_DEPRECATED 1911251881Spetersvn_error_t * 1912251881Spetersvn_io_run_diff3(const char *dir, 1913251881Speter const char *mine, 1914251881Speter const char *older, 1915251881Speter const char *yours, 1916251881Speter const char *mine_label, 1917251881Speter const char *older_label, 1918251881Speter const char *yours_label, 1919251881Speter apr_file_t *merged, 1920251881Speter int *exitcode, 1921251881Speter const char *diff3_cmd, 1922251881Speter apr_pool_t *pool); 1923251881Speter 1924251881Speter 1925251881Speter/** Parse utf8-encoded @a mimetypes_file as a MIME types file (such as 1926251881Speter * is provided with Apache HTTP Server), and set @a *type_map to a 1927251881Speter * hash mapping <tt>const char *</tt> filename extensions to 1928251881Speter * <tt>const char *</tt> MIME types. 1929251881Speter * 1930251881Speter * @since New in 1.5. 1931251881Speter */ 1932251881Spetersvn_error_t * 1933251881Spetersvn_io_parse_mimetypes_file(apr_hash_t **type_map, 1934251881Speter const char *mimetypes_file, 1935251881Speter apr_pool_t *pool); 1936251881Speter 1937251881Speter 1938251881Speter/** Examine utf8-encoded @a file to determine if it can be described by a 1939251881Speter * known (as in, known by this function) Multipurpose Internet Mail 1940251881Speter * Extension (MIME) type. If so, set @a *mimetype to a character string 1941251881Speter * describing the MIME type, else set it to @c NULL. 1942251881Speter * 1943251881Speter * If not @c NULL, @a mimetype_map is a hash mapping <tt>const char *</tt> 1944251881Speter * filename extensions to <tt>const char *</tt> MIME types, and is the 1945251881Speter * first source consulted regarding @a file's MIME type. 1946251881Speter * 1947251881Speter * Use @a pool for any necessary allocations. 1948251881Speter * 1949251881Speter * @since New in 1.5. 1950251881Speter */ 1951251881Spetersvn_error_t * 1952251881Spetersvn_io_detect_mimetype2(const char **mimetype, 1953251881Speter const char *file, 1954251881Speter apr_hash_t *mimetype_map, 1955251881Speter apr_pool_t *pool); 1956251881Speter 1957251881Speter 1958251881Speter/** Like svn_io_detect_mimetype2, but with @a mimetypes_map set to 1959251881Speter * @c NULL. 1960251881Speter * 1961251881Speter * @deprecated Provided for backward compatibility with the 1.4 API 1962251881Speter */ 1963251881SpeterSVN_DEPRECATED 1964251881Spetersvn_error_t * 1965251881Spetersvn_io_detect_mimetype(const char **mimetype, 1966251881Speter const char *file, 1967251881Speter apr_pool_t *pool); 1968251881Speter 1969251881Speter 1970251881Speter/** Examine up to @a len bytes of data in @a buf to determine if the 1971251881Speter * can be considered binary data, in which case return TRUE. 1972251881Speter * If the data can be considered plain-text data, return FALSE. 1973251881Speter * 1974251881Speter * @since New in 1.7. 1975251881Speter */ 1976251881Spetersvn_boolean_t 1977251881Spetersvn_io_is_binary_data(const void *buf, apr_size_t len); 1978251881Speter 1979251881Speter 1980251881Speter/** Wrapper for apr_file_open(). @a fname is utf8-encoded. 1981251881Speter Always passed flag | APR_BINARY to apr. */ 1982251881Spetersvn_error_t * 1983251881Spetersvn_io_file_open(apr_file_t **new_file, 1984251881Speter const char *fname, 1985251881Speter apr_int32_t flag, 1986251881Speter apr_fileperms_t perm, 1987251881Speter apr_pool_t *pool); 1988251881Speter 1989251881Speter 1990251881Speter/** Wrapper for apr_file_close(). */ 1991251881Spetersvn_error_t * 1992251881Spetersvn_io_file_close(apr_file_t *file, 1993251881Speter apr_pool_t *pool); 1994251881Speter 1995251881Speter 1996251881Speter/** Wrapper for apr_file_getc(). */ 1997251881Spetersvn_error_t * 1998251881Spetersvn_io_file_getc(char *ch, 1999251881Speter apr_file_t *file, 2000251881Speter apr_pool_t *pool); 2001251881Speter 2002251881Speter 2003251881Speter/** Wrapper for apr_file_putc(). 2004251881Speter * @since New in 1.7 2005251881Speter */ 2006251881Spetersvn_error_t * 2007251881Spetersvn_io_file_putc(char ch, 2008251881Speter apr_file_t *file, 2009251881Speter apr_pool_t *pool); 2010251881Speter 2011251881Speter 2012251881Speter/** Wrapper for apr_file_info_get(). */ 2013251881Spetersvn_error_t * 2014251881Spetersvn_io_file_info_get(apr_finfo_t *finfo, 2015251881Speter apr_int32_t wanted, 2016251881Speter apr_file_t *file, 2017251881Speter apr_pool_t *pool); 2018251881Speter 2019251881Speter 2020251881Speter/** Wrapper for apr_file_read(). */ 2021251881Spetersvn_error_t * 2022251881Spetersvn_io_file_read(apr_file_t *file, 2023251881Speter void *buf, 2024251881Speter apr_size_t *nbytes, 2025251881Speter apr_pool_t *pool); 2026251881Speter 2027251881Speter 2028251881Speter/** Wrapper for apr_file_read_full(). 2029251881Speter * 2030251881Speter * If @a hit_eof is not NULL, EOF will be indicated there and no 2031251881Speter * svn_error_t error object will be created upon EOF. 2032251881Speter * 2033251881Speter * @since New in 1.7 2034251881Speter */ 2035251881Spetersvn_error_t * 2036251881Spetersvn_io_file_read_full2(apr_file_t *file, 2037251881Speter void *buf, 2038251881Speter apr_size_t nbytes, 2039251881Speter apr_size_t *bytes_read, 2040251881Speter svn_boolean_t *hit_eof, 2041251881Speter apr_pool_t *pool); 2042251881Speter 2043251881Speter 2044251881Speter/** Similar to svn_io_file_read_full2 with hit_eof being set 2045251881Speter * to @c NULL. 2046251881Speter * 2047251881Speter * @deprecated Provided for backward compatibility with the 1.6 API 2048251881Speter */ 2049251881SpeterSVN_DEPRECATED 2050251881Spetersvn_error_t * 2051251881Spetersvn_io_file_read_full(apr_file_t *file, 2052251881Speter void *buf, 2053251881Speter apr_size_t nbytes, 2054251881Speter apr_size_t *bytes_read, 2055251881Speter apr_pool_t *pool); 2056251881Speter 2057251881Speter 2058251881Speter/** Wrapper for apr_file_seek(). */ 2059251881Spetersvn_error_t * 2060251881Spetersvn_io_file_seek(apr_file_t *file, 2061251881Speter apr_seek_where_t where, 2062251881Speter apr_off_t *offset, 2063251881Speter apr_pool_t *pool); 2064251881Speter 2065251881Speter 2066251881Speter/** Wrapper for apr_file_write(). */ 2067251881Spetersvn_error_t * 2068251881Spetersvn_io_file_write(apr_file_t *file, 2069251881Speter const void *buf, 2070251881Speter apr_size_t *nbytes, 2071251881Speter apr_pool_t *pool); 2072251881Speter 2073251881Speter 2074251881Speter/** Wrapper for apr_file_write_full(). */ 2075251881Spetersvn_error_t * 2076251881Spetersvn_io_file_write_full(apr_file_t *file, 2077251881Speter const void *buf, 2078251881Speter apr_size_t nbytes, 2079251881Speter apr_size_t *bytes_written, 2080251881Speter apr_pool_t *pool); 2081251881Speter 2082251881Speter/** 2083251881Speter * Open a unique file in @a dirpath, and write @a nbytes from @a buf to 2084251881Speter * the file before flushing it to disk and closing it. Return the name 2085251881Speter * of the newly created file in @a *tmp_path, allocated in @a pool. 2086251881Speter * 2087251881Speter * If @a dirpath is @c NULL, use the path returned from svn_io_temp_dir(). 2088251881Speter * (Note that when using the system-provided temp directory, it may not 2089251881Speter * be possible to atomically rename the resulting file due to cross-device 2090251881Speter * issues.) 2091251881Speter * 2092251881Speter * The file will be deleted according to @a delete_when. 2093251881Speter * 2094251881Speter * @since New in 1.6. 2095251881Speter */ 2096251881Spetersvn_error_t * 2097251881Spetersvn_io_write_unique(const char **tmp_path, 2098251881Speter const char *dirpath, 2099251881Speter const void *buf, 2100251881Speter apr_size_t nbytes, 2101251881Speter svn_io_file_del_t delete_when, 2102251881Speter apr_pool_t *pool); 2103251881Speter 2104251881Speter/** Wrapper for apr_file_trunc(). 2105251881Speter * @since New in 1.6. */ 2106251881Spetersvn_error_t * 2107251881Spetersvn_io_file_trunc(apr_file_t *file, 2108251881Speter apr_off_t offset, 2109251881Speter apr_pool_t *pool); 2110251881Speter 2111251881Speter 2112251881Speter/** Wrapper for apr_stat(). @a fname is utf8-encoded. */ 2113251881Spetersvn_error_t * 2114251881Spetersvn_io_stat(apr_finfo_t *finfo, 2115251881Speter const char *fname, 2116251881Speter apr_int32_t wanted, 2117251881Speter apr_pool_t *pool); 2118251881Speter 2119251881Speter 2120251881Speter/** Rename and/or move the node (not necessarily a regular file) at 2121251881Speter * @a from_path to a new path @a to_path within the same filesystem. 2122251881Speter * In some cases, an existing node at @a to_path will be overwritten. 2123251881Speter * 2124251881Speter * A wrapper for apr_file_rename(). @a from_path and @a to_path are 2125251881Speter * utf8-encoded. 2126251881Speter */ 2127251881Spetersvn_error_t * 2128251881Spetersvn_io_file_rename(const char *from_path, 2129251881Speter const char *to_path, 2130251881Speter apr_pool_t *pool); 2131251881Speter 2132251881Speter 2133251881Speter/** Move the file from @a from_path to @a to_path, even across device 2134251881Speter * boundaries. Overwrite @a to_path if it exists. 2135251881Speter * 2136251881Speter * @note This function is different from svn_io_file_rename in that the 2137251881Speter * latter fails in the 'across device boundaries' case. 2138251881Speter * 2139251881Speter * @since New in 1.3. 2140251881Speter */ 2141251881Spetersvn_error_t * 2142251881Spetersvn_io_file_move(const char *from_path, 2143251881Speter const char *to_path, 2144251881Speter apr_pool_t *pool); 2145251881Speter 2146251881Speter 2147251881Speter/** Wrapper for apr_dir_make(). @a path is utf8-encoded. */ 2148251881Spetersvn_error_t * 2149251881Spetersvn_io_dir_make(const char *path, 2150251881Speter apr_fileperms_t perm, 2151251881Speter apr_pool_t *pool); 2152251881Speter 2153251881Speter/** Same as svn_io_dir_make(), but sets the hidden attribute on the 2154251881Speter directory on systems that support it. */ 2155251881Spetersvn_error_t * 2156251881Spetersvn_io_dir_make_hidden(const char *path, 2157251881Speter apr_fileperms_t perm, 2158251881Speter apr_pool_t *pool); 2159251881Speter 2160251881Speter/** 2161251881Speter * Same as svn_io_dir_make(), but attempts to set the sgid on the 2162251881Speter * directory on systems that support it. Does not return an error if 2163251881Speter * the attempt to set the sgid bit fails. On Unix filesystems, 2164251881Speter * setting the sgid bit on a directory ensures that files and 2165251881Speter * subdirectories created within inherit group ownership from the 2166251881Speter * parent instead of from the primary gid. 2167251881Speter * 2168251881Speter * @since New in 1.1. 2169251881Speter */ 2170251881Spetersvn_error_t * 2171251881Spetersvn_io_dir_make_sgid(const char *path, 2172251881Speter apr_fileperms_t perm, 2173251881Speter apr_pool_t *pool); 2174251881Speter 2175251881Speter/** Wrapper for apr_dir_open(). @a dirname is utf8-encoded. */ 2176251881Spetersvn_error_t * 2177251881Spetersvn_io_dir_open(apr_dir_t **new_dir, 2178251881Speter const char *dirname, 2179251881Speter apr_pool_t *pool); 2180251881Speter 2181251881Speter/** Wrapper for apr_dir_close(). 2182251881Speter * 2183251881Speter * @since New in 1.7. 2184251881Speter */ 2185251881Spetersvn_error_t * 2186251881Spetersvn_io_dir_close(apr_dir_t *thedir); 2187251881Speter 2188251881Speter/** Wrapper for apr_dir_remove(). @a dirname is utf8-encoded. 2189251881Speter * @note This function has this name to avoid confusion with 2190251881Speter * svn_io_remove_dir2(), which is recursive. 2191251881Speter */ 2192251881Spetersvn_error_t * 2193251881Spetersvn_io_dir_remove_nonrecursive(const char *dirname, 2194251881Speter apr_pool_t *pool); 2195251881Speter 2196251881Speter 2197251881Speter/** Wrapper for apr_dir_read(). Ensures that @a finfo->name is 2198251881Speter * utf8-encoded, which means allocating @a finfo->name in @a pool, 2199251881Speter * which may or may not be the same as @a finfo's pool. Use @a pool 2200251881Speter * for error allocation as well. 2201251881Speter */ 2202251881Spetersvn_error_t * 2203251881Spetersvn_io_dir_read(apr_finfo_t *finfo, 2204251881Speter apr_int32_t wanted, 2205251881Speter apr_dir_t *thedir, 2206251881Speter apr_pool_t *pool); 2207251881Speter 2208251881Speter/** Wrapper for apr_file_name_get(). @a *filename is utf8-encoded. 2209251881Speter * 2210251881Speter * @note The file name may be NULL. 2211251881Speter * 2212251881Speter * @since New in 1.7. */ 2213251881Spetersvn_error_t * 2214251881Spetersvn_io_file_name_get(const char **filename, 2215251881Speter apr_file_t *file, 2216251881Speter apr_pool_t *pool); 2217251881Speter 2218251881Speter 2219251881Speter 2220251881Speter/** Version/format files. 2221251881Speter * 2222251881Speter * @defgroup svn_io_format_files Version/format files 2223251881Speter * @{ 2224251881Speter */ 2225251881Speter 2226251881Speter/** Set @a *version to the integer that starts the file at @a path. If the 2227251881Speter * file does not begin with a series of digits followed by a newline, 2228251881Speter * return the error #SVN_ERR_BAD_VERSION_FILE_FORMAT. Use @a pool for 2229251881Speter * all allocations. 2230251881Speter */ 2231251881Spetersvn_error_t * 2232251881Spetersvn_io_read_version_file(int *version, 2233251881Speter const char *path, 2234251881Speter apr_pool_t *pool); 2235251881Speter 2236251881Speter/** Create (or overwrite) the file at @a path with new contents, 2237251881Speter * formatted as a non-negative integer @a version followed by a single 2238251881Speter * newline. On successful completion the file will be read-only. Use 2239251881Speter * @a pool for all allocations. 2240251881Speter */ 2241251881Spetersvn_error_t * 2242251881Spetersvn_io_write_version_file(const char *path, 2243251881Speter int version, 2244251881Speter apr_pool_t *pool); 2245251881Speter 2246251881Speter/** Read a line of text from a file, up to a specified length. 2247251881Speter * 2248251881Speter * Allocate @a *stringbuf in @a result_pool, and read into it one line 2249251881Speter * from @a file. Reading stops either after a line-terminator was found 2250251881Speter * or after @a max_len bytes have been read. 2251251881Speter * 2252251881Speter * If end-of-file is reached or @a max_len bytes have been read, and @a eof 2253251881Speter * is not NULL, then set @a *eof to @c TRUE. 2254251881Speter * 2255251881Speter * The line-terminator is not stored in @a *stringbuf. 2256251881Speter * The line-terminator is detected automatically and stored in @a *eol 2257251881Speter * if @a eol is not NULL. If EOF is reached and @a file does not end 2258251881Speter * with a newline character, and @a eol is not NULL, @ *eol is set to NULL. 2259251881Speter * 2260251881Speter * @a scratch_pool is used for temporary allocations. 2261251881Speter * 2262251881Speter * Hint: To read all data until a line-terminator is hit, pass APR_SIZE_MAX 2263251881Speter * for @a max_len. 2264251881Speter * 2265251881Speter * @since New in 1.8. 2266251881Speter */ 2267251881Spetersvn_error_t * 2268251881Spetersvn_io_file_readline(apr_file_t *file, 2269251881Speter svn_stringbuf_t **stringbuf, 2270251881Speter const char **eol, 2271251881Speter svn_boolean_t *eof, 2272251881Speter apr_size_t max_len, 2273251881Speter apr_pool_t *result_pool, 2274251881Speter apr_pool_t *scratch_pool); 2275251881Speter 2276251881Speter/** @} */ 2277251881Speter 2278251881Speter#ifdef __cplusplus 2279251881Speter} 2280251881Speter#endif /* __cplusplus */ 2281251881Speter 2282251881Speter#endif /* SVN_IO_H */ 2283