Main Page | Modules | Data Structures | File List | Data Fields | Globals

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

Generated on Wed Oct 13 23:55:34 2004 for Subversion by doxygen 1.3.4