Main Page   Modules   Data Structures   File List   Data Fields   Globals   Related Pages  

svn_io.h

Go to the documentation of this file.
00001 /**
00002  * @copyright
00003  * ====================================================================
00004  * Copyright (c) 2000-2004 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 Subversion I/O definitions
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_file_io.h>
00031 #include <apr_thread_proc.h>
00032 
00033 #include "svn_types.h"
00034 #include "svn_error.h"
00035 #include "svn_string.h"
00036 
00037 #ifdef __cplusplus
00038 extern "C" {
00039 #endif /* __cplusplus */
00040 
00041 
00042 
00043 /** Determine the @a kind of @a path.
00044  *
00045  * If utf8-encoded @a path exists, set @a *kind to the appropriate kind,
00046  * else set it to @c svn_node_unknown. 
00047  *
00048  * If @a path is a file, @a *kind is set to @c svn_node_file.
00049  *
00050  * If @a path is a directory, @a *kind is set to @c svn_node_dir.
00051  *
00052  * If @a path does not exist in its final component, @a *kind is set to
00053  * @c svn_node_none.  
00054  *
00055  * If intermediate directories on the way to @a path don't exist, an
00056  * error is returned, and @a *kind's value is undefined.
00057  */
00058 svn_error_t *svn_io_check_path (const char *path,
00059                                 svn_node_kind_t *kind,
00060                                 apr_pool_t *pool);
00061 
00062 /**
00063  * @since New in 1.1.
00064  *
00065  * Like svn_io_check_path(), but also set *is_special to @c TRUE if
00066  * the path is not a normal file.
00067  */
00068 svn_error_t *svn_io_check_special_path (const char *path,
00069                                         svn_node_kind_t *kind,
00070                                         svn_boolean_t *is_special,
00071                                         apr_pool_t *pool);
00072 
00073 /** Like svn_io_check_path(), but resolve symlinks.  This returns the
00074     same varieties of @a kind as svn_io_check_path(). */ 
00075 svn_error_t *svn_io_check_resolved_path (const char *path,
00076                                          svn_node_kind_t *kind,
00077                                          apr_pool_t *pool);
00078 
00079 
00080 /** Open a new file (for writing) with a unique name based on utf-8
00081  * encoded @a path, in the same directory as @a path.  The file handle is
00082  * returned in @a *f, and the name, which ends with @a suffix, is returned
00083  * in @a *unique_name_p, also utf8-encoded.  If @a delete_on_close is set,
00084  * then the @c APR_DELONCLOSE flag will be used when opening the file. The
00085  * @c APR_BUFFERED flag will always be used.
00086  *
00087  * @a suffix may not be null.
00088  *
00089  * The first attempt will just append @a suffix.  If the result is not
00090  * a unique name, then subsequent attempts will append a dot,
00091  * followed by an iteration number ("2", then "3", and so on),
00092  * followed by the suffix.  For example, if @a path is
00093  *
00094  *    tests/t1/A/D/G/pi
00095  *
00096  * then successive calls to
00097  *
00098  *    @c svn_io_open_unique_file(&f, &unique_name, @a path, ".tmp", pool) 
00099  *
00100  * will open
00101  *
00102  *    tests/t1/A/D/G/pi.tmp
00103  *    tests/t1/A/D/G/pi.2.tmp
00104  *    tests/t1/A/D/G/pi.3.tmp
00105  *    tests/t1/A/D/G/pi.4.tmp
00106  *    tests/t1/A/D/G/pi.5.tmp
00107  *    ...
00108  *
00109  * @a *unique_name_p will never be exactly the same as @a path, even
00110  * if @a path does not exist.
00111  * 
00112  * It doesn't matter if @a path is a file or directory, the unique name will
00113  * be in @a path's parent either way.
00114  *
00115  * Allocate @a *f and @a *unique_name_p in @a pool.
00116  *
00117  * If no unique name can be found, @c SVN_ERR_IO_UNIQUE_NAMES_EXHAUSTED is
00118  * the error returned.
00119  *
00120  * Claim of Historical Inevitability: this function was written
00121  * because 
00122  *
00123  *    - @c tmpnam() is not thread-safe.
00124  *    - @c tempname() tries standard system tmp areas first.
00125  */
00126 svn_error_t *svn_io_open_unique_file (apr_file_t **f,
00127                                       const char **unique_name_p,
00128                                       const char *path,
00129                                       const char *suffix,
00130                                       svn_boolean_t delete_on_close,
00131                                       apr_pool_t *pool);
00132 
00133 /**
00134  * @since New in 1.1.
00135  *
00136  * Like svn_io_open_unique_file, except that instead of creating a
00137  * file, a symlink is generated that references the path @a dest.
00138  */
00139 svn_error_t *svn_io_create_unique_link (const char **unique_name_p,
00140                                         const char *path,
00141                                         const char *dest,
00142                                         const char *suffix,
00143                                         apr_pool_t *pool);
00144 
00145 
00146 /**
00147  * @since New in 1.1.
00148  *
00149  * Set @a dest to the path that the symlink at @a path references.
00150  * Allocate the string from @a pool.
00151  */
00152 svn_error_t *svn_io_read_link (svn_string_t **dest,
00153                                const char *path,
00154                                apr_pool_t *pool);
00155 
00156 
00157 /** Set @a dir to a directory path (allocated in @a pool) deemed
00158  * usable for the creation of temporary files and subdirectories.
00159  */
00160 svn_error_t *svn_io_temp_dir (const char **dir,
00161                               apr_pool_t *pool);
00162 
00163 
00164 /** Copy @a src to @a dst atomically.  Overwrite @a dst if it exists, else
00165  * create it.  Both @a src and @a dst are utf8-encoded filenames.  If
00166  * @a copy_perms is true, set @a dst's permissions to match those of @a src.
00167  */
00168 svn_error_t *svn_io_copy_file (const char *src,
00169                                const char *dst,
00170                                svn_boolean_t copy_perms,
00171                                apr_pool_t *pool);
00172 
00173 /** 
00174  * @since New in 1.1.
00175  *
00176  * Copy symbolic link @a src to @a dst atomically.  Overwrite @a dst
00177  * if it exists, else create it.  Both @a src and @a dst are
00178  * utf8-encoded filenames.  After copying, the @a dst link will point
00179  * to the same thing @a src does.
00180  */
00181 svn_error_t *svn_io_copy_link (const char *src,
00182                                const char *dst,
00183                                apr_pool_t *pool);
00184 
00185 
00186 /** Recursively copy directory @a src into @a dst_parent, as a new entry named
00187  * @a dst_basename.  If @a dst_basename already exists in @a dst_parent, 
00188  * return error.  @a copy_perms will be passed through to @c svn_io_copy_file 
00189  * when any files are copied.  @a src, @a dst_parent, and @a dst_basename are 
00190  * all utf8-encoded.
00191  *
00192  * If @a cancel_func is non-null, invoke it with @a cancel_baton at
00193  * various points during the operation.  If it returns any error
00194  * (typically @c SVN_ERR_CANCELLED), return that error immediately.
00195  */ 
00196 svn_error_t *svn_io_copy_dir_recursively (const char *src,
00197                                           const char *dst_parent,
00198                                           const char *dst_basename,
00199                                           svn_boolean_t copy_perms,
00200                                           svn_cancel_func_t cancel_func,
00201                                           void *cancel_baton,
00202                                           apr_pool_t *pool);
00203 
00204 
00205 
00206 /** Create directory @a path on the file system, creating intermediate
00207  * directories as required, like <tt>mkdir -p</tt>.  Report no error if @a 
00208  * path already exists.  @a path is utf8-encoded.
00209  *
00210  * This is essentially a wrapper for @c apr_dir_make_recursive(), passing
00211  * @c APR_OS_DEFAULT as the permissions.
00212  */
00213 svn_error_t *svn_io_make_dir_recursively (const char *path, apr_pool_t *pool);
00214 
00215 
00216 /** Set @a *is_empty_p to @c TRUE if directory @a path is empty, else to 
00217  * @c FALSE if it is not empty.  @a path must be a directory, and is
00218  * utf8-encoded.  Use @a pool for temporary allocation.
00219  */
00220 svn_error_t *
00221 svn_io_dir_empty (svn_boolean_t *is_empty_p,
00222                   const char *path,
00223                   apr_pool_t *pool);
00224 
00225 
00226 /** Append @a src to @a dst.  @a dst will be appended to if it exists, else it
00227  * will be created.  Both @a src and @a dst are utf8-encoded.
00228  */
00229 svn_error_t *svn_io_append_file (const char *src,
00230                                  const char *dst,
00231                                  apr_pool_t *pool);
00232 
00233 
00234 /** Make a file as read-only as the operating system allows.
00235  * @a path is the utf8-encoded path to the file. If @a ignore_enoent is
00236  * @c TRUE, don't fail if the target file doesn't exist.
00237  */
00238 svn_error_t *svn_io_set_file_read_only (const char *path,
00239                                         svn_boolean_t ignore_enoent,
00240                                         apr_pool_t *pool);
00241 
00242 
00243 /** Make a file as writable as the operating system allows.
00244  * @a path is the utf8-encoded path to the file.  If @a ignore_enoent is
00245  * @c TRUE, don't fail if the target file doesn't exist.
00246  * @warning On Unix this function will do the equivlanet of chmod a+w path.
00247  * If this is not what you want you should not use this function, but rather
00248  * use apr_file_perms_set().
00249  */
00250 svn_error_t *svn_io_set_file_read_write (const char *path,
00251                                          svn_boolean_t ignore_enoent,
00252                                          apr_pool_t *pool);
00253 
00254 /** Toggle a file's "executability".
00255  *
00256  * When making the file executable on operating systems with unix style
00257  * permissions, never add an execute permission where there is not
00258  * already a read permission: that is, only make the file executable
00259  * for the user, group or world if the corresponding read permission
00260  * is already set for user, group or world.
00261  *
00262  * When making the file non-executable on operating systems with unix style
00263  * permissions, remove all execute permissions.
00264  *
00265  * On other operating systems, toggle the file's "executability" as much as
00266  * the operating system allows.
00267  *
00268  * @a path is the utf8-encoded path to the file.  If @a executable
00269  * is @c TRUE, then make the file executable.  If @c FALSE, make in
00270  * non-executable.  If @a ignore_enoent is @c TRUE, don't fail if the target
00271  * file doesn't exist.
00272  */
00273 svn_error_t *svn_io_set_file_executable (const char *path,
00274                                          svn_boolean_t executable,
00275                                          svn_boolean_t ignore_enoent,
00276                                          apr_pool_t *pool);
00277 
00278 /** Determine whether a file is executable by the current user.  
00279  * Set @a *executable to @c TRUE if the file @a path is executable by the 
00280  * current user, otherwise set it to @c FALSE.  
00281  * 
00282  * On Windows and on platforms without userids, always returns @c FALSE.
00283  */
00284 svn_error_t *svn_io_is_file_executable(svn_boolean_t *executable, 
00285                                        const char *path, 
00286                                        apr_pool_t *pool);
00287 
00288 
00289 /** Read a line from @a file into @a buf, but not exceeding @a *limit bytes.
00290  * Does not include newline, instead '\\0' is put there.
00291  * Length (as in strlen) is returned in @a *limit.
00292  * @a buf should be pre-allocated.
00293  * @a file should be already opened. 
00294  *
00295  * When the file is out of lines, @c APR_EOF will be returned.
00296  */
00297 svn_error_t *
00298 svn_io_read_length_line (apr_file_t *file, char *buf, apr_size_t *limit,
00299                          apr_pool_t *pool);
00300 
00301 
00302 /** Set @a *apr_time to the time of last modification of the contents of the
00303  * file @a path.  @a path is utf8-encoded.
00304  *
00305  * Note: this is the APR mtime which corresponds to the traditional mtime
00306  * on Unix, and the last write time on Windows.
00307  */
00308 svn_error_t *svn_io_file_affected_time (apr_time_t *apr_time,
00309                                         const char *path,
00310                                         apr_pool_t *pool);
00311 
00312 /** Set the timestamp of file @a path to @a apr_time.  @a path is
00313  *  utf8-encoded.
00314  *
00315  * Note: this is the APR mtime which corresponds to the traditional mtime
00316  * on Unix, and the last write time on Windows.
00317  */
00318 svn_error_t *svn_io_set_file_affected_time (apr_time_t apr_time,
00319                                             const char *path,
00320                                             apr_pool_t *pool);
00321 
00322 
00323 
00324 /** Set @a *different_p to non-zero if @a file1 and @a file2 have different
00325  * sizes, else set to zero.  Both @a file1 and @a file2 are utf8-encoded.
00326  *
00327  * Setting @a *different_p to zero does not mean the files definitely
00328  * have the same size, it merely means that the sizes are not
00329  * definitely different.  That is, if the size of one or both files
00330  * cannot be determined, then the sizes are not known to be different,
00331  * so @a *different_p is set to 0.
00332  */
00333 svn_error_t *svn_io_filesizes_different_p (svn_boolean_t *different_p,
00334                                            const char *file1,
00335                                            const char *file2,
00336                                            apr_pool_t *pool);
00337 
00338 
00339 /** Put the md5 checksum of @a file into @a digest.
00340  * @a digest points to @c APR_MD5_DIGESTSIZE bytes of storage.
00341  * Use @a pool only for temporary allocations.
00342  */
00343 svn_error_t *svn_io_file_checksum (unsigned char digest[],
00344                                    const char *file,
00345                                    apr_pool_t *pool);
00346 
00347 
00348 /* Set @a *same to non-zero if @a file1 and @a file2 have the same
00349  * contents, else set it to zero.  Use @a pool for temporary allocations.
00350  */
00351 svn_error_t *svn_io_files_contents_same_p (svn_boolean_t *same,
00352                                            const char *file1,
00353                                            const char *file2,
00354                                            apr_pool_t *pool);
00355 
00356 /** Create file at @a file with contents @a contents.
00357  * will be created.  Path @a file is utf8-encoded.
00358  * Use @a pool for memory allocations.
00359  */
00360 svn_error_t *svn_io_file_create (const char *file,
00361                                  const char *contents,
00362                                  apr_pool_t *pool);
00363 
00364 /**
00365  * @deprecated Provided for backward compatibility with the 1.0.0 API.
00366  *
00367  * Lock file at @a lock_file. If @exclusive is TRUE,
00368  * obtain exclusive lock, otherwise obtain shared lock.
00369  * Lock will be automaticaly released when @a pool is cleared or destroyed.
00370  * Use @a pool for memory allocations.
00371  */
00372 svn_error_t *svn_io_file_lock (const char *lock_file,
00373                                svn_boolean_t exclusive,
00374                                apr_pool_t *pool);
00375 
00376 /**
00377  * @since New in 1.1.
00378  *
00379  * Lock file at @a lock_file. If @exclusive is TRUE,
00380  * obtain exclusive lock, otherwise obtain shared lock.
00381  *
00382  * If @a nonblocking is TRUE, do not wait for the lock if it
00383  * is not available: throw an error instead.
00384  *
00385  * Lock will be automaticaly released when @a pool is cleared or destroyed.
00386  * Use @a pool for memory allocations.
00387  */
00388 svn_error_t *svn_io_file_lock2 (const char *lock_file,
00389                                 svn_boolean_t exclusive,
00390                                 svn_boolean_t nonblocking,
00391                                 apr_pool_t *pool);
00392 /**
00393  * @since New in 1.1.
00394  *
00395  * Flush any unwritten data from @a file to disk.  Use @a pool for
00396  *  memory allocations.
00397  */
00398 svn_error_t *svn_io_file_flush_to_disk (apr_file_t *file,
00399                                         apr_pool_t *pool);
00400 
00401 /** Copy file @a file from location @a src_path to location @a dest_path.
00402  * Use @a pool for memory allocations.
00403  */
00404 svn_error_t *svn_io_dir_file_copy (const char *src_path, 
00405                                    const char *dest_path, 
00406                                    const char *file,
00407                                    apr_pool_t *pool);
00408 
00409 
00410 /** Generic byte-streams
00411  *
00412  * @defgroup svn_io_byte_streams generic byte streams
00413  * @{
00414  */
00415 
00416 /** An abstract stream of bytes--either incoming or outgoing or both.
00417  *
00418  * The creator of a stream sets functions to handle read and write.
00419  * Both of these handlers accept a baton whose value is determined at
00420  * stream creation time; this baton can point to a structure
00421  * containing data associated with the stream.  If a caller attempts
00422  * to invoke a handler which has not been set, it will generate a
00423  * runtime assertion failure.  The creator can also set a handler for
00424  * close requests so that it can flush buffered data or whatever;
00425  * if a close handler is not specified, a close request on the stream
00426  * will simply be ignored.  Note that svn_stream_close() does not
00427  * deallocate the memory used to allocate the stream structure; free
00428  * the pool you created the stream in to free that memory.
00429  *
00430  * The read and write handlers accept length arguments via pointer.
00431  * On entry to the handler, the pointed-to value should be the amount
00432  * of data which can be read or the amount of data to write.  When the
00433  * handler returns, the value is reset to the amount of data actually
00434  * read or written.  Handlers are obliged to complete a read or write
00435  * to the maximum extent possible; thus, a short read with no
00436  * associated error implies the end of the input stream, and a short
00437  * write should never occur without an associated error.
00438  */
00439 typedef struct svn_stream_t svn_stream_t;
00440 
00441 
00442 
00443 /** Read handler function for a generic stream.  */
00444 typedef svn_error_t *(*svn_read_fn_t) (void *baton,
00445                                        char *buffer,
00446                                        apr_size_t *len);
00447 
00448 /** Write handler function for a generic stream.  */
00449 typedef svn_error_t *(*svn_write_fn_t) (void *baton,
00450                                         const char *data,
00451                                         apr_size_t *len);
00452 
00453 /** Close handler function for a generic stream.  */
00454 typedef svn_error_t *(*svn_close_fn_t) (void *baton);
00455 
00456 
00457 /** Creating a generic stream.  */
00458 svn_stream_t *svn_stream_create (void *baton, apr_pool_t *pool);
00459 
00460 /** Set @a stream's baton to @a baton */
00461 void svn_stream_set_baton (svn_stream_t *stream, void *baton);
00462 
00463 /** Set @a stream's read function to @a read_fn */
00464 void svn_stream_set_read (svn_stream_t *stream, svn_read_fn_t read_fn);
00465 
00466 /** Set @a stream's write function to @a write_fn */
00467 void svn_stream_set_write (svn_stream_t *stream, svn_write_fn_t write_fn);
00468 
00469 /** Set @a stream's close function to @a close_fn */
00470 void svn_stream_set_close (svn_stream_t *stream, svn_close_fn_t close_fn);
00471 
00472 
00473 /** Convenience function to create a generic stream which is empty.  */
00474 svn_stream_t *svn_stream_empty (apr_pool_t *pool);
00475 
00476 
00477 /** Convenience function for creating streams which operate on APR
00478  * files.  For convenience, if @a file is NULL then @c svn_stream_empty(pool) 
00479  * is returned.  Note that the stream returned by these operations is not 
00480  * considered to "own" the underlying file, meaning that @c svn_stream_close() 
00481  * on the stream will not close the file.
00482  */
00483 svn_stream_t *svn_stream_from_aprfile (apr_file_t *file, apr_pool_t *pool);
00484 
00485 /** Set @a *out to a generic stream connected to stdout, allocated in 
00486  * @a pool.  The stream and its underlying APR handle will be closed
00487  * when @a pool is cleared or destroyed.
00488  */
00489 svn_error_t *svn_stream_for_stdout (svn_stream_t **out, apr_pool_t *pool);
00490 
00491 /** Return a generic stream connected to stringbuf @a str.  Allocate the
00492  * stream in @a pool.
00493  */
00494 svn_stream_t *svn_stream_from_stringbuf (svn_stringbuf_t *str,
00495                                          apr_pool_t *pool);
00496 
00497 /** Return a stream that decompresses all data read and compresses all
00498  * data written. The stream @a stream is used to read and write all
00499  * compressed data. All compression data structures are allocated on
00500  * @a pool. If compression support is not compiled in then @c
00501  * svn_stream_compressed() returns @a stream unmodified. Make sure you
00502  * call @c svn_stream_close() on the stream returned by this function,
00503  * so that all data are flushed and cleaned up.
00504  */
00505 svn_stream_t *svn_stream_compressed (svn_stream_t *stream, 
00506                                      apr_pool_t *pool);
00507 
00508 /** Read from a generic stream. */
00509 svn_error_t *svn_stream_read (svn_stream_t *stream, char *buffer,
00510                               apr_size_t *len);
00511 
00512 /** Write to a generic stream. */
00513 svn_error_t *svn_stream_write (svn_stream_t *stream, const char *data,
00514                                apr_size_t *len);
00515 
00516 /** Close a generic stream. */
00517 svn_error_t *svn_stream_close (svn_stream_t *stream);
00518 
00519 
00520 /** Write to @a stream using a printf-style @a fmt specifier, passed through
00521  * @c apr_psprintf using memory from @a pool.
00522  */
00523 svn_error_t *svn_stream_printf (svn_stream_t *stream,
00524                                 apr_pool_t *pool,
00525                                 const char *fmt,
00526                                 ...)
00527        __attribute__ ((format(printf, 3, 4)));
00528 
00529 /** Allocate @a *stringbuf in @a pool, and read into it one line (terminated
00530  * by @a eol) from @a stream. The line-terminator is read from the stream,
00531  * but is not added to the end of the stringbuf.  Instead, the stringbuf
00532  * ends with a usual '\\0'.
00533  *
00534  * If @a stream runs out of bytes before encountering a line-terminator,
00535  * then set @a *eof to @c TRUE, otherwise set @a *eof to FALSE.
00536  */
00537 svn_error_t *
00538 svn_stream_readline (svn_stream_t *stream,
00539                      svn_stringbuf_t **stringbuf,
00540                      const char *eol,
00541                      svn_boolean_t *eof,
00542                      apr_pool_t *pool);
00543 
00544 /**
00545  * @since New in 1.1.
00546  *
00547  * Read the contents of the readable stream @a from and write them to the
00548  * writable stream @a to.
00549  */
00550 svn_error_t *svn_stream_copy (svn_stream_t *from, svn_stream_t *to,
00551                               apr_pool_t *pool);
00552 
00553 /** @} */
00554 
00555 /** Sets @a *result to a string containing the contents of @a filename, a
00556  * utf8-encoded path. 
00557  *
00558  * If @a filename is "-", return the error @c SVN_ERR_UNSUPPORTED_FEATURE
00559  * and don't touch @a *result.
00560  *
00561  * ### Someday, "-" will fill @a *result from stdin.  The problem right
00562  * now is that if the same command invokes the editor, stdin is crap,
00563  * and the editor acts funny or dies outright.  One solution is to
00564  * disallow stdin reading and invoking the editor, but how to do that
00565  * reliably?
00566  */
00567 svn_error_t *svn_stringbuf_from_file (svn_stringbuf_t **result, 
00568                                       const char *filename, 
00569                                       apr_pool_t *pool);
00570 
00571 /** Sets @a *result to a string containing the contents of the already opened
00572  * @a file.  Reads from the current position in file to the end.  Does not
00573  * close the file or reset the cursor position.
00574  */
00575 svn_error_t *svn_stringbuf_from_aprfile (svn_stringbuf_t **result,
00576                                          apr_file_t *file,
00577                                          apr_pool_t *pool);
00578 
00579 /** Remove file @a path, a utf8-encoded path.  This wraps @c apr_file_remove(), 
00580  * converting any error to a Subversion error.
00581  */
00582 svn_error_t *svn_io_remove_file (const char *path, apr_pool_t *pool);
00583 
00584 /** Recursively remove directory @a path.  @a path is utf8-encoded. */
00585 svn_error_t *svn_io_remove_dir (const char *path, apr_pool_t *pool);
00586 
00587 
00588 /** Read all of the disk entries in directory @a path, a utf8-encoded
00589  * path.  Return a @a dirents hash mapping dirent names (<tt>char *</tt>) to
00590  * enumerated dirent filetypes (@c svn_node_kind_t *).
00591  *
00592  * Note:  the `.' and `..' directories normally returned by
00593  * @c apr_dir_read are NOT returned in the hash.
00594  */
00595 svn_error_t *svn_io_get_dirents (apr_hash_t **dirents,
00596                                  const char *path,
00597                                  apr_pool_t *pool);
00598 
00599 
00600 /** Callback function type for @c svn_io_dir_walk  */
00601 typedef svn_error_t * (*svn_io_walk_func_t) (void *baton,
00602                                              const char *path,
00603                                              const apr_finfo_t *finfo,
00604                                              apr_pool_t *pool);
00605 
00606 /** This function will recursively walk over the files and directories
00607  * rooted at @a dirname, a utf8-encoded path. For each file or directory,
00608  * @a walk_func is invoked, passing in the @a walk_baton, the utf8-encoded
00609  * full path to the entry, an @c apr_finfo_t structure, and a temporary
00610  * pool for allocations.  For any directory, @a walk_func will be invoked
00611  * on the directory itself before being invoked on any subdirectories or
00612  * files within the directory.
00613  *
00614  * The set of information passed to @a walk_func is specified by @a wanted,
00615  * and the items specified by @c APR_FINFO_TYPE and @c APR_FINFO_NAME.
00616  *
00617  * All allocations will be performed in @a pool.
00618  */
00619 svn_error_t *svn_io_dir_walk (const char *dirname,
00620                               apr_int32_t wanted,
00621                               svn_io_walk_func_t walk_func,
00622                               void *walk_baton,
00623                               apr_pool_t *pool);
00624 
00625 /** Invoke @a cmd with @a args, using utf8-encoded @a path as working 
00626  * directory.  Connect @a cmd's stdin, stdout, and stderr to @a infile, 
00627  * @a outfile, and @a errfile, except where they are null.
00628  *
00629  * If set, @a exitcode will contain the exit code of the process upon return,
00630  * and @a exitwhy will indicate why the process terminated. If @a exitwhy is 
00631  * not set and the exit reason is not @c APR_PROC_CHECK_EXIT(), or if 
00632  * @a exitcode is not set and the exit code is non-zero, then an 
00633  * @c SVN_ERR_EXTERNAL_PROGRAM error will be returned.
00634  *
00635  * @a args is a list of utf8-encoded (<tt>const char *</tt>)'s, terminated by
00636  * @c NULL.  @c ARGS[0] is the name of the program, though it need not be
00637  * the same as @a cmd.
00638  *
00639  * @a inherit sets whether the invoked program shall inherit its environment or
00640  * run "clean".
00641  */
00642 svn_error_t *svn_io_run_cmd (const char *path,
00643                              const char *cmd,
00644                              const char *const *args,
00645                              int *exitcode,
00646                              apr_exit_why_e *exitwhy,
00647                              svn_boolean_t inherit,
00648                              apr_file_t *infile,
00649                              apr_file_t *outfile,
00650                              apr_file_t *errfile,
00651                              apr_pool_t *pool);
00652 
00653 /** Invoke @c the configured diff program, with @a user_args (an array
00654  * of utf8-encoded @a num_user_args arguments), if they are specified,
00655  * or "-u" if they are not.
00656  *
00657  * Diff runs in utf8-encoded @a dir, and its exit status is stored in
00658  * @a exitcode, if it is not @c NULL.  
00659  *
00660  * If @a label1 and/or @a label2 are not null they will be passed to the diff
00661  * process as the arguments of "-L" options.  @a label1 and @a label2 are also 
00662  * in utf8, and will be converted to native charset along with the other args.
00663  *
00664  * @a from is the first file passed to diff, and @a to is the second.  The
00665  * stdout of diff will be sent to @a outfile, and the stderr to @a errfile.
00666  *
00667  * @a diff_cmd must be non-null.
00668  *
00669  * Do all allocation in @a pool. 
00670  */
00671 svn_error_t *svn_io_run_diff (const char *dir,
00672                               const char *const *user_args,
00673                               int num_user_args,
00674                               const char *label1,
00675                               const char *label2,
00676                               const char *from,
00677                               const char *to,
00678                               int *exitcode,
00679                               apr_file_t *outfile,
00680                               apr_file_t *errfile,
00681                               const char *diff_cmd,
00682                               apr_pool_t *pool);
00683 
00684 
00685 /** Invoke @c the configured diff3 program, in utf8-encoded @a dir
00686  * like this:
00687  *
00688  *          diff3 -Em @a mine @a older @a yours > @a merged
00689  *
00690  * (See the diff3 documentation for details.)
00691  *
00692  * @a mine, @a older, and @a yours are utf8-encoded paths, relative to @a dir, 
00693  * to three files that already exist.  @a merged is an open file handle, and
00694  * is left open after the merge result is written to it. (@a merged
00695  * should *not* be the same file as @a mine, or nondeterministic things
00696  * may happen!)
00697  *
00698  * @a mine_label, @a older_label, @a yours_label are utf8-encoded label
00699  * parameters for diff3's -L option.  Any of them may be @c NULL, in
00700  * which case the corresponding @a mine, @a older, or @a yours parameter is
00701  * used instead.
00702  *
00703  * Set @a *exitcode to diff3's exit status.  If @a *exitcode is anything
00704  * other than 0 or 1, then return @c SVN_ERR_EXTERNAL_PROGRAM.  (Note the
00705  * following from the diff3 info pages: "An exit status of 0 means
00706  * `diff3' was successful, 1 means some conflicts were found, and 2
00707  * means trouble.") 
00708  *
00709  * @a diff3_cmd must be non-null.
00710  *
00711  * Do all allocation in @a pool. 
00712  */
00713 svn_error_t *svn_io_run_diff3 (const char *dir,
00714                                const char *mine,
00715                                const char *older,
00716                                const char *yours,
00717                                const char *mine_label,
00718                                const char *older_label,
00719                                const char *yours_label,
00720                                apr_file_t *merged,
00721                                int *exitcode,
00722                                const char *diff3_cmd,
00723                                apr_pool_t *pool);
00724 
00725 
00726 /** Examine utf8-encoded @a file to determine if it can be described by a
00727  * known (as in, known by this function) Multipurpose Internet Mail
00728  * Extension (MIME) type.  If so, set @a mimetype to a character string
00729  * describing the MIME type, else set it to @c NULL.  Use @a pool for any
00730  * necessary allocations.
00731  */
00732 svn_error_t *svn_io_detect_mimetype (const char **mimetype,
00733                                      const char *file,
00734                                      apr_pool_t *pool);
00735                                       
00736 
00737 /** Wrapper for @c apr_file_open(), which see.  @a fname is utf8-encoded. */
00738 svn_error_t *
00739 svn_io_file_open (apr_file_t **new_file, const char *fname,
00740                   apr_int32_t flag, apr_fileperms_t perm,
00741                   apr_pool_t *pool);
00742 
00743 
00744 /** Wrapper for @c apr_file_close(), which see. */
00745 svn_error_t *
00746 svn_io_file_close (apr_file_t *file, apr_pool_t *pool);
00747 
00748 
00749 /** Wrapper for @c apr_file_getc(), which see. */
00750 svn_error_t *
00751 svn_io_file_getc (char *ch, apr_file_t *file, apr_pool_t *pool);
00752 
00753 
00754 /** Wrapper for @c apr_file_info_get(), which see. */
00755 svn_error_t *
00756 svn_io_file_info_get (apr_finfo_t *finfo, apr_int32_t wanted, 
00757                       apr_file_t *file, apr_pool_t *pool);
00758 
00759 
00760 /** Wrapper for @c apr_file_read(), which see. */
00761 svn_error_t *
00762 svn_io_file_read (apr_file_t *file, void *buf, 
00763                   apr_size_t *nbytes, apr_pool_t *pool);
00764 
00765 
00766 /** Wrapper for @c apr_file_read_full(), which see. */
00767 svn_error_t *
00768 svn_io_file_read_full (apr_file_t *file, void *buf, 
00769                        apr_size_t nbytes, apr_size_t *bytes_read,
00770                        apr_pool_t *pool);
00771 
00772 
00773 /** Wrapper for @c apr_file_seek(), which see. */
00774 svn_error_t *
00775 svn_io_file_seek (apr_file_t *file, apr_seek_where_t where, 
00776                   apr_off_t *offset, apr_pool_t *pool);
00777 
00778 
00779 /** Wrapper for @c apr_file_write(), which see. */
00780 svn_error_t *
00781 svn_io_file_write (apr_file_t *file, const void *buf, 
00782                    apr_size_t *nbytes, apr_pool_t *pool);
00783 
00784 
00785 /** Wrapper for @c apr_file_write_full(), which see. */
00786 svn_error_t *
00787 svn_io_file_write_full (apr_file_t *file, const void *buf, 
00788                         apr_size_t nbytes, apr_size_t *bytes_written,
00789                         apr_pool_t *pool);
00790 
00791 
00792 /** Wrapper for @c apr_stat(), which see.  @a fname is utf8-encoded. */
00793 svn_error_t *
00794 svn_io_stat (apr_finfo_t *finfo, const char *fname,
00795              apr_int32_t wanted, apr_pool_t *pool);
00796 
00797 
00798 /** Wrapper for @c apr_file_rename(), which see.  @a from_path and @a to_path
00799  * are utf8-encoded.
00800  */
00801 svn_error_t *
00802 svn_io_file_rename (const char *from_path, const char *to_path,
00803                     apr_pool_t *pool);
00804 
00805 
00806 /** Wrapper for @c apr_dir_make(), which see.  @a path is utf8-encoded. */
00807 svn_error_t *
00808 svn_io_dir_make (const char *path, apr_fileperms_t perm, apr_pool_t *pool);
00809 
00810 /** Same as svn_io_dir_make, but sets the hidden attribute on the
00811     directory on systems that support it. */
00812 svn_error_t *
00813 svn_io_dir_make_hidden (const char *path, apr_fileperms_t perm,
00814                         apr_pool_t *pool);
00815 
00816 /**
00817  * @since New in 1.1.
00818  *
00819  * Same as svn_io_dir_make, but attempts to set the sgid on the
00820  * directory on systems that support it.  Does not return an error if
00821  * the attempt to set the sgid bit fails.  On Unix filesystems,
00822  * setting the sgid bit on a directory ensures that files and
00823  * subdirectories created within inherit group ownership from the
00824  * parent instead of from the primary gid. */
00825 svn_error_t *
00826 svn_io_dir_make_sgid (const char *path, apr_fileperms_t perm,
00827                       apr_pool_t *pool);
00828 
00829 /** Wrapper for @c apr_dir_open(), which see.  @a dirname is utf8-encoded. */
00830 svn_error_t *
00831 svn_io_dir_open (apr_dir_t **new_dir, const char *dirname, apr_pool_t *pool);
00832 
00833 
00834 /** Wrapper for @c apr_dir_remove(), which see.  @a dirname is utf8-encoded.
00835  * Note: this function has this name to avoid confusion with
00836  * @c svn_io_remove_dir, which is recursive.
00837  */
00838 svn_error_t *
00839 svn_io_dir_remove_nonrecursive (const char *dirname, apr_pool_t *pool);
00840 
00841 
00842 /** Wrapper for @c apr_dir_read, which see.  Ensures that @a finfo->name is
00843  * utf8-encoded, which means allocating @a finfo->name in @a pool, which may
00844  * or may not be the same as @a finfo's pool.  Use @a pool for error allocation
00845  * as well.
00846  */
00847 svn_error_t *
00848 svn_io_dir_read (apr_finfo_t *finfo,
00849                  apr_int32_t wanted,
00850                  apr_dir_t *thedir,
00851                  apr_pool_t *pool);
00852 
00853 
00854 
00855 /** Version/format files. 
00856  *
00857  * @defgroup svn_io_format_files version/format files
00858  * @{
00859  */
00860 
00861 /** Set @a *version to the integer that starts the file at @a path.  If the
00862  * file does not begin with a series of digits followed by a newline,
00863  * return the error @c SVN_ERR_BAD_VERSION_FILE_FORMAT.  Use @a pool for
00864  * all allocations.
00865  */
00866 svn_error_t *
00867 svn_io_read_version_file (int *version, const char *path, apr_pool_t *pool);
00868 
00869 /** Create (or overwrite) the file at @a path with new contents,
00870  * formatted as a non-negative integer @a version followed by a single
00871  * newline.  On successful completion the file will be read-only.  Use
00872  * @a pool for all allocations.
00873  */
00874 svn_error_t *
00875 svn_io_write_version_file (const char *path, int version, apr_pool_t *pool);
00876 
00877 /** @} */
00878 
00879 #ifdef __cplusplus
00880 }
00881 #endif /* __cplusplus */
00882 
00883 #endif /* SVN_IO_H */

Generated on Sat Apr 2 12:00:41 2005 for Subversion by doxygen1.2.18