00001 /** 00002 * @copyright 00003 * ==================================================================== 00004 * Copyright (c) 2000-2008 CollabNet. All rights reserved. 00005 * 00006 * This software is licensed as described in the file COPYING, which 00007 * you should have received as part of this distribution. The terms 00008 * are also available at http://subversion.tigris.org/license-1.html. 00009 * If newer versions of this license are posted there, you may use a 00010 * newer version instead, at your option. 00011 * 00012 * This software consists of voluntary contributions made by many 00013 * individuals. For exact contribution history, see the revision 00014 * history and logs, available at http://subversion.tigris.org/. 00015 * ==================================================================== 00016 * @endcopyright 00017 * 00018 * @file svn_io.h 00019 * @brief General file I/O for Subversion 00020 */ 00021 00022 /* ==================================================================== */ 00023 00024 00025 #ifndef SVN_IO_H 00026 #define SVN_IO_H 00027 00028 #include <apr.h> 00029 #include <apr_pools.h> 00030 #include <apr_time.h> 00031 #include <apr_hash.h> 00032 #include <apr_tables.h> 00033 #include <apr_file_io.h> 00034 #include <apr_file_info.h> 00035 #include <apr_thread_proc.h> /* for apr_proc_t, apr_exit_why_e */ 00036 00037 #include "svn_types.h" 00038 #include "svn_string.h" 00039 #include "svn_checksum.h" 00040 00041 #ifdef __cplusplus 00042 extern "C" { 00043 #endif /* __cplusplus */ 00044 00045 00046 00047 /** Used as an argument when creating temporary files to indicate 00048 * when a file should be removed. 00049 * 00050 * @since New in 1.4. 00051 * 00052 * Not specifying any of these means no removal at all. */ 00053 typedef enum svn_io_file_del_t 00054 { 00055 /** No deletion ever */ 00056 svn_io_file_del_none = 0, 00057 /** Remove when the file is closed */ 00058 svn_io_file_del_on_close, 00059 /** Remove when the associated pool is cleared */ 00060 svn_io_file_del_on_pool_cleanup 00061 } svn_io_file_del_t; 00062 00063 00064 00065 /** Represents the kind and special status of a directory entry. 00066 * 00067 * @since New in 1.3. 00068 */ 00069 typedef struct svn_io_dirent_t { 00070 /** The kind of this entry. */ 00071 svn_node_kind_t kind; 00072 /** If @c kind is @c svn_node_file, whether this entry is a special file; 00073 * else FALSE. 00074 * 00075 * @see svn_io_check_special_path(). 00076 */ 00077 svn_boolean_t special; 00078 } svn_io_dirent_t; 00079 00080 /** Determine the @a kind of @a path. @a path should be UTF-8 encoded. 00081 * 00082 * If @a path is a file, set @a *kind to @c svn_node_file. 00083 * 00084 * If @a path is a directory, set @a *kind to @c svn_node_dir. 00085 * 00086 * If @a path does not exist, set @a *kind to @c svn_node_none. 00087 * 00088 * If @a path exists but is none of the above, set @a *kind to @c 00089 * svn_node_unknown. 00090 * 00091 * If unable to determine @a path's kind, return an error, with @a *kind's 00092 * value undefined. 00093 * 00094 * Use @a pool for temporary allocations. 00095 * 00096 * @see svn_node_kind_t 00097 */ 00098 svn_error_t * 00099 svn_io_check_path(const char *path, 00100 svn_node_kind_t *kind, 00101 apr_pool_t *pool); 00102 00103 /** 00104 * Like svn_io_check_path(), but also set *is_special to @c TRUE if 00105 * the path is not a normal file. 00106 * 00107 * @since New in 1.1. 00108 */ 00109 svn_error_t * 00110 svn_io_check_special_path(const char *path, 00111 svn_node_kind_t *kind, 00112 svn_boolean_t *is_special, 00113 apr_pool_t *pool); 00114 00115 /** Like svn_io_check_path(), but resolve symlinks. This returns the 00116 same varieties of @a kind as svn_io_check_path(). */ 00117 svn_error_t * 00118 svn_io_check_resolved_path(const char *path, 00119 svn_node_kind_t *kind, 00120 apr_pool_t *pool); 00121 00122 00123 /** Open a new file (for reading and writing) with a unique name based on 00124 * utf-8 encoded @a filename, in the directory @a dirpath. The file handle is 00125 * returned in @a *file, and the name, which ends with @a suffix, is returned 00126 * in @a *unique_name, also utf8-encoded. Either @a file or @a unique_name 00127 * may be @c NULL. 00128 * 00129 * If @a delete_when is @c svn_io_file_del_on_close, then the @c APR_DELONCLOSE 00130 * flag will be used when opening the file. The @c APR_BUFFERED flag will 00131 * always be used. 00132 * 00133 * The first attempt will just append @a suffix. If the result is not 00134 * a unique name, then subsequent attempts will append a dot, 00135 * followed by an iteration number ("2", then "3", and so on), 00136 * followed by the suffix. For example, successive calls to 00137 * 00138 * svn_io_open_uniquely_named(&f, &u, "tests/t1/A/D/G", "pi", ".tmp", ...) 00139 * 00140 * will open 00141 * 00142 * tests/t1/A/D/G/pi.tmp 00143 * tests/t1/A/D/G/pi.2.tmp 00144 * tests/t1/A/D/G/pi.3.tmp 00145 * tests/t1/A/D/G/pi.4.tmp 00146 * tests/t1/A/D/G/pi.5.tmp 00147 * ... 00148 * 00149 * Assuming @a suffix is non-empty, @a *unique_name will never be exactly 00150 * the same as @a filename, even if @a filename does not exist. 00151 * 00152 * If @a dirpath is NULL, then the directory returned by svn_io_temp_dir() 00153 * will be used. 00154 * 00155 * If @a filename is NULL, then "tempfile" will be used. 00156 * 00157 * If @a suffix is NULL, then ".tmp" will be used. 00158 * 00159 * Allocates @a *file and @a *unique_name in @a result_pool. All 00160 * intermediate allocations will be performed in @a scratch_pool. 00161 * 00162 * If no unique name can be found, @c SVN_ERR_IO_UNIQUE_NAMES_EXHAUSTED is 00163 * the error returned. 00164 * 00165 * Claim of Historical Inevitability: this function was written 00166 * because 00167 * 00168 * - tmpnam() is not thread-safe. 00169 * - tempname() tries standard system tmp areas first. 00170 * 00171 * @since New in 1.6 00172 */ 00173 svn_error_t * 00174 svn_io_open_uniquely_named(apr_file_t **file, 00175 const char **unique_name, 00176 const char *dirpath, 00177 const char *filename, 00178 const char *suffix, 00179 svn_io_file_del_t delete_when, 00180 apr_pool_t *result_pool, 00181 apr_pool_t *scratch_pool); 00182 00183 00184 /** Create a writable file in the directory @a dirpath. The file will have 00185 * an arbitrary and unique name, and the full path will be returned in 00186 * @a temp_path. The file will be returned in @a file. Both will be 00187 * allocated from @a result_pool. 00188 * 00189 * If @a dirpath is @c NULL, use the path returned from svn_io_temp_dir(). 00190 * (Note that when using the system-provided temp directory, it may not 00191 * be possibly to atomically rename the resulting file due to cross-device 00192 * issues.) 00193 * 00194 * The file will be deleted according to @a delete_when. 00195 * 00196 * Temporary allocations will be performed in @a scratch_pool. 00197 * 00198 * @since New in 1.6 00199 * @see svn_stream_open_unique() 00200 */ 00201 svn_error_t * 00202 svn_io_open_unique_file3(apr_file_t **file, 00203 const char **temp_path, 00204 const char *dirpath, 00205 svn_io_file_del_t delete_when, 00206 apr_pool_t *result_pool, 00207 apr_pool_t *scratch_pool); 00208 00209 00210 /** Like svn_io_open_uniquely_named(), but takes a joined dirpath and 00211 * filename, and a single pool. 00212 * 00213 * @since New in 1.4 00214 * 00215 * @deprecated Provided for backward compatibility with the 1.5 API 00216 */ 00217 SVN_DEPRECATED 00218 svn_error_t * 00219 svn_io_open_unique_file2(apr_file_t **f, 00220 const char **unique_name_p, 00221 const char *path, 00222 const char *suffix, 00223 svn_io_file_del_t delete_when, 00224 apr_pool_t *pool); 00225 00226 /** Like svn_io_open_unique_file2, but can't delete on pool cleanup. 00227 * 00228 * @deprecated Provided for backward compatibility with the 1.0 API 00229 * 00230 * @note In 1.4 the API was extended to require either @a f or 00231 * @a unique_name_p (the other can be NULL). Before that, both were 00232 * required. 00233 */ 00234 SVN_DEPRECATED 00235 svn_error_t * 00236 svn_io_open_unique_file(apr_file_t **f, 00237 const char **unique_name_p, 00238 const char *path, 00239 const char *suffix, 00240 svn_boolean_t delete_on_close, 00241 apr_pool_t *pool); 00242 00243 00244 /** 00245 * Like svn_io_open_unique_file(), except that instead of creating a 00246 * file, a symlink is generated that references the path @a dest. 00247 * 00248 * @since New in 1.1. 00249 */ 00250 svn_error_t * 00251 svn_io_create_unique_link(const char **unique_name_p, 00252 const char *path, 00253 const char *dest, 00254 const char *suffix, 00255 apr_pool_t *pool); 00256 00257 00258 /** 00259 * Set @a *dest to the path that the symlink at @a path references. 00260 * Allocate the string from @a pool. 00261 * 00262 * @since New in 1.1. 00263 */ 00264 svn_error_t * 00265 svn_io_read_link(svn_string_t **dest, 00266 const char *path, 00267 apr_pool_t *pool); 00268 00269 00270 /** Set @a *dir to a directory path (allocated in @a pool) deemed 00271 * usable for the creation of temporary files and subdirectories. 00272 */ 00273 svn_error_t * 00274 svn_io_temp_dir(const char **dir, 00275 apr_pool_t *pool); 00276 00277 00278 /** Copy @a src to @a dst atomically, in a "byte-for-byte" manner. 00279 * Overwrite @a dst if it exists, else create it. Both @a src and @a dst 00280 * are utf8-encoded filenames. If @a copy_perms is TRUE, set @a dst's 00281 * permissions to match those of @a src. 00282 */ 00283 svn_error_t * 00284 svn_io_copy_file(const char *src, 00285 const char *dst, 00286 svn_boolean_t copy_perms, 00287 apr_pool_t *pool); 00288 00289 00290 /** Copy permission flags from @a src onto the file at @a dst. Both 00291 * filenames are utf8-encoded filenames. 00292 */ 00293 svn_error_t * 00294 svn_io_copy_perms(const char *src, 00295 const char *dst, 00296 apr_pool_t *pool); 00297 00298 00299 /** 00300 * Copy symbolic link @a src to @a dst atomically. Overwrite @a dst 00301 * if it exists, else create it. Both @a src and @a dst are 00302 * utf8-encoded filenames. After copying, the @a dst link will point 00303 * to the same thing @a src does. 00304 * 00305 * @since New in 1.1. 00306 */ 00307 svn_error_t * 00308 svn_io_copy_link(const char *src, 00309 const char *dst, 00310 apr_pool_t *pool); 00311 00312 00313 /** Recursively copy directory @a src into @a dst_parent, as a new entry named 00314 * @a dst_basename. If @a dst_basename already exists in @a dst_parent, 00315 * return error. @a copy_perms will be passed through to svn_io_copy_file() 00316 * when any files are copied. @a src, @a dst_parent, and @a dst_basename are 00317 * all utf8-encoded. 00318 * 00319 * If @a cancel_func is non-NULL, invoke it with @a cancel_baton at 00320 * various points during the operation. If it returns any error 00321 * (typically @c SVN_ERR_CANCELLED), return that error immediately. 00322 */ 00323 svn_error_t * 00324 svn_io_copy_dir_recursively(const char *src, 00325 const char *dst_parent, 00326 const char *dst_basename, 00327 svn_boolean_t copy_perms, 00328 svn_cancel_func_t cancel_func, 00329 void *cancel_baton, 00330 apr_pool_t *pool); 00331 00332 00333 /** Create directory @a path on the file system, creating intermediate 00334 * directories as required, like <tt>mkdir -p</tt>. Report no error if @a 00335 * path already exists. @a path is utf8-encoded. 00336 * 00337 * This is essentially a wrapper for apr_dir_make_recursive(), passing 00338 * @c APR_OS_DEFAULT as the permissions. 00339 */ 00340 svn_error_t * 00341 svn_io_make_dir_recursively(const char *path, 00342 apr_pool_t *pool); 00343 00344 00345 /** Set @a *is_empty_p to @c TRUE if directory @a path is empty, else to 00346 * @c FALSE if it is not empty. @a path must be a directory, and is 00347 * utf8-encoded. Use @a pool for temporary allocation. 00348 */ 00349 svn_error_t * 00350 svn_io_dir_empty(svn_boolean_t *is_empty_p, 00351 const char *path, 00352 apr_pool_t *pool); 00353 00354 00355 /** Append @a src to @a dst. @a dst will be appended to if it exists, else it 00356 * will be created. Both @a src and @a dst are utf8-encoded. 00357 */ 00358 svn_error_t * 00359 svn_io_append_file(const char *src, 00360 const char *dst, 00361 apr_pool_t *pool); 00362 00363 00364 /** Make a file as read-only as the operating system allows. 00365 * @a path is the utf8-encoded path to the file. If @a ignore_enoent is 00366 * @c TRUE, don't fail if the target file doesn't exist. 00367 * 00368 * If @a path is a symlink, do nothing. 00369 * 00370 * @note If @a path is a directory, act on it as though it were a 00371 * file, as described above, but note that you probably don't want to 00372 * call this function on directories. We have left it effective on 00373 * directories for compatibility reasons, but as its name implies, it 00374 * should be used only for files. 00375 */ 00376 svn_error_t * 00377 svn_io_set_file_read_only(const char *path, 00378 svn_boolean_t ignore_enoent, 00379 apr_pool_t *pool); 00380 00381 00382 /** Make a file as writable as the operating system allows. 00383 * @a path is the utf8-encoded path to the file. If @a ignore_enoent is 00384 * @c TRUE, don't fail if the target file doesn't exist. 00385 * @warning On Unix this function will do the equivalent of chmod a+w path. 00386 * If this is not what you want you should not use this function, but rather 00387 * use apr_file_perms_set(). 00388 * 00389 * If @a path is a symlink, do nothing. 00390 * 00391 * @note If @a path is a directory, act on it as though it were a 00392 * file, as described above, but note that you probably don't want to 00393 * call this function on directories. We have left it effective on 00394 * directories for compatibility reasons, but as its name implies, it 00395 * should be used only for files. 00396 */ 00397 svn_error_t * 00398 svn_io_set_file_read_write(const char *path, 00399 svn_boolean_t ignore_enoent, 00400 apr_pool_t *pool); 00401 00402 00403 /** Similar to svn_io_set_file_read_* functions. 00404 * Change the read-write permissions of a file. 00405 * @since New in 1.1. 00406 * 00407 * When making @a path read-write on operating systems with unix style 00408 * permissions, set the permissions on @a path to the permissions that 00409 * are set when a new file is created (effectively honoring the user's 00410 * umask). 00411 * 00412 * When making the file read-only on operating systems with unix style 00413 * permissions, remove all write permissions. 00414 * 00415 * On other operating systems, toggle the file's "writability" as much as 00416 * the operating system allows. 00417 * 00418 * @a path is the utf8-encoded path to the file. If @a enable_write 00419 * is @c TRUE, then make the file read-write. If @c FALSE, make it 00420 * read-only. If @a ignore_enoent is @c TRUE, don't fail if the target 00421 * file doesn't exist. 00422 * 00423 * @deprecated Provided for backward compatibility with the 1.3 API. 00424 */ 00425 SVN_DEPRECATED 00426 svn_error_t * 00427 svn_io_set_file_read_write_carefully(const char *path, 00428 svn_boolean_t enable_write, 00429 svn_boolean_t ignore_enoent, 00430 apr_pool_t *pool); 00431 00432 /** Set @a path's "executability" (but do nothing if it is a symlink). 00433 * 00434 * @a path is the utf8-encoded path to the file. If @a executable 00435 * is @c TRUE, then make the file executable. If @c FALSE, make it 00436 * non-executable. If @a ignore_enoent is @c TRUE, don't fail if the target 00437 * file doesn't exist. 00438 * 00439 * When making the file executable on operating systems with unix style 00440 * permissions, never add an execute permission where there is not 00441 * already a read permission: that is, only make the file executable 00442 * for the user, group or world if the corresponding read permission 00443 * is already set for user, group or world. 00444 * 00445 * When making the file non-executable on operating systems with unix style 00446 * permissions, remove all execute permissions. 00447 * 00448 * On other operating systems, toggle the file's "executability" as much as 00449 * the operating system allows. 00450 * 00451 * @note If @a path is a directory, act on it as though it were a 00452 * file, as described above, but note that you probably don't want to 00453 * call this function on directories. We have left it effective on 00454 * directories for compatibility reasons, but as its name implies, it 00455 * should be used only for files. 00456 */ 00457 svn_error_t * 00458 svn_io_set_file_executable(const char *path, 00459 svn_boolean_t executable, 00460 svn_boolean_t ignore_enoent, 00461 apr_pool_t *pool); 00462 00463 /** Determine whether a file is executable by the current user. 00464 * Set @a *executable to @c TRUE if the file @a path is executable by the 00465 * current user, otherwise set it to @c FALSE. 00466 * 00467 * On Windows and on platforms without userids, always returns @c FALSE. 00468 */ 00469 svn_error_t * 00470 svn_io_is_file_executable(svn_boolean_t *executable, 00471 const char *path, 00472 apr_pool_t *pool); 00473 00474 00475 /** Read a line from @a file into @a buf, but not exceeding @a *limit bytes. 00476 * Does not include newline, instead '\\0' is put there. 00477 * Length (as in strlen) is returned in @a *limit. 00478 * @a buf should be pre-allocated. 00479 * @a file should be already opened. 00480 * 00481 * When the file is out of lines, @c APR_EOF will be returned. 00482 */ 00483 svn_error_t * 00484 svn_io_read_length_line(apr_file_t *file, 00485 char *buf, 00486 apr_size_t *limit, 00487 apr_pool_t *pool); 00488 00489 00490 /** Set @a *apr_time to the time of last modification of the contents of the 00491 * file @a path. @a path is utf8-encoded. 00492 * 00493 * @note This is the APR mtime which corresponds to the traditional mtime 00494 * on Unix, and the last write time on Windows. 00495 */ 00496 svn_error_t * 00497 svn_io_file_affected_time(apr_time_t *apr_time, 00498 const char *path, 00499 apr_pool_t *pool); 00500 00501 /** Set the timestamp of file @a path to @a apr_time. @a path is 00502 * utf8-encoded. 00503 * 00504 * @note This is the APR mtime which corresponds to the traditional mtime 00505 * on Unix, and the last write time on Windows. 00506 */ 00507 svn_error_t * 00508 svn_io_set_file_affected_time(apr_time_t apr_time, 00509 const char *path, 00510 apr_pool_t *pool); 00511 00512 /** Sleep to ensure that any files modified after we exit have a different 00513 * timestamp than the one we recorded. If @a path is not NULL, check if we 00514 * can determine how long we should wait for a new timestamp on the filesystem 00515 * containing @a path, an existing file or directory. If @a path is NULL or we 00516 * can't determine the timestamp resolution, sleep until the next second. 00517 * 00518 * Use @a pool for any necessary allocations. @a pool can be null if @a path 00519 * is NULL. 00520 * 00521 * Errors while retrieving the timestamp resolution will result in sleeping 00522 * to the next second, to keep the working copy stable in error conditions. 00523 * 00524 * @since New in 1.6. 00525 */ 00526 void 00527 svn_io_sleep_for_timestamps(const char *path, apr_pool_t *pool); 00528 00529 /** Set @a *different_p to non-zero if @a file1 and @a file2 have different 00530 * sizes, else set to zero. Both @a file1 and @a file2 are utf8-encoded. 00531 * 00532 * Setting @a *different_p to zero does not mean the files definitely 00533 * have the same size, it merely means that the sizes are not 00534 * definitely different. That is, if the size of one or both files 00535 * cannot be determined, then the sizes are not known to be different, 00536 * so @a *different_p is set to 0. 00537 */ 00538 svn_error_t * 00539 svn_io_filesizes_different_p(svn_boolean_t *different_p, 00540 const char *file1, 00541 const char *file2, 00542 apr_pool_t *pool); 00543 00544 00545 /** Return in @a *checksum the checksum of type @a kind of @a file 00546 * Use @a pool for temporary allocations and to allocate @a *checksum. 00547 * 00548 * @since New in 1.6. 00549 */ 00550 svn_error_t * 00551 svn_io_file_checksum2(svn_checksum_t **checksum, 00552 const char *file, 00553 svn_checksum_kind_t kind, 00554 apr_pool_t *pool); 00555 00556 00557 /** Put the md5 checksum of @a file into @a digest. 00558 * @a digest points to @c APR_MD5_DIGESTSIZE bytes of storage. 00559 * Use @a pool only for temporary allocations. 00560 * 00561 * @deprecated Provided for backward compatibility with the 1.5 API. 00562 */ 00563 SVN_DEPRECATED 00564 svn_error_t * 00565 svn_io_file_checksum(unsigned char digest[], 00566 const char *file, 00567 apr_pool_t *pool); 00568 00569 00570 /** Set @a *same to TRUE if @a file1 and @a file2 have the same 00571 * contents, else set it to FALSE. Use @a pool for temporary allocations. 00572 */ 00573 svn_error_t * 00574 svn_io_files_contents_same_p(svn_boolean_t *same, 00575 const char *file1, 00576 const char *file2, 00577 apr_pool_t *pool); 00578 00579 /** Create file at utf8-encoded @a file with contents @a contents. 00580 * @a file must not already exist. 00581 * Use @a pool for memory allocations. 00582 */ 00583 svn_error_t * 00584 svn_io_file_create(const char *file, 00585 const char *contents, 00586 apr_pool_t *pool); 00587 00588 /** 00589 * Lock file at @a lock_file. If @a exclusive is TRUE, 00590 * obtain exclusive lock, otherwise obtain shared lock. 00591 * Lock will be automatically released when @a pool is cleared or destroyed. 00592 * Use @a pool for memory allocations. 00593 * 00594 * @deprecated Provided for backward compatibility with the 1.0 API. 00595 */ 00596 SVN_DEPRECATED 00597 svn_error_t * 00598 svn_io_file_lock(const char *lock_file, 00599 svn_boolean_t exclusive, 00600 apr_pool_t *pool); 00601 00602 /** 00603 * Lock file at @a lock_file. If @a exclusive is TRUE, 00604 * obtain exclusive lock, otherwise obtain shared lock. 00605 * 00606 * If @a nonblocking is TRUE, do not wait for the lock if it 00607 * is not available: throw an error instead. 00608 * 00609 * Lock will be automatically released when @a pool is cleared or destroyed. 00610 * Use @a pool for memory allocations. 00611 * 00612 * @since New in 1.1. 00613 */ 00614 svn_error_t * 00615 svn_io_file_lock2(const char *lock_file, 00616 svn_boolean_t exclusive, 00617 svn_boolean_t nonblocking, 00618 apr_pool_t *pool); 00619 /** 00620 * Flush any unwritten data from @a file to disk. Use @a pool for 00621 * memory allocations. 00622 * 00623 * @since New in 1.1. 00624 */ 00625 svn_error_t * 00626 svn_io_file_flush_to_disk(apr_file_t *file, 00627 apr_pool_t *pool); 00628 00629 /** Copy file @a file from location @a src_path to location @a dest_path. 00630 * Use @a pool for memory allocations. 00631 */ 00632 svn_error_t * 00633 svn_io_dir_file_copy(const char *src_path, 00634 const char *dest_path, 00635 const char *file, 00636 apr_pool_t *pool); 00637 00638 00639 /** Generic byte-streams 00640 * 00641 * @defgroup svn_io_byte_streams Generic byte streams 00642 * @{ 00643 */ 00644 00645 /** An abstract stream of bytes--either incoming or outgoing or both. 00646 * 00647 * The creator of a stream sets functions to handle read and write. 00648 * Both of these handlers accept a baton whose value is determined at 00649 * stream creation time; this baton can point to a structure 00650 * containing data associated with the stream. If a caller attempts 00651 * to invoke a handler which has not been set, it will generate a 00652 * runtime assertion failure. The creator can also set a handler for 00653 * close requests so that it can flush buffered data or whatever; 00654 * if a close handler is not specified, a close request on the stream 00655 * will simply be ignored. Note that svn_stream_close() does not 00656 * deallocate the memory used to allocate the stream structure; free 00657 * the pool you created the stream in to free that memory. 00658 * 00659 * The read and write handlers accept length arguments via pointer. 00660 * On entry to the handler, the pointed-to value should be the amount 00661 * of data which can be read or the amount of data to write. When the 00662 * handler returns, the value is reset to the amount of data actually 00663 * read or written. Handlers are obliged to complete a read or write 00664 * to the maximum extent possible; thus, a short read with no 00665 * associated error implies the end of the input stream, and a short 00666 * write should never occur without an associated error. 00667 */ 00668 typedef struct svn_stream_t svn_stream_t; 00669 00670 00671 00672 /** Read handler function for a generic stream. @see svn_stream_t. */ 00673 typedef svn_error_t *(*svn_read_fn_t)(void *baton, 00674 char *buffer, 00675 apr_size_t *len); 00676 00677 /** Write handler function for a generic stream. @see svn_stream_t. */ 00678 typedef svn_error_t *(*svn_write_fn_t)(void *baton, 00679 const char *data, 00680 apr_size_t *len); 00681 00682 /** Close handler function for a generic stream. @see svn_stream_t. */ 00683 typedef svn_error_t *(*svn_close_fn_t)(void *baton); 00684 00685 00686 /** Create a generic stream. @see svn_stream_t. */ 00687 svn_stream_t * 00688 svn_stream_create(void *baton, 00689 apr_pool_t *pool); 00690 00691 /** Set @a stream's baton to @a baton */ 00692 void 00693 svn_stream_set_baton(svn_stream_t *stream, 00694 void *baton); 00695 00696 /** Set @a stream's read function to @a read_fn */ 00697 void 00698 svn_stream_set_read(svn_stream_t *stream, 00699 svn_read_fn_t read_fn); 00700 00701 /** Set @a stream's write function to @a write_fn */ 00702 void 00703 svn_stream_set_write(svn_stream_t *stream, 00704 svn_write_fn_t write_fn); 00705 00706 /** Set @a stream's close function to @a close_fn */ 00707 void 00708 svn_stream_set_close(svn_stream_t *stream, 00709 svn_close_fn_t close_fn); 00710 00711 00712 /** Create a stream that is empty for reading and infinite for writing. */ 00713 svn_stream_t * 00714 svn_stream_empty(apr_pool_t *pool); 00715 00716 /** Return a stream allocated in @a pool which forwards all requests 00717 * to @a stream. Destruction is explicitly excluded from forwarding. 00718 * 00719 * @see notes/destruction-of-stacked-resources 00720 * 00721 * @since New in 1.4. 00722 */ 00723 svn_stream_t * 00724 svn_stream_disown(svn_stream_t *stream, 00725 apr_pool_t *pool); 00726 00727 00728 /** Create a stream to read the file at @a path. It will be opened using 00729 * the APR_BUFFERED and APR_BINARY flag, and APR_OS_DEFAULT for the perms. 00730 * If you'd like to use different values, then open the file yourself, and 00731 * use the svn_stream_from_aprfile2() interface. 00732 * 00733 * The stream will be returned in @a stream, and allocated from @a result_pool. 00734 * Temporary allocations will be performed in @a scratch_pool. 00735 * 00736 * @since New in 1.6 00737 */ 00738 svn_error_t * 00739 svn_stream_open_readonly(svn_stream_t **stream, 00740 const char *path, 00741 apr_pool_t *result_pool, 00742 apr_pool_t *scratch_pool); 00743 00744 00745 /** Create a stream to write a file at @a path. The file will be *created* 00746 * using the APR_BUFFERED and APR_BINARY flag, and APR_OS_DEFAULT for the 00747 * perms. The file will be created "exclusively", so if it already exists, 00748 * then an error will be thrown. If you'd like to use different values, or 00749 * open an existing file, then open the file yourself, and use the 00750 * svn_stream_from_aprfile2() interface. 00751 * 00752 * The stream will be returned in @a stream, and allocated from @a result_pool. 00753 * Temporary allocations will be performed in @a scratch_pool. 00754 * 00755 * @since New in 1.6 00756 */ 00757 svn_error_t * 00758 svn_stream_open_writable(svn_stream_t **stream, 00759 const char *path, 00760 apr_pool_t *result_pool, 00761 apr_pool_t *scratch_pool); 00762 00763 00764 /** Create a writable stream to a file in the directory @a dirpath. 00765 * The file will have an arbitrary and unique name, and the full path 00766 * will be returned in @a temp_path. The stream will be returned in 00767 * @a stream. Both will be allocated from @a result_pool. 00768 * 00769 * If @a dirpath is @c NULL, use the path returned from svn_io_temp_dir(). 00770 * (Note that when using the system-provided temp directory, it may not 00771 * be possibly to atomically rename the resulting file due to cross-device 00772 * issues.) 00773 * 00774 * The file will be deleted according to @a delete_when. 00775 * 00776 * Temporary allocations will be performed in @a scratch_pool. 00777 * 00778 * @since New in 1.6 00779 * @see svn_io_open_unique_file3() 00780 */ 00781 svn_error_t * 00782 svn_stream_open_unique(svn_stream_t **stream, 00783 const char **temp_path, 00784 const char *dirpath, 00785 svn_io_file_del_t delete_when, 00786 apr_pool_t *result_pool, 00787 apr_pool_t *scratch_pool); 00788 00789 00790 /** Create a stream from an APR file. For convenience, if @a file is 00791 * @c NULL, an empty stream created by svn_stream_empty() is returned. 00792 * 00793 * This function should normally be called with @a disown set to FALSE, 00794 * in which case closing the stream will also close the underlying file. 00795 * 00796 * If @a disown is TRUE, the stream will disown the underlying file, 00797 * meaning that svn_stream_close() will not close the file. 00798 * 00799 * @since New in 1.4. 00800 */ 00801 svn_stream_t * 00802 svn_stream_from_aprfile2(apr_file_t *file, 00803 svn_boolean_t disown, 00804 apr_pool_t *pool); 00805 00806 /** Similar to svn_stream_from_aprfile2(), except that the file will 00807 * always be disowned. 00808 * 00809 * @note The stream returned is not considered to "own" the underlying 00810 * file, meaning that svn_stream_close() on the stream will not 00811 * close the file. 00812 * 00813 * @deprecated Provided for backward compatibility with the 1.3 API. 00814 */ 00815 SVN_DEPRECATED 00816 svn_stream_t * 00817 svn_stream_from_aprfile(apr_file_t *file, 00818 apr_pool_t *pool); 00819 00820 /** Set @a *out to a generic stream connected to stdout, allocated in 00821 * @a pool. The stream and its underlying APR handle will be closed 00822 * when @a pool is cleared or destroyed. 00823 */ 00824 svn_error_t * 00825 svn_stream_for_stdout(svn_stream_t **out, 00826 apr_pool_t *pool); 00827 00828 /** Return a generic stream connected to stringbuf @a str. Allocate the 00829 * stream in @a pool. 00830 */ 00831 svn_stream_t * 00832 svn_stream_from_stringbuf(svn_stringbuf_t *str, 00833 apr_pool_t *pool); 00834 00835 /** Return a generic read-only stream connected to string @a str. 00836 * Allocate the stream in @a pool. 00837 */ 00838 svn_stream_t * 00839 svn_stream_from_string(const svn_string_t *str, 00840 apr_pool_t *pool); 00841 00842 /** Return a stream that decompresses all data read and compresses all 00843 * data written. The stream @a stream is used to read and write all 00844 * compressed data. All compression data structures are allocated on 00845 * @a pool. If compression support is not compiled in then 00846 * svn_stream_compressed() returns @a stream unmodified. Make sure you 00847 * call svn_stream_close() on the stream returned by this function, 00848 * so that all data are flushed and cleaned up. 00849 * 00850 * @note From 1.4, compression support is always compiled in. 00851 */ 00852 svn_stream_t * 00853 svn_stream_compressed(svn_stream_t *stream, 00854 apr_pool_t *pool); 00855 00856 /** Return a stream that calculates checksums for all data read 00857 * and written. The stream @a stream is used to read and write all data. 00858 * The stream and the resulting digests are allocated in @a pool. 00859 * 00860 * When the stream is closed, @a *read_checksum and @a *write_checksum 00861 * are set to point to the resulting checksums, of type @a read_checksum_kind 00862 * and @a write_checksum_kind, respectively. 00863 * 00864 * Both @a read_checksum and @a write_checksum can be @c NULL, in which case 00865 * the respective checksum isn't calculated. 00866 * 00867 * If @a read_all is TRUE, make sure that all data available on @a 00868 * stream is read (and checksummed) when the stream is closed. 00869 * 00870 * Read and write operations can be mixed without interfering. 00871 * 00872 * The @a stream passed into this function is closed when the created 00873 * stream is closed. 00874 * 00875 * @since New in 1.6. 00876 */ 00877 svn_stream_t * 00878 svn_stream_checksummed2(svn_stream_t *stream, 00879 svn_checksum_t **read_checksum, 00880 svn_checksum_t **write_checksum, 00881 svn_checksum_kind_t checksum_kind, 00882 svn_boolean_t read_all, 00883 apr_pool_t *pool); 00884 00885 /** 00886 * Similar to svn_stream_checksummed2(), but always returning the MD5 00887 * checksum in @a read_digest and @a write_digest. 00888 * 00889 * @since New in 1.4. 00890 * @deprecated Provided for backward compatibility with the 1.5 API. 00891 */ 00892 SVN_DEPRECATED 00893 svn_stream_t * 00894 svn_stream_checksummed(svn_stream_t *stream, 00895 const unsigned char **read_digest, 00896 const unsigned char **write_digest, 00897 svn_boolean_t read_all, 00898 apr_pool_t *pool); 00899 00900 /** Read from a generic stream. @see svn_stream_t. */ 00901 svn_error_t * 00902 svn_stream_read(svn_stream_t *stream, 00903 char *buffer, 00904 apr_size_t *len); 00905 00906 /** Write to a generic stream. @see svn_stream_t. */ 00907 svn_error_t * 00908 svn_stream_write(svn_stream_t *stream, 00909 const char *data, 00910 apr_size_t *len); 00911 00912 /** Close a generic stream. @see svn_stream_t. */ 00913 svn_error_t * 00914 svn_stream_close(svn_stream_t *stream); 00915 00916 00917 /** Write to @a stream using a printf-style @a fmt specifier, passed through 00918 * apr_psprintf() using memory from @a pool. 00919 */ 00920 svn_error_t * 00921 svn_stream_printf(svn_stream_t *stream, 00922 apr_pool_t *pool, 00923 const char *fmt, 00924 ...) 00925 __attribute__((format(printf, 3, 4))); 00926 00927 /** Write to @a stream using a printf-style @a fmt specifier, passed through 00928 * apr_psprintf() using memory from @a pool. The resulting string 00929 * will be translated to @a encoding before it is sent to @a stream. 00930 * 00931 * @note Use @c APR_LOCALE_CHARSET to translate to the encoding of the 00932 * current locale. 00933 * 00934 * @since New in 1.3. 00935 */ 00936 svn_error_t * 00937 svn_stream_printf_from_utf8(svn_stream_t *stream, 00938 const char *encoding, 00939 apr_pool_t *pool, 00940 const char *fmt, 00941 ...) 00942 __attribute__((format(printf, 4, 5))); 00943 00944 /** Allocate @a *stringbuf in @a pool, and read into it one line (terminated 00945 * by @a eol) from @a stream. The line-terminator is read from the stream, 00946 * but is not added to the end of the stringbuf. Instead, the stringbuf 00947 * ends with a usual '\\0'. 00948 * 00949 * If @a stream runs out of bytes before encountering a line-terminator, 00950 * then set @a *eof to @c TRUE, otherwise set @a *eof to FALSE. 00951 */ 00952 svn_error_t * 00953 svn_stream_readline(svn_stream_t *stream, 00954 svn_stringbuf_t **stringbuf, 00955 const char *eol, 00956 svn_boolean_t *eof, 00957 apr_pool_t *pool); 00958 00959 00960 /** 00961 * Read the contents of the readable stream @a from and write them to the 00962 * writable stream @a to calling @a cancel_func before copying each chunk. 00963 * 00964 * @a cancel_func may be @c NULL. 00965 * 00966 * @note both @a from and @a to will be closed upon successful completion of 00967 * the copy (but an error may still be returned, based on trying to close 00968 * the two streams). If the closure is not desired, then you can use 00969 * svn_stream_disown() to protect either or both of the streams from 00970 * being closed. 00971 * ### TODO: should close the streams ALWAYS, even on error exit 00972 * 00973 * @since New in 1.6. 00974 */ 00975 svn_error_t * 00976 svn_stream_copy3(svn_stream_t *from, 00977 svn_stream_t *to, 00978 svn_cancel_func_t cancel_func, 00979 void *cancel_baton, 00980 apr_pool_t *pool); 00981 00982 /** 00983 * Same as svn_stream_copy3() but the streams are not closed. 00984 * 00985 * @since New in 1.5. 00986 * @deprecated Provided for backward compatibility with the 1.5 API. 00987 */ 00988 SVN_DEPRECATED 00989 svn_error_t * 00990 svn_stream_copy2(svn_stream_t *from, 00991 svn_stream_t *to, 00992 svn_cancel_func_t cancel_func, 00993 void *cancel_baton, 00994 apr_pool_t *pool); 00995 00996 /** 00997 * Same as svn_stream_copy3(), but without the cancellation function 00998 * or stream closing. 00999 * 01000 * @since New in 1.1. 01001 * @deprecated Provided for backward compatibility with the 1.4 API. 01002 */ 01003 SVN_DEPRECATED 01004 svn_error_t * 01005 svn_stream_copy(svn_stream_t *from, 01006 svn_stream_t *to, 01007 apr_pool_t *pool); 01008 01009 01010 /** Set @a *same to TRUE if @a stream1 and @a stream2 have the same 01011 * contents, else set it to FALSE. Use @a pool for temporary allocations. 01012 * 01013 * @since New in 1.4. 01014 */ 01015 svn_error_t * 01016 svn_stream_contents_same(svn_boolean_t *same, 01017 svn_stream_t *stream1, 01018 svn_stream_t *stream2, 01019 apr_pool_t *pool); 01020 01021 01022 /** Read the contents of @a stream into memory, returning the data in 01023 * @a result. The stream will be closed when it has been successfully and 01024 * completely read. 01025 * 01026 * The returned memory is allocated in @a result_pool, and any temporary 01027 * allocations are performed in @a scratch_pool. 01028 * 01029 * @note due to memory pseudo-reallocation behavior (due to pools), this 01030 * can be a memory-intensive operation for large files. 01031 * 01032 * @since New in 1.6 01033 */ 01034 svn_error_t * 01035 svn_string_from_stream(svn_string_t **result, 01036 svn_stream_t *stream, 01037 apr_pool_t *result_pool, 01038 apr_pool_t *scratch_pool); 01039 01040 01041 /** @} */ 01042 01043 /** Set @a *result to a string containing the contents of @a 01044 * filename, which is either "-" (indicating that stdin should be 01045 * read) or the utf8-encoded path of a real file. 01046 * 01047 * @warning Callers should be aware of possible unexpected results 01048 * when using this function to read from stdin where additional 01049 * stdin-reading processes abound. For example, if a program tries 01050 * both to invoke an external editor and to read from stdin, stdin 01051 * could be trashed and the editor might act funky or die outright. 01052 * 01053 * @note due to memory pseudo-reallocation behavior (due to pools), this 01054 * can be a memory-intensive operation for large files. 01055 * 01056 * @since New in 1.5. 01057 */ 01058 svn_error_t * 01059 svn_stringbuf_from_file2(svn_stringbuf_t **result, 01060 const char *filename, 01061 apr_pool_t *pool); 01062 01063 /** Similar to svn_stringbuf_from_file2(), except that if @a filename 01064 * is "-", return the error @c SVN_ERR_UNSUPPORTED_FEATURE and don't 01065 * touch @a *result. 01066 * 01067 * @deprecated Provided for backwards compatibility with the 1.4 API. 01068 */ 01069 SVN_DEPRECATED 01070 svn_error_t * 01071 svn_stringbuf_from_file(svn_stringbuf_t **result, 01072 const char *filename, 01073 apr_pool_t *pool); 01074 01075 /** Sets @a *result to a string containing the contents of the already opened 01076 * @a file. Reads from the current position in file to the end. Does not 01077 * close the file or reset the cursor position. 01078 * 01079 * @note due to memory pseudo-reallocation behavior (due to pools), this 01080 * can be a memory-intensive operation for large files. 01081 */ 01082 svn_error_t * 01083 svn_stringbuf_from_aprfile(svn_stringbuf_t **result, 01084 apr_file_t *file, 01085 apr_pool_t *pool); 01086 01087 /** Remove file @a path, a utf8-encoded path. This wraps apr_file_remove(), 01088 * converting any error to a Subversion error. 01089 */ 01090 svn_error_t * 01091 svn_io_remove_file(const char *path, 01092 apr_pool_t *pool); 01093 01094 /** Recursively remove directory @a path. @a path is utf8-encoded. 01095 * If @a ignore_enoent is @c TRUE, don't fail if the target directory 01096 * doesn't exist. Use @a pool for temporary allocations. 01097 * 01098 * Because recursive delete of a directory tree can be a lengthy operation, 01099 * provide @a cancel_func and @a cancel_baton for interruptability. 01100 * 01101 * @since New in 1.5. 01102 */ 01103 svn_error_t * 01104 svn_io_remove_dir2(const char *path, 01105 svn_boolean_t ignore_enoent, 01106 svn_cancel_func_t cancel_func, 01107 void *cancel_baton, 01108 apr_pool_t *pool); 01109 01110 /** Similar to svn_io_remove_dir2(), but with @a ignore_enoent set to 01111 * @c FALSE and @a cancel_func and @a cancel_baton set to @c NULL. 01112 * 01113 * @deprecated Provided for backward compatibility with the 1.4 API 01114 */ 01115 SVN_DEPRECATED 01116 svn_error_t * 01117 svn_io_remove_dir(const char *path, 01118 apr_pool_t *pool); 01119 01120 /** Read all of the disk entries in directory @a path, a utf8-encoded 01121 * path. Set @a *dirents to a hash mapping dirent names (<tt>char *</tt>) to 01122 * undefined non-NULL values, allocated in @a pool. 01123 * 01124 * @note The `.' and `..' directories normally returned by 01125 * apr_dir_read() are NOT returned in the hash. 01126 * 01127 * @since New in 1.4. 01128 */ 01129 svn_error_t * 01130 svn_io_get_dir_filenames(apr_hash_t **dirents, 01131 const char *path, 01132 apr_pool_t *pool); 01133 01134 /** Read all of the disk entries in directory @a path, a utf8-encoded 01135 * path. Set @a *dirents to a hash mapping dirent names (<tt>char *</tt>) to 01136 * @c svn_io_dirent_t structures, allocated in @a pool. 01137 * 01138 * @note The `.' and `..' directories normally returned by 01139 * apr_dir_read() are NOT returned in the hash. 01140 * 01141 * @note The kind field in the @a dirents is set according to the mapping 01142 * as documented for svn_io_check_path() 01143 * 01144 * @since New in 1.3. 01145 */ 01146 svn_error_t * 01147 svn_io_get_dirents2(apr_hash_t **dirents, 01148 const char *path, 01149 apr_pool_t *pool); 01150 01151 /** Similar to svn_io_get_dirents2(), but @a *dirents is a hash table 01152 * with @c svn_node_kind_t values. 01153 * 01154 * @deprecated Provided for backwards compatibility with the 1.2 API. 01155 */ 01156 SVN_DEPRECATED 01157 svn_error_t * 01158 svn_io_get_dirents(apr_hash_t **dirents, 01159 const char *path, 01160 apr_pool_t *pool); 01161 01162 01163 /** Callback function type for svn_io_dir_walk() */ 01164 typedef svn_error_t * (*svn_io_walk_func_t)(void *baton, 01165 const char *path, 01166 const apr_finfo_t *finfo, 01167 apr_pool_t *pool); 01168 01169 /** This function will recursively walk over the files and directories 01170 * rooted at @a dirname, a utf8-encoded path. For each file or directory, 01171 * @a walk_func is invoked, passing in the @a walk_baton, the utf8-encoded 01172 * full path to the entry, an @c apr_finfo_t structure, and a temporary 01173 * pool for allocations. For any directory, @a walk_func will be invoked 01174 * on the directory itself before being invoked on any subdirectories or 01175 * files within the directory. 01176 * 01177 * The set of information passed to @a walk_func is specified by @a wanted, 01178 * and the items specified by @c APR_FINFO_TYPE and @c APR_FINFO_NAME. 01179 * 01180 * All allocations will be performed in @a pool. 01181 */ 01182 svn_error_t * 01183 svn_io_dir_walk(const char *dirname, 01184 apr_int32_t wanted, 01185 svn_io_walk_func_t walk_func, 01186 void *walk_baton, 01187 apr_pool_t *pool); 01188 01189 /** 01190 * Start @a cmd with @a args, using utf8-encoded @a path as working 01191 * directory. Connect @a cmd's stdin, stdout, and stderr to @a infile, 01192 * @a outfile, and @a errfile, except where they are NULL. Return the 01193 * process handle for the invoked program in @a *cmd_proc. 01194 * 01195 * @a args is a list of utf8-encoded <tt>const char *</tt> arguments, 01196 * terminated by @c NULL. @a args[0] is the name of the program, though it 01197 * need not be the same as @a cmd. 01198 * 01199 * If @a inherit is TRUE, the invoked program inherits its environment from 01200 * the caller and @a cmd, if not absolute, is searched for in PATH. 01201 * Otherwise, the invoked program runs with an empty environment and @a cmd 01202 * must be an absolute path. 01203 * 01204 * @note On some platforms, failure to execute @a cmd in the child process 01205 * will result in error output being written to @a errfile, if non-NULL, and 01206 * a non-zero exit status being returned to the parent process. 01207 * 01208 * @since New in 1.3. 01209 */ 01210 svn_error_t * 01211 svn_io_start_cmd(apr_proc_t *cmd_proc, 01212 const char *path, 01213 const char *cmd, 01214 const char *const *args, 01215 svn_boolean_t inherit, 01216 apr_file_t *infile, 01217 apr_file_t *outfile, 01218 apr_file_t *errfile, 01219 apr_pool_t *pool); 01220 01221 /** 01222 * Wait for the process @a *cmd_proc to complete and optionally retrieve 01223 * its exit code. @a cmd is used only in error messages. 01224 * 01225 * If @a exitcode is not NULL, and SVN_NO_ERROR is returned, @a *exitcode 01226 * will contain the exit code of the process. If @a exitcode is NULL and 01227 * the exit code is non-zero, then an @c SVN_ERR_EXTERNAL_PROGRAM error 01228 * will be returned. 01229 * 01230 * If @a exitwhy is not NULL, and SVN_NO_ERROR is returned, @a *exitwhy 01231 * will indicate why the process terminated. If @a exitwhy is NULL, 01232 * and the exit reason is not @c APR_PROC_CHECK_EXIT(), then an 01233 * @c SVN_ERR_EXTERNAL_PROGRAM error will be returned. 01234 * 01235 * @since New in 1.3. 01236 */ 01237 svn_error_t * 01238 svn_io_wait_for_cmd(apr_proc_t *cmd_proc, 01239 const char *cmd, 01240 int *exitcode, 01241 apr_exit_why_e *exitwhy, 01242 apr_pool_t *pool); 01243 01244 /** Run a command to completion, by first calling svn_io_start_cmd() and 01245 * then calling svn_io_wait_for_cmd(). The parameters correspond to 01246 * the same-named parameters of those two functions. 01247 */ 01248 svn_error_t * 01249 svn_io_run_cmd(const char *path, 01250 const char *cmd, 01251 const char *const *args, 01252 int *exitcode, 01253 apr_exit_why_e *exitwhy, 01254 svn_boolean_t inherit, 01255 apr_file_t *infile, 01256 apr_file_t *outfile, 01257 apr_file_t *errfile, 01258 apr_pool_t *pool); 01259 01260 /** Invoke the configured @c diff program, with @a user_args (an array 01261 * of utf8-encoded @a num_user_args arguments) if they are specified 01262 * (that is, if @a user_args is non-NULL), or "-u" if they are not. 01263 * If @a user_args is NULL, the value of @a num_user_args is ignored. 01264 * 01265 * Diff runs in utf8-encoded @a dir, and its exit status is stored in 01266 * @a exitcode, if it is not @c NULL. 01267 * 01268 * If @a label1 and/or @a label2 are not NULL they will be passed to the diff 01269 * process as the arguments of "-L" options. @a label1 and @a label2 are also 01270 * in utf8, and will be converted to native charset along with the other args. 01271 * 01272 * @a from is the first file passed to diff, and @a to is the second. The 01273 * stdout of diff will be sent to @a outfile, and the stderr to @a errfile. 01274 * 01275 * @a diff_cmd must be non-NULL. 01276 * 01277 * Do all allocation in @a pool. 01278 * @since New in 1.6.0. 01279 */ 01280 svn_error_t * 01281 svn_io_run_diff2(const char *dir, 01282 const char *const *user_args, 01283 int num_user_args, 01284 const char *label1, 01285 const char *label2, 01286 const char *from, 01287 const char *to, 01288 int *exitcode, 01289 apr_file_t *outfile, 01290 apr_file_t *errfile, 01291 const char *diff_cmd, 01292 apr_pool_t *pool); 01293 01294 /** Similar to svn_io_run_diff2() but with @diff_cmd encoded in internal 01295 * encoding used by APR. 01296 * 01297 * @deprecated Provided for backwards compatibility with the 1.5 API. */ 01298 SVN_DEPRECATED 01299 svn_error_t * 01300 svn_io_run_diff(const char *dir, 01301 const char *const *user_args, 01302 int num_user_args, 01303 const char *label1, 01304 const char *label2, 01305 const char *from, 01306 const char *to, 01307 int *exitcode, 01308 apr_file_t *outfile, 01309 apr_file_t *errfile, 01310 const char *diff_cmd, 01311 apr_pool_t *pool); 01312 01313 01314 01315 /** Invoke the configured @c diff3 program, in utf8-encoded @a dir 01316 * like this: 01317 * 01318 * diff3 -E -m @a mine @a older @a yours > @a merged 01319 * 01320 * (See the diff3 documentation for details.) 01321 * 01322 * If @a user_args is non-NULL, replace "-E" with the <tt>const char*</tt> 01323 * elements that @a user_args contains. 01324 * 01325 * @a mine, @a older and @a yours are utf8-encoded paths (relative to 01326 * @a dir or absolute) to three files that already exist. 01327 * 01328 * @a merged is an open file handle, and is left open after the merge 01329 * result is written to it. (@a merged should *not* be the same file 01330 * as @a mine, or nondeterministic things may happen!) 01331 * 01332 * @a mine_label, @a older_label, @a yours_label are utf8-encoded label 01333 * parameters for diff3's -L option. Any of them may be @c NULL, in 01334 * which case the corresponding @a mine, @a older, or @a yours parameter is 01335 * used instead. 01336 * 01337 * Set @a *exitcode to diff3's exit status. If @a *exitcode is anything 01338 * other than 0 or 1, then return @c SVN_ERR_EXTERNAL_PROGRAM. (Note the 01339 * following from the diff3 info pages: "An exit status of 0 means 01340 * `diff3' was successful, 1 means some conflicts were found, and 2 01341 * means trouble.") 01342 * 01343 * @a diff3_cmd must be non-NULL. 01344 * 01345 * Do all allocation in @a pool. 01346 * 01347 * @since New in 1.4. 01348 */ 01349 svn_error_t * 01350 svn_io_run_diff3_3(int *exitcode, 01351 const char *dir, 01352 const char *mine, 01353 const char *older, 01354 const char *yours, 01355 const char *mine_label, 01356 const char *older_label, 01357 const char *yours_label, 01358 apr_file_t *merged, 01359 const char *diff3_cmd, 01360 const apr_array_header_t *user_args, 01361 apr_pool_t *pool); 01362 01363 /** Similar to svn_io_run_diff3_3(), but with @a diff3_cmd encoded in 01364 * internal encoding used by APR. 01365 * 01366 * @deprecated Provided for backwards compatibility with the 1.5 API. 01367 * @since New in 1.4. 01368 */ 01369 SVN_DEPRECATED 01370 svn_error_t * 01371 svn_io_run_diff3_2(int *exitcode, 01372 const char *dir, 01373 const char *mine, 01374 const char *older, 01375 const char *yours, 01376 const char *mine_label, 01377 const char *older_label, 01378 const char *yours_label, 01379 apr_file_t *merged, 01380 const char *diff3_cmd, 01381 const apr_array_header_t *user_args, 01382 apr_pool_t *pool); 01383 01384 /** Similar to svn_io_run_diff3_2(), but with @a user_args set to @c NULL. 01385 * 01386 * @deprecated Provided for backwards compatibility with the 1.3 API. 01387 */ 01388 SVN_DEPRECATED 01389 svn_error_t * 01390 svn_io_run_diff3(const char *dir, 01391 const char *mine, 01392 const char *older, 01393 const char *yours, 01394 const char *mine_label, 01395 const char *older_label, 01396 const char *yours_label, 01397 apr_file_t *merged, 01398 int *exitcode, 01399 const char *diff3_cmd, 01400 apr_pool_t *pool); 01401 01402 01403 /** Parse utf8-encoded @a mimetypes_file as a MIME types file (such as 01404 * is provided with Apache HTTP Server), and set @a *type_map to a 01405 * hash mapping <tt>const char *</tt> filename extensions to 01406 * <tt>const char *</tt> MIME types. 01407 * 01408 * @since New in 1.5. 01409 */ 01410 svn_error_t * 01411 svn_io_parse_mimetypes_file(apr_hash_t **type_map, 01412 const char *mimetypes_file, 01413 apr_pool_t *pool); 01414 01415 01416 /** Examine utf8-encoded @a file to determine if it can be described by a 01417 * known (as in, known by this function) Multipurpose Internet Mail 01418 * Extension (MIME) type. If so, set @a *mimetype to a character string 01419 * describing the MIME type, else set it to @c NULL. 01420 * 01421 * If not @c NULL, @a mimetype_map is a hash mapping <tt>const char *</tt> 01422 * filename extensions to <tt>const char *</tt> MIME types, and is the 01423 * first source consulted regarding @a file's MIME type. 01424 * 01425 * Use @a pool for any necessary allocations. 01426 * 01427 * @since New in 1.5. 01428 */ 01429 svn_error_t * 01430 svn_io_detect_mimetype2(const char **mimetype, 01431 const char *file, 01432 apr_hash_t *mimetype_map, 01433 apr_pool_t *pool); 01434 01435 01436 /** Like svn_io_detect_mimetype2, but with @a mimetypes_map set to 01437 * @c NULL. 01438 * 01439 * @deprecated Provided for backward compatibility with the 1.4 API 01440 */ 01441 SVN_DEPRECATED 01442 svn_error_t * 01443 svn_io_detect_mimetype(const char **mimetype, 01444 const char *file, 01445 apr_pool_t *pool); 01446 01447 01448 /** Wrapper for apr_file_open(). @a fname is utf8-encoded. */ 01449 svn_error_t * 01450 svn_io_file_open(apr_file_t **new_file, 01451 const char *fname, 01452 apr_int32_t flag, 01453 apr_fileperms_t perm, 01454 apr_pool_t *pool); 01455 01456 01457 /** Wrapper for apr_file_close(). */ 01458 svn_error_t * 01459 svn_io_file_close(apr_file_t *file, 01460 apr_pool_t *pool); 01461 01462 01463 /** Wrapper for apr_file_getc(). */ 01464 svn_error_t * 01465 svn_io_file_getc(char *ch, 01466 apr_file_t *file, 01467 apr_pool_t *pool); 01468 01469 01470 /** Wrapper for apr_file_info_get(). */ 01471 svn_error_t * 01472 svn_io_file_info_get(apr_finfo_t *finfo, 01473 apr_int32_t wanted, 01474 apr_file_t *file, 01475 apr_pool_t *pool); 01476 01477 01478 /** Wrapper for apr_file_read(). */ 01479 svn_error_t * 01480 svn_io_file_read(apr_file_t *file, 01481 void *buf, 01482 apr_size_t *nbytes, 01483 apr_pool_t *pool); 01484 01485 01486 /** Wrapper for apr_file_read_full(). */ 01487 svn_error_t * 01488 svn_io_file_read_full(apr_file_t *file, 01489 void *buf, 01490 apr_size_t nbytes, 01491 apr_size_t *bytes_read, 01492 apr_pool_t *pool); 01493 01494 01495 /** Wrapper for apr_file_seek(). */ 01496 svn_error_t * 01497 svn_io_file_seek(apr_file_t *file, 01498 apr_seek_where_t where, 01499 apr_off_t *offset, 01500 apr_pool_t *pool); 01501 01502 01503 /** Wrapper for apr_file_write(). */ 01504 svn_error_t * 01505 svn_io_file_write(apr_file_t *file, 01506 const void *buf, 01507 apr_size_t *nbytes, 01508 apr_pool_t *pool); 01509 01510 01511 /** Wrapper for apr_file_write_full(). */ 01512 svn_error_t * 01513 svn_io_file_write_full(apr_file_t *file, 01514 const void *buf, 01515 apr_size_t nbytes, 01516 apr_size_t *bytes_written, 01517 apr_pool_t *pool); 01518 01519 /** 01520 * Open a unique file in @a dirpath, and write @a nbytes from @a buf to 01521 * the file before closing it. Return the name of the newly created file 01522 * in @a *tmp_path, allocated in @a pool. 01523 * 01524 * If @a dirpath is @c NULL, use the path returned from svn_io_temp_dir(). 01525 * (Note that when using the system-provided temp directory, it may not 01526 * be possibly to atomically rename the resulting file due to cross-device 01527 * issues.) 01528 * 01529 * The file will be deleted according to @a delete_when. 01530 * 01531 * @since New in 1.6. 01532 */ 01533 svn_error_t * 01534 svn_io_write_unique(const char **tmp_path, 01535 const char *dirpath, 01536 const void *buf, 01537 apr_size_t nbytes, 01538 svn_io_file_del_t delete_when, 01539 apr_pool_t *pool); 01540 01541 /** Wrapper for apr_file_trunc(). 01542 * @since New in 1.6. */ 01543 svn_error_t * 01544 svn_io_file_trunc(apr_file_t *file, 01545 apr_off_t offset, 01546 apr_pool_t *pool); 01547 01548 01549 /** Wrapper for apr_stat(). @a fname is utf8-encoded. */ 01550 svn_error_t * 01551 svn_io_stat(apr_finfo_t *finfo, 01552 const char *fname, 01553 apr_int32_t wanted, 01554 apr_pool_t *pool); 01555 01556 01557 /** Wrapper for apr_file_rename(). @a from_path and @a to_path are 01558 * utf8-encoded. 01559 */ 01560 svn_error_t * 01561 svn_io_file_rename(const char *from_path, 01562 const char *to_path, 01563 apr_pool_t *pool); 01564 01565 01566 /** Move the file from @a from_path to @a to_path, even across device 01567 * boundaries. Overwrite @a to_path if it exists. 01568 * 01569 * @note This function is different from svn_io_file_rename in that the 01570 * latter fails in the 'across device boundaries' case. 01571 * 01572 * @since New in 1.3. 01573 */ 01574 svn_error_t * 01575 svn_io_file_move(const char *from_path, 01576 const char *to_path, 01577 apr_pool_t *pool); 01578 01579 01580 /** Wrapper for apr_dir_make(). @a path is utf8-encoded. */ 01581 svn_error_t * 01582 svn_io_dir_make(const char *path, 01583 apr_fileperms_t perm, 01584 apr_pool_t *pool); 01585 01586 /** Same as svn_io_dir_make(), but sets the hidden attribute on the 01587 directory on systems that support it. */ 01588 svn_error_t * 01589 svn_io_dir_make_hidden(const char *path, 01590 apr_fileperms_t perm, 01591 apr_pool_t *pool); 01592 01593 /** 01594 * Same as svn_io_dir_make(), but attempts to set the sgid on the 01595 * directory on systems that support it. Does not return an error if 01596 * the attempt to set the sgid bit fails. On Unix filesystems, 01597 * setting the sgid bit on a directory ensures that files and 01598 * subdirectories created within inherit group ownership from the 01599 * parent instead of from the primary gid. 01600 * 01601 * @since New in 1.1. 01602 */ 01603 svn_error_t * 01604 svn_io_dir_make_sgid(const char *path, 01605 apr_fileperms_t perm, 01606 apr_pool_t *pool); 01607 01608 /** Wrapper for apr_dir_open(). @a dirname is utf8-encoded. */ 01609 svn_error_t * 01610 svn_io_dir_open(apr_dir_t **new_dir, 01611 const char *dirname, 01612 apr_pool_t *pool); 01613 01614 01615 /** Wrapper for apr_dir_remove(). @a dirname is utf8-encoded. 01616 * @note This function has this name to avoid confusion with 01617 * svn_io_remove_dir2(), which is recursive. 01618 */ 01619 svn_error_t * 01620 svn_io_dir_remove_nonrecursive(const char *dirname, 01621 apr_pool_t *pool); 01622 01623 01624 /** Wrapper for apr_dir_read(). Ensures that @a finfo->name is 01625 * utf8-encoded, which means allocating @a finfo->name in @a pool, 01626 * which may or may not be the same as @a finfo's pool. Use @a pool 01627 * for error allocation as well. 01628 */ 01629 svn_error_t * 01630 svn_io_dir_read(apr_finfo_t *finfo, 01631 apr_int32_t wanted, 01632 apr_dir_t *thedir, 01633 apr_pool_t *pool); 01634 01635 01636 01637 /** Version/format files. 01638 * 01639 * @defgroup svn_io_format_files Version/format files 01640 * @{ 01641 */ 01642 01643 /** Set @a *version to the integer that starts the file at @a path. If the 01644 * file does not begin with a series of digits followed by a newline, 01645 * return the error @c SVN_ERR_BAD_VERSION_FILE_FORMAT. Use @a pool for 01646 * all allocations. 01647 */ 01648 svn_error_t * 01649 svn_io_read_version_file(int *version, 01650 const char *path, 01651 apr_pool_t *pool); 01652 01653 /** Create (or overwrite) the file at @a path with new contents, 01654 * formatted as a non-negative integer @a version followed by a single 01655 * newline. On successful completion the file will be read-only. Use 01656 * @a pool for all allocations. 01657 */ 01658 svn_error_t * 01659 svn_io_write_version_file(const char *path, 01660 int version, 01661 apr_pool_t *pool); 01662 01663 /** @} */ 01664 01665 #ifdef __cplusplus 01666 } 01667 #endif /* __cplusplus */ 01668 01669 #endif /* SVN_IO_H */