3 * ====================================================================
4 * Copyright (c) 2000-2007 CollabNet. All rights reserved.
6 * This software is licensed as described in the file COPYING, which
7 * you should have received as part of this distribution. The terms
8 * are also available at http://subversion.tigris.org/license-1.html.
9 * If newer versions of this license are posted there, you may use a
10 * newer version instead, at your option.
12 * This software consists of voluntary contributions made by many
13 * individuals. For exact contribution history, see the revision
14 * history and logs, available at http://subversion.tigris.org/.
15 * ====================================================================
19 * @brief General file I/O for Subversion
22 /* ==================================================================== */
29 #include <apr_pools.h>
30 #include <apr_file_io.h>
31 #include <apr_thread_proc.h>
33 #include "svn_types.h"
34 #include "svn_error.h"
35 #include "svn_string.h"
39 #endif /* __cplusplus */
43 /** Used as an argument when creating temporary files to indicate
44 * when a file should be removed.
48 * Not specifying any of these means no removal at all. */
49 typedef enum svn_io_file_del_t
51 /** No deletion ever */
52 svn_io_file_del_none
= 0,
53 /** Remove when the file is closed */
54 svn_io_file_del_on_close
,
55 /** Remove when the associated pool is cleared */
56 svn_io_file_del_on_pool_cleanup
61 /** Represents the kind and special status of a directory entry.
65 typedef struct svn_io_dirent_t
{
66 /** The kind of this entry. */
68 /** If @c kind is @c svn_node_file, whether this entry is a special file;
71 * @see svn_io_check_special_path().
73 svn_boolean_t special
;
76 /** Determine the @a kind of @a path.
78 * If utf8-encoded @a path exists, set @a *kind to the appropriate kind,
79 * else set it to @c svn_node_unknown.
81 * If @a path is a file, @a *kind is set to @c svn_node_file.
83 * If @a path is a directory, @a *kind is set to @c svn_node_dir.
85 * If @a path does not exist in its final component, @a *kind is set to
88 * If intermediate directories on the way to @a path don't exist, an
89 * error is returned, and @a *kind's value is undefined.
91 * Use @a pool for temporary allocations.
93 svn_error_t
*svn_io_check_path(const char *path
,
94 svn_node_kind_t
*kind
,
98 * Like svn_io_check_path(), but also set *is_special to @c TRUE if
99 * the path is not a normal file.
103 svn_error_t
*svn_io_check_special_path(const char *path
,
104 svn_node_kind_t
*kind
,
105 svn_boolean_t
*is_special
,
108 /** Like svn_io_check_path(), but resolve symlinks. This returns the
109 same varieties of @a kind as svn_io_check_path(). */
110 svn_error_t
*svn_io_check_resolved_path(const char *path
,
111 svn_node_kind_t
*kind
,
115 /** Open a new file (for reading and writing) with a unique name based on
116 * utf-8 encoded @a path, in the same directory as @a path. The file handle is
117 * returned in @a *f, and the name, which ends with @a suffix, is returned
118 * in @a *unique_name_p, also utf8-encoded. Either @a f or @a unique_name_p
121 * If @a delete_when is @c svn_io_file_del_on_close, then the @c APR_DELONCLOSE
122 * flag will be used when opening the file. The @c APR_BUFFERED flag will
125 * The first attempt will just append @a suffix. If the result is not
126 * a unique name, then subsequent attempts will append a dot,
127 * followed by an iteration number ("2", then "3", and so on),
128 * followed by the suffix. For example, if @a path is
132 * then successive calls to
134 * svn_io_open_unique_file2(&f, &unique_name, @a path, ".tmp", ..., pool)
138 * tests/t1/A/D/G/pi.tmp
139 * tests/t1/A/D/G/pi.2.tmp
140 * tests/t1/A/D/G/pi.3.tmp
141 * tests/t1/A/D/G/pi.4.tmp
142 * tests/t1/A/D/G/pi.5.tmp
145 * Assuming @a suffix is non-empty, @a *unique_name_p will never be exactly
146 * the same as @a path, even if @a path does not exist.
148 * It doesn't matter if @a path is a file or directory, the unique name will
149 * be in @a path's parent either way.
151 * Allocate @a *f and @a *unique_name_p in @a pool.
153 * If no unique name can be found, @c SVN_ERR_IO_UNIQUE_NAMES_EXHAUSTED is
154 * the error returned.
156 * Claim of Historical Inevitability: this function was written
159 * - tmpnam() is not thread-safe.
160 * - tempname() tries standard system tmp areas first.
166 svn_error_t
*svn_io_open_unique_file2(apr_file_t
**f
,
167 const char **unique_name_p
,
170 svn_io_file_del_t delete_when
,
173 /** Like svn_io_open_unique_file2, but can't delete on pool cleanup.
175 * @deprecated Provided for backward compatibility with the 1.0 API
177 * @note In 1.4 the API was extended to require either @a f or
178 * @a unique_name_p (the other can be NULL). Before that, both were
182 svn_error_t
*svn_io_open_unique_file(apr_file_t
**f
,
183 const char **unique_name_p
,
186 svn_boolean_t delete_on_close
,
190 * Like svn_io_open_unique_file(), except that instead of creating a
191 * file, a symlink is generated that references the path @a dest.
195 svn_error_t
*svn_io_create_unique_link(const char **unique_name_p
,
203 * Set @a *dest to the path that the symlink at @a path references.
204 * Allocate the string from @a pool.
208 svn_error_t
*svn_io_read_link(svn_string_t
**dest
,
213 /** Set @a *dir to a directory path (allocated in @a pool) deemed
214 * usable for the creation of temporary files and subdirectories.
216 svn_error_t
*svn_io_temp_dir(const char **dir
,
220 /** Copy @a src to @a dst atomically, in a "byte-for-byte" manner.
221 * Overwrite @a dst if it exists, else create it. Both @a src and @a dst
222 * are utf8-encoded filenames. If @a copy_perms is TRUE, set @a dst's
223 * permissions to match those of @a src.
225 svn_error_t
*svn_io_copy_file(const char *src
,
227 svn_boolean_t copy_perms
,
231 * Copy symbolic link @a src to @a dst atomically. Overwrite @a dst
232 * if it exists, else create it. Both @a src and @a dst are
233 * utf8-encoded filenames. After copying, the @a dst link will point
234 * to the same thing @a src does.
238 svn_error_t
*svn_io_copy_link(const char *src
,
243 /** Recursively copy directory @a src into @a dst_parent, as a new entry named
244 * @a dst_basename. If @a dst_basename already exists in @a dst_parent,
245 * return error. @a copy_perms will be passed through to svn_io_copy_file()
246 * when any files are copied. @a src, @a dst_parent, and @a dst_basename are
249 * If @a cancel_func is non-NULL, invoke it with @a cancel_baton at
250 * various points during the operation. If it returns any error
251 * (typically @c SVN_ERR_CANCELLED), return that error immediately.
253 svn_error_t
*svn_io_copy_dir_recursively(const char *src
,
254 const char *dst_parent
,
255 const char *dst_basename
,
256 svn_boolean_t copy_perms
,
257 svn_cancel_func_t cancel_func
,
263 /** Create directory @a path on the file system, creating intermediate
264 * directories as required, like <tt>mkdir -p</tt>. Report no error if @a
265 * path already exists. @a path is utf8-encoded.
267 * This is essentially a wrapper for apr_dir_make_recursive(), passing
268 * @c APR_OS_DEFAULT as the permissions.
270 svn_error_t
*svn_io_make_dir_recursively(const char *path
, apr_pool_t
*pool
);
273 /** Set @a *is_empty_p to @c TRUE if directory @a path is empty, else to
274 * @c FALSE if it is not empty. @a path must be a directory, and is
275 * utf8-encoded. Use @a pool for temporary allocation.
278 svn_io_dir_empty(svn_boolean_t
*is_empty_p
,
283 /** Append @a src to @a dst. @a dst will be appended to if it exists, else it
284 * will be created. Both @a src and @a dst are utf8-encoded.
286 svn_error_t
*svn_io_append_file(const char *src
,
291 /** Make a file as read-only as the operating system allows.
292 * @a path is the utf8-encoded path to the file. If @a ignore_enoent is
293 * @c TRUE, don't fail if the target file doesn't exist.
295 * If @a path is a symlink, do nothing.
297 * @note If @a path is a directory, act on it as though it were a
298 * file, as described above, but note that you probably don't want to
299 * call this function on directories. We have left it effective on
300 * directories for compatibility reasons, but as its name implies, it
301 * should be used only for files.
303 svn_error_t
*svn_io_set_file_read_only(const char *path
,
304 svn_boolean_t ignore_enoent
,
308 /** Make a file as writable as the operating system allows.
309 * @a path is the utf8-encoded path to the file. If @a ignore_enoent is
310 * @c TRUE, don't fail if the target file doesn't exist.
311 * @warning On Unix this function will do the equivalent of chmod a+w path.
312 * If this is not what you want you should not use this function, but rather
313 * use apr_file_perms_set().
315 * If @a path is a symlink, do nothing.
317 * @note If @a path is a directory, act on it as though it were a
318 * file, as described above, but note that you probably don't want to
319 * call this function on directories. We have left it effective on
320 * directories for compatibility reasons, but as its name implies, it
321 * should be used only for files.
323 svn_error_t
*svn_io_set_file_read_write(const char *path
,
324 svn_boolean_t ignore_enoent
,
328 /** Similar to svn_io_set_file_read_* functions.
329 * Change the read-write permissions of a file.
332 * When making @a path read-write on operating systems with unix style
333 * permissions, set the permissions on @a path to the permissions that
334 * are set when a new file is created (effectively honoring the user's
337 * When making the file read-only on operating systems with unix style
338 * permissions, remove all write permissions.
340 * On other operating systems, toggle the file's "writability" as much as
341 * the operating system allows.
343 * @a path is the utf8-encoded path to the file. If @a enable_write
344 * is @c TRUE, then make the file read-write. If @c FALSE, make it
345 * read-only. If @a ignore_enoent is @c TRUE, don't fail if the target
346 * file doesn't exist.
348 * @deprecated Provided for backward compatibility with the 1.3 API.
350 svn_error_t
*svn_io_set_file_read_write_carefully(const char *path
,
351 svn_boolean_t enable_write
,
352 svn_boolean_t ignore_enoent
,
355 /** Set @a path's "executability" (but do nothing if it is a symlink).
357 * @a path is the utf8-encoded path to the file. If @a executable
358 * is @c TRUE, then make the file executable. If @c FALSE, make it
359 * non-executable. If @a ignore_enoent is @c TRUE, don't fail if the target
360 * file doesn't exist.
362 * When making the file executable on operating systems with unix style
363 * permissions, never add an execute permission where there is not
364 * already a read permission: that is, only make the file executable
365 * for the user, group or world if the corresponding read permission
366 * is already set for user, group or world.
368 * When making the file non-executable on operating systems with unix style
369 * permissions, remove all execute permissions.
371 * On other operating systems, toggle the file's "executability" as much as
372 * the operating system allows.
374 * @note If @a path is a directory, act on it as though it were a
375 * file, as described above, but note that you probably don't want to
376 * call this function on directories. We have left it effective on
377 * directories for compatibility reasons, but as its name implies, it
378 * should be used only for files.
380 svn_error_t
*svn_io_set_file_executable(const char *path
,
381 svn_boolean_t executable
,
382 svn_boolean_t ignore_enoent
,
385 /** Determine whether a file is executable by the current user.
386 * Set @a *executable to @c TRUE if the file @a path is executable by the
387 * current user, otherwise set it to @c FALSE.
389 * On Windows and on platforms without userids, always returns @c FALSE.
391 svn_error_t
*svn_io_is_file_executable(svn_boolean_t
*executable
,
396 /** Read a line from @a file into @a buf, but not exceeding @a *limit bytes.
397 * Does not include newline, instead '\\0' is put there.
398 * Length (as in strlen) is returned in @a *limit.
399 * @a buf should be pre-allocated.
400 * @a file should be already opened.
402 * When the file is out of lines, @c APR_EOF will be returned.
405 svn_io_read_length_line(apr_file_t
*file
, char *buf
, apr_size_t
*limit
,
409 /** Set @a *apr_time to the time of last modification of the contents of the
410 * file @a path. @a path is utf8-encoded.
412 * @note This is the APR mtime which corresponds to the traditional mtime
413 * on Unix, and the last write time on Windows.
415 svn_error_t
*svn_io_file_affected_time(apr_time_t
*apr_time
,
419 /** Set the timestamp of file @a path to @a apr_time. @a path is
422 * @note This is the APR mtime which corresponds to the traditional mtime
423 * on Unix, and the last write time on Windows.
425 svn_error_t
*svn_io_set_file_affected_time(apr_time_t apr_time
,
431 /** Set @a *different_p to non-zero if @a file1 and @a file2 have different
432 * sizes, else set to zero. Both @a file1 and @a file2 are utf8-encoded.
434 * Setting @a *different_p to zero does not mean the files definitely
435 * have the same size, it merely means that the sizes are not
436 * definitely different. That is, if the size of one or both files
437 * cannot be determined, then the sizes are not known to be different,
438 * so @a *different_p is set to 0.
440 svn_error_t
*svn_io_filesizes_different_p(svn_boolean_t
*different_p
,
446 /** Put the md5 checksum of @a file into @a digest.
447 * @a digest points to @c APR_MD5_DIGESTSIZE bytes of storage.
448 * Use @a pool only for temporary allocations.
450 svn_error_t
*svn_io_file_checksum(unsigned char digest
[],
455 /** Set @a *same to TRUE if @a file1 and @a file2 have the same
456 * contents, else set it to FALSE. Use @a pool for temporary allocations.
458 svn_error_t
*svn_io_files_contents_same_p(svn_boolean_t
*same
,
463 /** Create file at utf8-encoded @a file with contents @a contents.
464 * @a file must not already exist.
465 * Use @a pool for memory allocations.
467 svn_error_t
*svn_io_file_create(const char *file
,
468 const char *contents
,
472 * Lock file at @a lock_file. If @a exclusive is TRUE,
473 * obtain exclusive lock, otherwise obtain shared lock.
474 * Lock will be automatically released when @a pool is cleared or destroyed.
475 * Use @a pool for memory allocations.
477 * @deprecated Provided for backward compatibility with the 1.0 API.
479 svn_error_t
*svn_io_file_lock(const char *lock_file
,
480 svn_boolean_t exclusive
,
484 * Lock file at @a lock_file. If @a exclusive is TRUE,
485 * obtain exclusive lock, otherwise obtain shared lock.
487 * If @a nonblocking is TRUE, do not wait for the lock if it
488 * is not available: throw an error instead.
490 * Lock will be automatically released when @a pool is cleared or destroyed.
491 * Use @a pool for memory allocations.
495 svn_error_t
*svn_io_file_lock2(const char *lock_file
,
496 svn_boolean_t exclusive
,
497 svn_boolean_t nonblocking
,
500 * Flush any unwritten data from @a file to disk. Use @a pool for
501 * memory allocations.
505 svn_error_t
*svn_io_file_flush_to_disk(apr_file_t
*file
,
508 /** Copy file @a file from location @a src_path to location @a dest_path.
509 * Use @a pool for memory allocations.
511 svn_error_t
*svn_io_dir_file_copy(const char *src_path
,
512 const char *dest_path
,
517 /** Generic byte-streams
519 * @defgroup svn_io_byte_streams Generic byte streams
523 /** An abstract stream of bytes--either incoming or outgoing or both.
525 * The creator of a stream sets functions to handle read and write.
526 * Both of these handlers accept a baton whose value is determined at
527 * stream creation time; this baton can point to a structure
528 * containing data associated with the stream. If a caller attempts
529 * to invoke a handler which has not been set, it will generate a
530 * runtime assertion failure. The creator can also set a handler for
531 * close requests so that it can flush buffered data or whatever;
532 * if a close handler is not specified, a close request on the stream
533 * will simply be ignored. Note that svn_stream_close() does not
534 * deallocate the memory used to allocate the stream structure; free
535 * the pool you created the stream in to free that memory.
537 * The read and write handlers accept length arguments via pointer.
538 * On entry to the handler, the pointed-to value should be the amount
539 * of data which can be read or the amount of data to write. When the
540 * handler returns, the value is reset to the amount of data actually
541 * read or written. Handlers are obliged to complete a read or write
542 * to the maximum extent possible; thus, a short read with no
543 * associated error implies the end of the input stream, and a short
544 * write should never occur without an associated error.
546 typedef struct svn_stream_t svn_stream_t
;
550 /** Read handler function for a generic stream. @see svn_stream_t. */
551 typedef svn_error_t
*(*svn_read_fn_t
)(void *baton
,
555 /** Write handler function for a generic stream. @see svn_stream_t. */
556 typedef svn_error_t
*(*svn_write_fn_t
)(void *baton
,
560 /** Close handler function for a generic stream. @see svn_stream_t. */
561 typedef svn_error_t
*(*svn_close_fn_t
)(void *baton
);
564 /** Create a generic stream. @see svn_stream_t. */
565 svn_stream_t
*svn_stream_create(void *baton
, apr_pool_t
*pool
);
567 /** Set @a stream's baton to @a baton */
568 void svn_stream_set_baton(svn_stream_t
*stream
, void *baton
);
570 /** Set @a stream's read function to @a read_fn */
571 void svn_stream_set_read(svn_stream_t
*stream
, svn_read_fn_t read_fn
);
573 /** Set @a stream's write function to @a write_fn */
574 void svn_stream_set_write(svn_stream_t
*stream
, svn_write_fn_t write_fn
);
576 /** Set @a stream's close function to @a close_fn */
577 void svn_stream_set_close(svn_stream_t
*stream
, svn_close_fn_t close_fn
);
580 /** Create a stream that is empty for reading and infinite for writing. */
581 svn_stream_t
*svn_stream_empty(apr_pool_t
*pool
);
583 /** Return a stream allocated in @a pool which forwards all requests
584 * to @a stream. Destruction is explicitly excluded from forwarding.
586 * @see notes/destruction-of-stacked-resources
590 svn_stream_t
*svn_stream_disown(svn_stream_t
*stream
, apr_pool_t
*pool
);
592 /** Create a stream from an APR file. For convenience, if @a file is
593 * @c NULL, an empty stream created by svn_stream_empty() is returned.
595 * This function should normally be called with @a disown set to FALSE,
596 * in which case closing the stream will also close the underlying file.
598 * If @a disown is TRUE, the stream will disown the underlying file,
599 * meaning that svn_stream_close() will not close the file.
603 svn_stream_t
* svn_stream_from_aprfile2(apr_file_t
*file
,
604 svn_boolean_t disown
,
607 /** Similar to svn_stream_from_aprfile2(), except that the file will
608 * always be disowned.
610 * @note The stream returned is not considered to "own" the underlying
611 * file, meaning that svn_stream_close() on the stream will not
614 * @deprecated Provided for backward compatibility with the 1.3 API.
616 svn_stream_t
*svn_stream_from_aprfile(apr_file_t
*file
, apr_pool_t
*pool
);
618 /** Set @a *out to a generic stream connected to stdout, allocated in
619 * @a pool. The stream and its underlying APR handle will be closed
620 * when @a pool is cleared or destroyed.
622 svn_error_t
*svn_stream_for_stdout(svn_stream_t
**out
, apr_pool_t
*pool
);
624 /** Return a generic stream connected to stringbuf @a str. Allocate the
627 svn_stream_t
*svn_stream_from_stringbuf(svn_stringbuf_t
*str
,
630 /** Return a stream that decompresses all data read and compresses all
631 * data written. The stream @a stream is used to read and write all
632 * compressed data. All compression data structures are allocated on
633 * @a pool. If compression support is not compiled in then
634 * svn_stream_compressed() returns @a stream unmodified. Make sure you
635 * call svn_stream_close() on the stream returned by this function,
636 * so that all data are flushed and cleaned up.
638 * @note From 1.4, compression support is always compiled in.
640 svn_stream_t
*svn_stream_compressed(svn_stream_t
*stream
,
643 /** Return a stream that calculates checksums for all data read
644 * and written. The stream @a stream is used to read and write all data.
645 * The stream and the resulting digests are allocated in @a pool.
647 * When the stream is closed, @a read_digest and @a write_digest
648 * are set to point to the resulting digests.
650 * Both @a read_digest and @a write_digest
651 * can be @c NULL, in which case the respective checksum isn't calculated.
653 * If @a read_all is TRUE, make sure that all data available on @a
654 * stream is read (and checksummed) when the stream is closed.
656 * Read and write operations can be mixed without interfering.
658 * The @a stream passed into this function is closed when the created
663 svn_stream_t
*svn_stream_checksummed(svn_stream_t
*stream
,
664 const unsigned char **read_digest
,
665 const unsigned char **write_digest
,
666 svn_boolean_t read_all
,
669 /** Read from a generic stream. @see svn_stream_t. */
670 svn_error_t
*svn_stream_read(svn_stream_t
*stream
, char *buffer
,
673 /** Write to a generic stream. @see svn_stream_t. */
674 svn_error_t
*svn_stream_write(svn_stream_t
*stream
, const char *data
,
677 /** Close a generic stream. @see svn_stream_t. */
678 svn_error_t
*svn_stream_close(svn_stream_t
*stream
);
681 /** Write to @a stream using a printf-style @a fmt specifier, passed through
682 * apr_psprintf() using memory from @a pool.
684 svn_error_t
*svn_stream_printf(svn_stream_t
*stream
,
688 __attribute__((format(printf
, 3, 4)));
690 /** Write to @a stream using a printf-style @a fmt specifier, passed through
691 * apr_psprintf() using memory from @a pool. The resulting string
692 * will be translated to @a encoding before it is sent to @a stream.
694 * @note Use @c APR_LOCALE_CHARSET to translate to the encoding of the
699 svn_error_t
*svn_stream_printf_from_utf8(svn_stream_t
*stream
,
700 const char *encoding
,
704 __attribute__((format(printf
, 4, 5)));
706 /** Allocate @a *stringbuf in @a pool, and read into it one line (terminated
707 * by @a eol) from @a stream. The line-terminator is read from the stream,
708 * but is not added to the end of the stringbuf. Instead, the stringbuf
709 * ends with a usual '\\0'.
711 * If @a stream runs out of bytes before encountering a line-terminator,
712 * then set @a *eof to @c TRUE, otherwise set @a *eof to FALSE.
715 svn_stream_readline(svn_stream_t
*stream
,
716 svn_stringbuf_t
**stringbuf
,
722 * Read the contents of the readable stream @a from and write them to the
723 * writable stream @a to calling @a cancel_func before copying each chunk.
725 * @a cancel_func may be @c NULL.
729 svn_error_t
*svn_stream_copy2(svn_stream_t
*from
, svn_stream_t
*to
,
730 svn_cancel_func_t cancel_func
,
736 * Same as svn_stream_copy2(), but without the cancellation function.
739 * @deprecated Provided for backward compatibility with the 1.4 API.
741 svn_error_t
*svn_stream_copy(svn_stream_t
*from
, svn_stream_t
*to
,
744 /** Set @a *same to TRUE if @a stream1 and @a stream2 have the same
745 * contents, else set it to FALSE. Use @a pool for temporary allocations.
750 svn_stream_contents_same(svn_boolean_t
*same
,
751 svn_stream_t
*stream1
,
752 svn_stream_t
*stream2
,
757 /** Set @a *result to a string containing the contents of @a
758 * filename, which is either "-" (indicating that stdin should be
759 * read) or the utf8-encoded path of a real file.
761 * @warning Callers should be aware of possible unexpected results
762 * when using this function to read from stdin where additional
763 * stdin-reading processes abound. For example, if a program tries
764 * both to invoke an external editor and to read from stdin, stdin
765 * could be trashed and the editor might act funky or die outright.
769 svn_error_t
*svn_stringbuf_from_file2(svn_stringbuf_t
**result
,
770 const char *filename
,
773 /** Similar to svn_stringbuf_from_file2(), except that if @a filename
774 * is "-", return the error @c SVN_ERR_UNSUPPORTED_FEATURE and don't
777 * @deprecated Provided for backwards compatibility with the 1.4 API.
779 svn_error_t
*svn_stringbuf_from_file(svn_stringbuf_t
**result
,
780 const char *filename
,
783 /** Sets @a *result to a string containing the contents of the already opened
784 * @a file. Reads from the current position in file to the end. Does not
785 * close the file or reset the cursor position.
787 svn_error_t
*svn_stringbuf_from_aprfile(svn_stringbuf_t
**result
,
791 /** Remove file @a path, a utf8-encoded path. This wraps apr_file_remove(),
792 * converting any error to a Subversion error.
794 svn_error_t
*svn_io_remove_file(const char *path
, apr_pool_t
*pool
);
796 /** Recursively remove directory @a path. @a path is utf8-encoded.
797 * If @a ignore_enoent is @c TRUE, don't fail if the target directory
798 * doesn't exist. Use @a pool for temporary allocations.
800 * Because recursive delete of a directory tree can be a lengthy operation,
801 * provide @a cancel_func and @a cancel_baton for interuptability.
805 svn_error_t
*svn_io_remove_dir2(const char *path
,
806 svn_boolean_t ignore_enoent
,
807 svn_cancel_func_t cancel_func
,
811 /** Similar to svn_io_remove_dir2(), but with @a ignore_enoent set to
814 * @deprecated Provided for backward compatibility with the 1.4 API
816 svn_error_t
*svn_io_remove_dir(const char *path
, apr_pool_t
*pool
);
818 /** Read all of the disk entries in directory @a path, a utf8-encoded
819 * path. Set @a *dirents to a hash mapping dirent names (<tt>char *</tt>) to
820 * undefined non-NULL values, allocated in @a pool.
822 * @note The `.' and `..' directories normally returned by
823 * apr_dir_read() are NOT returned in the hash.
827 svn_error_t
*svn_io_get_dir_filenames(apr_hash_t
**dirents
,
831 /** Read all of the disk entries in directory @a path, a utf8-encoded
832 * path. Set @a *dirents to a hash mapping dirent names (<tt>char *</tt>) to
833 * @c svn_io_dirent_t structures, allocated in @a pool.
835 * @note The `.' and `..' directories normally returned by
836 * apr_dir_read() are NOT returned in the hash.
838 * @note The kind field in the @a dirents is set according to the mapping
839 * as documented for svn_io_check_path()
843 svn_error_t
*svn_io_get_dirents2(apr_hash_t
**dirents
,
847 /** Similar to svn_io_get_dirents2(), but @a *dirents is a hash table
848 * with @c svn_node_kind_t values.
850 * @deprecated Provided for backwards compatibility with the 1.2 API.
852 svn_error_t
*svn_io_get_dirents(apr_hash_t
**dirents
,
857 /** Callback function type for svn_io_dir_walk() */
858 typedef svn_error_t
* (*svn_io_walk_func_t
)(void *baton
,
860 const apr_finfo_t
*finfo
,
863 /** This function will recursively walk over the files and directories
864 * rooted at @a dirname, a utf8-encoded path. For each file or directory,
865 * @a walk_func is invoked, passing in the @a walk_baton, the utf8-encoded
866 * full path to the entry, an @c apr_finfo_t structure, and a temporary
867 * pool for allocations. For any directory, @a walk_func will be invoked
868 * on the directory itself before being invoked on any subdirectories or
869 * files within the directory.
871 * The set of information passed to @a walk_func is specified by @a wanted,
872 * and the items specified by @c APR_FINFO_TYPE and @c APR_FINFO_NAME.
874 * All allocations will be performed in @a pool.
876 svn_error_t
*svn_io_dir_walk(const char *dirname
,
878 svn_io_walk_func_t walk_func
,
883 * Start @a cmd with @a args, using utf8-encoded @a path as working
884 * directory. Connect @a cmd's stdin, stdout, and stderr to @a infile,
885 * @a outfile, and @a errfile, except where they are NULL. Return the
886 * process handle for the invoked program in @a *cmd_proc.
888 * @a args is a list of utf8-encoded <tt>const char *</tt> arguments,
889 * terminated by @c NULL. @a args[0] is the name of the program, though it
890 * need not be the same as @a cmd.
892 * If @a inherit is TRUE, the invoked program inherits its environment from
893 * the caller and @a cmd, if not absolute, is searched for in PATH.
894 * Otherwise, the invoked program runs with an empty environment and @a cmd
895 * must be an absolute path.
897 * @note On some platforms, failure to execute @a cmd in the child process
898 * will result in error output being written to @a errfile, if non-NULL, and
899 * a non-zero exit status being returned to the parent process.
903 svn_error_t
*svn_io_start_cmd(apr_proc_t
*cmd_proc
,
906 const char *const *args
,
907 svn_boolean_t inherit
,
914 * Wait for the process @a *cmd_proc to complete and optionally retrieve
915 * its exit code. @a cmd is used only in error messages.
917 * If @a exitcode is not NULL, @a *exitcode will contain the exit code
918 * of the process upon return, and if @a exitwhy is not NULL, @a
919 * *exitwhy will indicate why the process terminated. If @a exitwhy is
920 * NULL, and the exit reason is not @c APR_PROC_CHECK_EXIT(), or if
921 * @a exitcode is NULL and the exit code is non-zero, then an
922 * @c SVN_ERR_EXTERNAL_PROGRAM error will be returned.
926 svn_error_t
*svn_io_wait_for_cmd(apr_proc_t
*cmd_proc
,
929 apr_exit_why_e
*exitwhy
,
932 /** Run a command to completion, by first calling svn_io_start_cmd() and
933 * then calling svn_io_wait_for_cmd(). The parameters correspond to
934 * the same-named parameters of those two functions.
936 svn_error_t
*svn_io_run_cmd(const char *path
,
938 const char *const *args
,
940 apr_exit_why_e
*exitwhy
,
941 svn_boolean_t inherit
,
947 /** Invoke @c the configured diff program, with @a user_args (an array
948 * of utf8-encoded @a num_user_args arguments), if they are specified,
949 * or "-u" if they are not.
951 * Diff runs in utf8-encoded @a dir, and its exit status is stored in
952 * @a exitcode, if it is not @c NULL.
954 * If @a label1 and/or @a label2 are not NULL they will be passed to the diff
955 * process as the arguments of "-L" options. @a label1 and @a label2 are also
956 * in utf8, and will be converted to native charset along with the other args.
958 * @a from is the first file passed to diff, and @a to is the second. The
959 * stdout of diff will be sent to @a outfile, and the stderr to @a errfile.
961 * @a diff_cmd must be non-NULL.
963 * Do all allocation in @a pool.
965 svn_error_t
*svn_io_run_diff(const char *dir
,
966 const char *const *user_args
,
975 const char *diff_cmd
,
979 /** Invoke the configured @c diff3 program, in utf8-encoded @a dir
982 * diff3 -E -m @a mine @a older @a yours > @a merged
984 * (See the diff3 documentation for details.)
986 * If @a user_args is non-NULL, replace "-E" with the <tt>const char*</tt>
987 * elements that @a user_args contains.
989 * @a mine, @a older and @a yours are utf8-encoded paths (relative to
990 * @a dir or absolute) to three files that already exist.
992 * @a merged is an open file handle, and is left open after the merge
993 * result is written to it. (@a merged should *not* be the same file
994 * as @a mine, or nondeterministic things may happen!)
996 * @a mine_label, @a older_label, @a yours_label are utf8-encoded label
997 * parameters for diff3's -L option. Any of them may be @c NULL, in
998 * which case the corresponding @a mine, @a older, or @a yours parameter is
1001 * Set @a *exitcode to diff3's exit status. If @a *exitcode is anything
1002 * other than 0 or 1, then return @c SVN_ERR_EXTERNAL_PROGRAM. (Note the
1003 * following from the diff3 info pages: "An exit status of 0 means
1004 * `diff3' was successful, 1 means some conflicts were found, and 2
1007 * @a diff3_cmd must be non-NULL.
1009 * Do all allocation in @a pool.
1011 * @since New in 1.4.
1013 svn_error_t
*svn_io_run_diff3_2(int *exitcode
,
1018 const char *mine_label
,
1019 const char *older_label
,
1020 const char *yours_label
,
1022 const char *diff3_cmd
,
1023 const apr_array_header_t
*user_args
,
1026 /** Similar to svn_io_run_diff3_2(), but with @a user_args set to @c NULL.
1028 * @deprecated Provided for backwards compatibility with the 1.3 API.
1030 svn_error_t
*svn_io_run_diff3(const char *dir
,
1034 const char *mine_label
,
1035 const char *older_label
,
1036 const char *yours_label
,
1039 const char *diff3_cmd
,
1043 /** Parse utf8-encoded @a mimetypes_file as a MIME types file (such as
1044 * is provided with Apache HTTP Server), and set @a *type_map to a
1045 * hash mapping <tt>const char *</tt> filename extensions to
1046 * <tt>const char *</tt> MIME types.
1048 * @since New in 1.5.
1050 svn_error_t
*svn_io_parse_mimetypes_file(apr_hash_t
**type_map
,
1051 const char *mimetypes_file
,
1055 /** Examine utf8-encoded @a file to determine if it can be described by a
1056 * known (as in, known by this function) Multipurpose Internet Mail
1057 * Extension (MIME) type. If so, set @a *mimetype to a character string
1058 * describing the MIME type, else set it to @c NULL.
1060 * If not @c NULL, @a mimetype_map is a hash mapping <tt>const char *</tt>
1061 * filename extensions to <tt>const char *</tt> MIME types, and is the
1062 * first source consulted regarding @a file's MIME type.
1064 * Use @a pool for any necessary allocations.
1066 * @since New in 1.5.
1068 svn_error_t
*svn_io_detect_mimetype2(const char **mimetype
,
1070 apr_hash_t
*mimetype_map
,
1074 /** Like svn_io_detect_mimetype2, but with @a mimetypes_map set to
1077 * @deprecated Provided for backward compatibility with the 1.4 API
1079 svn_error_t
*svn_io_detect_mimetype(const char **mimetype
,
1084 /** Wrapper for apr_file_open(). @a fname is utf8-encoded. */
1086 svn_io_file_open(apr_file_t
**new_file
, const char *fname
,
1087 apr_int32_t flag
, apr_fileperms_t perm
,
1091 /** Wrapper for apr_file_close(). */
1093 svn_io_file_close(apr_file_t
*file
, apr_pool_t
*pool
);
1096 /** Wrapper for apr_file_getc(). */
1098 svn_io_file_getc(char *ch
, apr_file_t
*file
, apr_pool_t
*pool
);
1101 /** Wrapper for apr_file_info_get(). */
1103 svn_io_file_info_get(apr_finfo_t
*finfo
, apr_int32_t wanted
,
1104 apr_file_t
*file
, apr_pool_t
*pool
);
1107 /** Wrapper for apr_file_read(). */
1109 svn_io_file_read(apr_file_t
*file
, void *buf
,
1110 apr_size_t
*nbytes
, apr_pool_t
*pool
);
1113 /** Wrapper for apr_file_read_full(). */
1115 svn_io_file_read_full(apr_file_t
*file
, void *buf
,
1116 apr_size_t nbytes
, apr_size_t
*bytes_read
,
1120 /** Wrapper for apr_file_seek(). */
1122 svn_io_file_seek(apr_file_t
*file
, apr_seek_where_t where
,
1123 apr_off_t
*offset
, apr_pool_t
*pool
);
1126 /** Wrapper for apr_file_write(). */
1128 svn_io_file_write(apr_file_t
*file
, const void *buf
,
1129 apr_size_t
*nbytes
, apr_pool_t
*pool
);
1132 /** Wrapper for apr_file_write_full(). */
1134 svn_io_file_write_full(apr_file_t
*file
, const void *buf
,
1135 apr_size_t nbytes
, apr_size_t
*bytes_written
,
1139 /** Wrapper for apr_stat(). @a fname is utf8-encoded. */
1141 svn_io_stat(apr_finfo_t
*finfo
, const char *fname
,
1142 apr_int32_t wanted
, apr_pool_t
*pool
);
1145 /** Wrapper for apr_file_rename(). @a from_path and @a to_path are
1149 svn_io_file_rename(const char *from_path
, const char *to_path
,
1153 /** Move the file from @a from_path to @a to_path, even across device
1154 * boundaries. Overwrite @a to_path if it exists.
1156 * @note This function is different from svn_io_file_rename in that the
1157 * latter fails in the 'across device boundaries' case.
1159 * @since New in 1.3.
1162 svn_io_file_move(const char *from_path
, const char *to_path
,
1166 /** Wrapper for apr_dir_make(). @a path is utf8-encoded. */
1168 svn_io_dir_make(const char *path
, apr_fileperms_t perm
, apr_pool_t
*pool
);
1170 /** Same as svn_io_dir_make(), but sets the hidden attribute on the
1171 directory on systems that support it. */
1173 svn_io_dir_make_hidden(const char *path
, apr_fileperms_t perm
,
1177 * Same as svn_io_dir_make(), but attempts to set the sgid on the
1178 * directory on systems that support it. Does not return an error if
1179 * the attempt to set the sgid bit fails. On Unix filesystems,
1180 * setting the sgid bit on a directory ensures that files and
1181 * subdirectories created within inherit group ownership from the
1182 * parent instead of from the primary gid.
1184 * @since New in 1.1.
1187 svn_io_dir_make_sgid(const char *path
, apr_fileperms_t perm
,
1190 /** Wrapper for apr_dir_open(). @a dirname is utf8-encoded. */
1192 svn_io_dir_open(apr_dir_t
**new_dir
, const char *dirname
, apr_pool_t
*pool
);
1195 /** Wrapper for apr_dir_remove(). @a dirname is utf8-encoded.
1196 * @note This function has this name to avoid confusion with
1197 * svn_io_remove_dir2(), which is recursive.
1200 svn_io_dir_remove_nonrecursive(const char *dirname
, apr_pool_t
*pool
);
1203 /** Wrapper for apr_dir_read(). Ensures that @a finfo->name is
1204 * utf8-encoded, which means allocating @a finfo->name in @a pool,
1205 * which may or may not be the same as @a finfo's pool. Use @a pool
1206 * for error allocation as well.
1209 svn_io_dir_read(apr_finfo_t
*finfo
,
1216 /** Version/format files.
1218 * @defgroup svn_io_format_files Version/format files
1222 /** Set @a *version to the integer that starts the file at @a path. If the
1223 * file does not begin with a series of digits followed by a newline,
1224 * return the error @c SVN_ERR_BAD_VERSION_FILE_FORMAT. Use @a pool for
1228 svn_io_read_version_file(int *version
, const char *path
, apr_pool_t
*pool
);
1230 /** Create (or overwrite) the file at @a path with new contents,
1231 * formatted as a non-negative integer @a version followed by a single
1232 * newline. On successful completion the file will be read-only. Use
1233 * @a pool for all allocations.
1236 svn_io_write_version_file(const char *path
, int version
, apr_pool_t
*pool
);
1242 #endif /* __cplusplus */
1244 #endif /* SVN_IO_H */