Subversion
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
svn_io.h
Go to the documentation of this file.
1 /**
2  * @copyright
3  * ====================================================================
4  * Licensed to the Apache Software Foundation (ASF) under one
5  * or more contributor license agreements. See the NOTICE file
6  * distributed with this work for additional information
7  * regarding copyright ownership. The ASF licenses this file
8  * to you under the Apache License, Version 2.0 (the
9  * "License"); you may not use this file except in compliance
10  * with the License. You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing,
15  * software distributed under the License is distributed on an
16  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17  * KIND, either express or implied. See the License for the
18  * specific language governing permissions and limitations
19  * under the License.
20  * ====================================================================
21  * @endcopyright
22  *
23  * @file svn_io.h
24  * @brief General file I/O for Subversion
25  */
26 
27 /* ==================================================================== */
28 
29 
30 #ifndef SVN_IO_H
31 #define SVN_IO_H
32 
33 #include <apr.h>
34 #include <apr_pools.h>
35 #include <apr_time.h>
36 #include <apr_hash.h>
37 #include <apr_tables.h>
38 #include <apr_file_io.h>
39 #include <apr_file_info.h>
40 #include <apr_thread_proc.h> /* for apr_proc_t, apr_exit_why_e */
41 
42 #include "svn_types.h"
43 #include "svn_string.h"
44 #include "svn_checksum.h"
45 
46 #ifdef __cplusplus
47 extern "C" {
48 #endif /* __cplusplus */
49 
50 
51 
52 /** Used as an argument when creating temporary files to indicate
53  * when a file should be removed.
54  *
55  * @since New in 1.4.
56  *
57  * Not specifying any of these means no removal at all. */
58 typedef enum svn_io_file_del_t
59 {
60  /** No deletion ever */
62  /** Remove when the file is closed */
64  /** Remove when the associated pool is cleared */
67 
68 /** A set of directory entry data elements as returned by svn_io_get_dirents
69  *
70  * Note that the first two fields are exactly identical to svn_io_dirent_t
71  * to allow returning a svn_io_dirent2_t as a svn_io_dirent_t.
72  *
73  * Use svn_io_dirent2_create() to create new svn_dirent2_t instances or
74  * svn_io_dirent2_dup() to duplicate an existing instance.
75  *
76  * @since New in 1.7.
77  */
78 typedef struct svn_io_dirent2_t {
79  /* New fields must be added at the end to preserve binary compatibility */
80 
81  /** The kind of this entry. */
83 
84  /** If @c kind is #svn_node_file, whether this entry is a special file;
85  * else FALSE.
86  *
87  * @see svn_io_check_special_path().
88  */
90 
91  /** The filesize of this entry or undefined for a directory */
93 
94  /** The time the file was last modified */
95  apr_time_t mtime;
96 
97  /* Don't forget to update svn_io_dirent2_dup() when adding new fields */
99 
100 
101 /** Creates a new #svn_io_dirent2_t structure
102  *
103  * @since New in 1.7.
104  */
106 svn_io_dirent2_create(apr_pool_t *result_pool);
107 
108 /** Duplicates a @c svn_io_dirent2_t structure into @a result_pool.
109  *
110  * @since New in 1.7.
111  */
114  apr_pool_t *result_pool);
115 
116 /** Represents the kind and special status of a directory entry.
117  *
118  * Note that the first two fields are exactly identical to svn_io_dirent2_t
119  * to allow returning a svn_io_dirent2_t as a svn_io_dirent_t.
120  *
121  * @since New in 1.3.
122  */
123 typedef struct svn_io_dirent_t {
124  /** The kind of this entry. */
126  /** If @c kind is #svn_node_file, whether this entry is a special file;
127  * else FALSE.
128  *
129  * @see svn_io_check_special_path().
130  */
133 
134 /** Determine the @a kind of @a path. @a path should be UTF-8 encoded.
135  *
136  * If @a path is a file, set @a *kind to #svn_node_file.
137  *
138  * If @a path is a directory, set @a *kind to #svn_node_dir.
139  *
140  * If @a path does not exist, set @a *kind to #svn_node_none.
141  *
142  * If @a path exists but is none of the above, set @a *kind to
143  * #svn_node_unknown.
144  *
145  * If @a path is not a valid pathname, set @a *kind to #svn_node_none. If
146  * unable to determine @a path's kind for any other reason, return an error,
147  * with @a *kind's value undefined.
148  *
149  * Use @a pool for temporary allocations.
150  *
151  * @see svn_node_kind_t
152  */
153 svn_error_t *
154 svn_io_check_path(const char *path,
155  svn_node_kind_t *kind,
156  apr_pool_t *pool);
157 
158 /**
159  * Like svn_io_check_path(), but also set *is_special to @c TRUE if
160  * the path is not a normal file.
161  *
162  * @since New in 1.1.
163  */
164 svn_error_t *
165 svn_io_check_special_path(const char *path,
166  svn_node_kind_t *kind,
167  svn_boolean_t *is_special,
168  apr_pool_t *pool);
169 
170 /** Like svn_io_check_path(), but resolve symlinks. This returns the
171  same varieties of @a kind as svn_io_check_path(). */
172 svn_error_t *
173 svn_io_check_resolved_path(const char *path,
174  svn_node_kind_t *kind,
175  apr_pool_t *pool);
176 
177 
178 /** Open a new file (for reading and writing) with a unique name based on
179  * utf-8 encoded @a filename, in the directory @a dirpath. The file handle is
180  * returned in @a *file, and the name, which ends with @a suffix, is returned
181  * in @a *unique_name, also utf8-encoded. Either @a file or @a unique_name
182  * may be @c NULL. If @a file is @c NULL, the file will be created but not
183  * open.
184  *
185  * If @a delete_when is #svn_io_file_del_on_close, then the @c APR_DELONCLOSE
186  * flag will be used when opening the file. The @c APR_BUFFERED flag will
187  * always be used.
188  *
189  * The first attempt will just append @a suffix. If the result is not
190  * a unique name, then subsequent attempts will append a dot,
191  * followed by an iteration number ("2", then "3", and so on),
192  * followed by the suffix. For example, successive calls to
193  *
194  * svn_io_open_uniquely_named(&f, &u, "tests/t1/A/D/G", "pi", ".tmp", ...)
195  *
196  * will open
197  *
198  * tests/t1/A/D/G/pi.tmp
199  * tests/t1/A/D/G/pi.2.tmp
200  * tests/t1/A/D/G/pi.3.tmp
201  * tests/t1/A/D/G/pi.4.tmp
202  * tests/t1/A/D/G/pi.5.tmp
203  * ...
204  *
205  * Assuming @a suffix is non-empty, @a *unique_name will never be exactly
206  * the same as @a filename, even if @a filename does not exist.
207  *
208  * If @a dirpath is NULL, then the directory returned by svn_io_temp_dir()
209  * will be used.
210  *
211  * If @a filename is NULL, then "tempfile" will be used.
212  *
213  * If @a suffix is NULL, then ".tmp" will be used.
214  *
215  * Allocates @a *file and @a *unique_name in @a result_pool. All
216  * intermediate allocations will be performed in @a scratch_pool.
217  *
218  * If no unique name can be found, #SVN_ERR_IO_UNIQUE_NAMES_EXHAUSTED is
219  * the error returned.
220  *
221  * Claim of Historical Inevitability: this function was written
222  * because
223  *
224  * - tmpnam() is not thread-safe.
225  * - tempname() tries standard system tmp areas first.
226  *
227  * @since New in 1.6
228  */
229 svn_error_t *
230 svn_io_open_uniquely_named(apr_file_t **file,
231  const char **unique_name,
232  const char *dirpath,
233  const char *filename,
234  const char *suffix,
235  svn_io_file_del_t delete_when,
236  apr_pool_t *result_pool,
237  apr_pool_t *scratch_pool);
238 
239 
240 /** Create a writable file, with an arbitrary and unique name, in the
241  * directory @a dirpath. Set @a *temp_path to its full path, and set
242  * @a *file to the file handle, both allocated from @a result_pool. Either
243  * @a file or @a unique_name may be @c NULL. If @a file is @c NULL, the file
244  * will be created but not open.
245  *
246  * If @a dirpath is @c NULL, use the path returned from svn_io_temp_dir().
247  * (Note that when using the system-provided temp directory, it may not
248  * be possible to atomically rename the resulting file due to cross-device
249  * issues.)
250  *
251  * The file will be deleted according to @a delete_when. If @a delete_when
252  * is @c svn_io_file_del_on_close and @a file is @c NULL, the file will be
253  * deleted before this function returns.
254  *
255  * When passing @c svn_io_file_del_none please don't forget to eventually
256  * remove the temporary file to avoid filling up the system temp directory.
257  * It is often appropriate to bind the lifetime of the temporary file to
258  * the lifetime of a pool by using @c svn_io_file_del_on_pool_cleanup.
259  *
260  * Temporary allocations will be performed in @a scratch_pool.
261  *
262  * @since New in 1.6
263  * @see svn_stream_open_unique()
264  */
265 svn_error_t *
266 svn_io_open_unique_file3(apr_file_t **file,
267  const char **temp_path,
268  const char *dirpath,
269  svn_io_file_del_t delete_when,
270  apr_pool_t *result_pool,
271  apr_pool_t *scratch_pool);
272 
273 
274 /** Like svn_io_open_uniquely_named(), but takes a joined dirpath and
275  * filename, and a single pool.
276  *
277  * @since New in 1.4
278  *
279  * @deprecated Provided for backward compatibility with the 1.5 API
280  */
282 svn_error_t *
283 svn_io_open_unique_file2(apr_file_t **f,
284  const char **unique_name_p,
285  const char *path,
286  const char *suffix,
287  svn_io_file_del_t delete_when,
288  apr_pool_t *pool);
289 
290 /** Like svn_io_open_unique_file2, but can't delete on pool cleanup.
291  *
292  * @deprecated Provided for backward compatibility with the 1.3 API
293  *
294  * @note In 1.4 the API was extended to require either @a f or
295  * @a unique_name_p (the other can be NULL). Before that, both were
296  * required.
297  */
299 svn_error_t *
300 svn_io_open_unique_file(apr_file_t **f,
301  const char **unique_name_p,
302  const char *path,
303  const char *suffix,
304  svn_boolean_t delete_on_close,
305  apr_pool_t *pool);
306 
307 
308 /**
309  * Like svn_io_open_unique_file(), except that instead of creating a
310  * file, a symlink is generated that references the path @a dest.
311  *
312  * @since New in 1.1.
313  */
314 svn_error_t *
315 svn_io_create_unique_link(const char **unique_name_p,
316  const char *path,
317  const char *dest,
318  const char *suffix,
319  apr_pool_t *pool);
320 
321 
322 /**
323  * Set @a *dest to the path that the symlink at @a path references.
324  * Allocate the string from @a pool.
325  *
326  * @since New in 1.1.
327  */
328 svn_error_t *
330  const char *path,
331  apr_pool_t *pool);
332 
333 
334 /** Set @a *dir to a directory path (allocated in @a pool) deemed
335  * usable for the creation of temporary files and subdirectories.
336  */
337 svn_error_t *
338 svn_io_temp_dir(const char **dir,
339  apr_pool_t *pool);
340 
341 
342 /** Copy @a src to @a dst atomically, in a "byte-for-byte" manner.
343  * Overwrite @a dst if it exists, else create it. Both @a src and @a dst
344  * are utf8-encoded filenames. If @a copy_perms is TRUE, set @a dst's
345  * permissions to match those of @a src.
346  */
347 svn_error_t *
348 svn_io_copy_file(const char *src,
349  const char *dst,
350  svn_boolean_t copy_perms,
351  apr_pool_t *pool);
352 
353 
354 /** Copy permission flags from @a src onto the file at @a dst. Both
355  * filenames are utf8-encoded filenames.
356  *
357  * @since New in 1.6.
358  */
359 svn_error_t *
360 svn_io_copy_perms(const char *src,
361  const char *dst,
362  apr_pool_t *pool);
363 
364 
365 /**
366  * Copy symbolic link @a src to @a dst atomically. Overwrite @a dst
367  * if it exists, else create it. Both @a src and @a dst are
368  * utf8-encoded filenames. After copying, the @a dst link will point
369  * to the same thing @a src does.
370  *
371  * @since New in 1.1.
372  */
373 svn_error_t *
374 svn_io_copy_link(const char *src,
375  const char *dst,
376  apr_pool_t *pool);
377 
378 
379 /** Recursively copy directory @a src into @a dst_parent, as a new entry named
380  * @a dst_basename. If @a dst_basename already exists in @a dst_parent,
381  * return error. @a copy_perms will be passed through to svn_io_copy_file()
382  * when any files are copied. @a src, @a dst_parent, and @a dst_basename are
383  * all utf8-encoded.
384  *
385  * If @a cancel_func is non-NULL, invoke it with @a cancel_baton at
386  * various points during the operation. If it returns any error
387  * (typically #SVN_ERR_CANCELLED), return that error immediately.
388  */
389 svn_error_t *
390 svn_io_copy_dir_recursively(const char *src,
391  const char *dst_parent,
392  const char *dst_basename,
393  svn_boolean_t copy_perms,
394  svn_cancel_func_t cancel_func,
395  void *cancel_baton,
396  apr_pool_t *pool);
397 
398 
399 /** Create directory @a path on the file system, creating intermediate
400  * directories as required, like <tt>mkdir -p</tt>. Report no error if @a
401  * path already exists. @a path is utf8-encoded.
402  *
403  * This is essentially a wrapper for apr_dir_make_recursive(), passing
404  * @c APR_OS_DEFAULT as the permissions.
405  */
406 svn_error_t *
407 svn_io_make_dir_recursively(const char *path,
408  apr_pool_t *pool);
409 
410 
411 /** Set @a *is_empty_p to @c TRUE if directory @a path is empty, else to
412  * @c FALSE if it is not empty. @a path must be a directory, and is
413  * utf8-encoded. Use @a pool for temporary allocation.
414  */
415 svn_error_t *
416 svn_io_dir_empty(svn_boolean_t *is_empty_p,
417  const char *path,
418  apr_pool_t *pool);
419 
420 
421 /** Append @a src to @a dst. @a dst will be appended to if it exists, else it
422  * will be created. Both @a src and @a dst are utf8-encoded.
423  */
424 svn_error_t *
425 svn_io_append_file(const char *src,
426  const char *dst,
427  apr_pool_t *pool);
428 
429 
430 /** Make a file as read-only as the operating system allows.
431  * @a path is the utf8-encoded path to the file. If @a ignore_enoent is
432  * @c TRUE, don't fail if the target file doesn't exist.
433  *
434  * If @a path is a symlink, do nothing.
435  *
436  * @note If @a path is a directory, act on it as though it were a
437  * file, as described above, but note that you probably don't want to
438  * call this function on directories. We have left it effective on
439  * directories for compatibility reasons, but as its name implies, it
440  * should be used only for files.
441  */
442 svn_error_t *
443 svn_io_set_file_read_only(const char *path,
444  svn_boolean_t ignore_enoent,
445  apr_pool_t *pool);
446 
447 
448 /** Make a file as writable as the operating system allows.
449  * @a path is the utf8-encoded path to the file. If @a ignore_enoent is
450  * @c TRUE, don't fail if the target file doesn't exist.
451  * @warning On Unix this function will do the equivalent of chmod a+w path.
452  * If this is not what you want you should not use this function, but rather
453  * use apr_file_perms_set().
454  *
455  * If @a path is a symlink, do nothing.
456  *
457  * @note If @a path is a directory, act on it as though it were a
458  * file, as described above, but note that you probably don't want to
459  * call this function on directories. We have left it effective on
460  * directories for compatibility reasons, but as its name implies, it
461  * should be used only for files.
462  */
463 svn_error_t *
464 svn_io_set_file_read_write(const char *path,
465  svn_boolean_t ignore_enoent,
466  apr_pool_t *pool);
467 
468 
469 /** Similar to svn_io_set_file_read_* functions.
470  * Change the read-write permissions of a file.
471  * @since New in 1.1.
472  *
473  * When making @a path read-write on operating systems with unix style
474  * permissions, set the permissions on @a path to the permissions that
475  * are set when a new file is created (effectively honoring the user's
476  * umask).
477  *
478  * When making the file read-only on operating systems with unix style
479  * permissions, remove all write permissions.
480  *
481  * On other operating systems, toggle the file's "writability" as much as
482  * the operating system allows.
483  *
484  * @a path is the utf8-encoded path to the file. If @a enable_write
485  * is @c TRUE, then make the file read-write. If @c FALSE, make it
486  * read-only. If @a ignore_enoent is @c TRUE, don't fail if the target
487  * file doesn't exist.
488  *
489  * @deprecated Provided for backward compatibility with the 1.3 API.
490  */
492 svn_error_t *
493 svn_io_set_file_read_write_carefully(const char *path,
494  svn_boolean_t enable_write,
495  svn_boolean_t ignore_enoent,
496  apr_pool_t *pool);
497 
498 /** Set @a path's "executability" (but do nothing if it is a symlink).
499  *
500  * @a path is the utf8-encoded path to the file. If @a executable
501  * is @c TRUE, then make the file executable. If @c FALSE, make it
502  * non-executable. If @a ignore_enoent is @c TRUE, don't fail if the target
503  * file doesn't exist.
504  *
505  * When making the file executable on operating systems with unix style
506  * permissions, never add an execute permission where there is not
507  * already a read permission: that is, only make the file executable
508  * for the user, group or world if the corresponding read permission
509  * is already set for user, group or world.
510  *
511  * When making the file non-executable on operating systems with unix style
512  * permissions, remove all execute permissions.
513  *
514  * On other operating systems, toggle the file's "executability" as much as
515  * the operating system allows.
516  *
517  * @note If @a path is a directory, act on it as though it were a
518  * file, as described above, but note that you probably don't want to
519  * call this function on directories. We have left it effective on
520  * directories for compatibility reasons, but as its name implies, it
521  * should be used only for files.
522  */
523 svn_error_t *
524 svn_io_set_file_executable(const char *path,
525  svn_boolean_t executable,
526  svn_boolean_t ignore_enoent,
527  apr_pool_t *pool);
528 
529 /** Determine whether a file is executable by the current user.
530  * Set @a *executable to @c TRUE if the file @a path is executable by the
531  * current user, otherwise set it to @c FALSE.
532  *
533  * On Windows and on platforms without userids, always returns @c FALSE.
534  */
535 svn_error_t *
537  const char *path,
538  apr_pool_t *pool);
539 
540 
541 /** Read a line from @a file into @a buf, but not exceeding @a *limit bytes.
542  * Does not include newline, instead '\\0' is put there.
543  * Length (as in strlen) is returned in @a *limit.
544  * @a buf should be pre-allocated.
545  * @a file should be already opened.
546  *
547  * When the file is out of lines, @c APR_EOF will be returned.
548  */
549 svn_error_t *
550 svn_io_read_length_line(apr_file_t *file,
551  char *buf,
552  apr_size_t *limit,
553  apr_pool_t *pool);
554 
555 
556 /** Set @a *apr_time to the time of last modification of the contents of the
557  * file @a path. @a path is utf8-encoded.
558  *
559  * @note This is the APR mtime which corresponds to the traditional mtime
560  * on Unix, and the last write time on Windows.
561  */
562 svn_error_t *
563 svn_io_file_affected_time(apr_time_t *apr_time,
564  const char *path,
565  apr_pool_t *pool);
566 
567 /** Set the timestamp of file @a path to @a apr_time. @a path is
568  * utf8-encoded.
569  *
570  * @note This is the APR mtime which corresponds to the traditional mtime
571  * on Unix, and the last write time on Windows.
572  */
573 svn_error_t *
574 svn_io_set_file_affected_time(apr_time_t apr_time,
575  const char *path,
576  apr_pool_t *pool);
577 
578 /** Sleep to ensure that any files modified after we exit have a different
579  * timestamp than the one we recorded. If @a path is not NULL, check if we
580  * can determine how long we should wait for a new timestamp on the filesystem
581  * containing @a path, an existing file or directory. If @a path is NULL or we
582  * can't determine the timestamp resolution, sleep until the next second.
583  *
584  * Use @a pool for any necessary allocations. @a pool can be null if @a path
585  * is NULL.
586  *
587  * Errors while retrieving the timestamp resolution will result in sleeping
588  * to the next second, to keep the working copy stable in error conditions.
589  *
590  * @since New in 1.6.
591  */
592 void
593 svn_io_sleep_for_timestamps(const char *path, apr_pool_t *pool);
594 
595 /** Set @a *different_p to non-zero if @a file1 and @a file2 have different
596  * sizes, else set to zero. Both @a file1 and @a file2 are utf8-encoded.
597  *
598  * Setting @a *different_p to zero does not mean the files definitely
599  * have the same size, it merely means that the sizes are not
600  * definitely different. That is, if the size of one or both files
601  * cannot be determined, then the sizes are not known to be different,
602  * so @a *different_p is set to 0.
603  */
604 svn_error_t *
606  const char *file1,
607  const char *file2,
608  apr_pool_t *pool);
609 
610 
611 /** Return in @a *checksum the checksum of type @a kind of @a file
612  * Use @a pool for temporary allocations and to allocate @a *checksum.
613  *
614  * @since New in 1.6.
615  */
616 svn_error_t *
618  const char *file,
619  svn_checksum_kind_t kind,
620  apr_pool_t *pool);
621 
622 
623 /** Put the md5 checksum of @a file into @a digest.
624  * @a digest points to @c APR_MD5_DIGESTSIZE bytes of storage.
625  * Use @a pool only for temporary allocations.
626  *
627  * @deprecated Provided for backward compatibility with the 1.5 API.
628  */
630 svn_error_t *
631 svn_io_file_checksum(unsigned char digest[],
632  const char *file,
633  apr_pool_t *pool);
634 
635 
636 /** Set @a *same to TRUE if @a file1 and @a file2 have the same
637  * contents, else set it to FALSE. Use @a pool for temporary allocations.
638  */
639 svn_error_t *
641  const char *file1,
642  const char *file2,
643  apr_pool_t *pool);
644 
645 /** Create file at utf8-encoded @a file with contents @a contents.
646  * @a file must not already exist.
647  * Use @a pool for memory allocations.
648  */
649 svn_error_t *
650 svn_io_file_create(const char *file,
651  const char *contents,
652  apr_pool_t *pool);
653 
654 /**
655  * Lock file at @a lock_file. If @a exclusive is TRUE,
656  * obtain exclusive lock, otherwise obtain shared lock.
657  * Lock will be automatically released when @a pool is cleared or destroyed.
658  * Use @a pool for memory allocations.
659  *
660  * @deprecated Provided for backward compatibility with the 1.0 API.
661  */
663 svn_error_t *
664 svn_io_file_lock(const char *lock_file,
665  svn_boolean_t exclusive,
666  apr_pool_t *pool);
667 
668 /**
669  * Lock file at @a lock_file. If @a exclusive is TRUE,
670  * obtain exclusive lock, otherwise obtain shared lock.
671  *
672  * If @a nonblocking is TRUE, do not wait for the lock if it
673  * is not available: throw an error instead.
674  *
675  * Lock will be automatically released when @a pool is cleared or destroyed.
676  * Use @a pool for memory allocations.
677  *
678  * @since New in 1.1.
679  */
680 svn_error_t *
681 svn_io_file_lock2(const char *lock_file,
682  svn_boolean_t exclusive,
683  svn_boolean_t nonblocking,
684  apr_pool_t *pool);
685 /**
686  * Flush any unwritten data from @a file to disk. Use @a pool for
687  * memory allocations.
688  *
689  * @since New in 1.1.
690  */
691 svn_error_t *
692 svn_io_file_flush_to_disk(apr_file_t *file,
693  apr_pool_t *pool);
694 
695 /** Copy the file whose basename (or relative path) is @a file within
696  * directory @a src_path to the same basename (or relative path) within
697  * directory @a dest_path. Overwrite the destination file if it already
698  * exists. The destination directory (including any directory
699  * components in @a name) must already exist. Set the destination
700  * file's permissions to match those of the source. Use @a pool for
701  * memory allocations.
702  */
703 svn_error_t *
704 svn_io_dir_file_copy(const char *src_path,
705  const char *dest_path,
706  const char *file,
707  apr_pool_t *pool);
708 
709 
710 /** Generic byte-streams
711  *
712  * @defgroup svn_io_byte_streams Generic byte streams
713  * @{
714  */
715 
716 /** An abstract stream of bytes--either incoming or outgoing or both.
717  *
718  * The creator of a stream sets functions to handle read and write.
719  * Both of these handlers accept a baton whose value is determined at
720  * stream creation time; this baton can point to a structure
721  * containing data associated with the stream. If a caller attempts
722  * to invoke a handler which has not been set, it will generate a
723  * runtime assertion failure. The creator can also set a handler for
724  * close requests so that it can flush buffered data or whatever;
725  * if a close handler is not specified, a close request on the stream
726  * will simply be ignored. Note that svn_stream_close() does not
727  * deallocate the memory used to allocate the stream structure; free
728  * the pool you created the stream in to free that memory.
729  *
730  * The read and write handlers accept length arguments via pointer.
731  * On entry to the handler, the pointed-to value should be the amount
732  * of data which can be read or the amount of data to write. When the
733  * handler returns, the value is reset to the amount of data actually
734  * read or written. Handlers are obliged to complete a read or write
735  * to the maximum extent possible; thus, a short read with no
736  * associated error implies the end of the input stream, and a short
737  * write should never occur without an associated error.
738  *
739  * In Subversion 1.7 reset support was added as an optional feature of
740  * streams. If a stream implements resetting it allows reading the data
741  * again after a successful call to svn_stream_reset().
742  */
743 typedef struct svn_stream_t svn_stream_t;
744 
745 
746 
747 /** Read handler function for a generic stream. @see svn_stream_t. */
748 typedef svn_error_t *(*svn_read_fn_t)(void *baton,
749  char *buffer,
750  apr_size_t *len);
751 
752 /** Skip data handler function for a generic stream. @see svn_stream_t
753  * and svn_stream_skip().
754  * @since New in 1.7.
755  */
756 typedef svn_error_t *(*svn_stream_skip_fn_t)(void *baton,
757  apr_size_t len);
758 
759 /** Write handler function for a generic stream. @see svn_stream_t. */
760 typedef svn_error_t *(*svn_write_fn_t)(void *baton,
761  const char *data,
762  apr_size_t *len);
763 
764 /** Close handler function for a generic stream. @see svn_stream_t. */
765 typedef svn_error_t *(*svn_close_fn_t)(void *baton);
766 
767 /** An opaque type which represents a mark on a stream. There is no
768  * concrete definition of this type, it is a named type for stream
769  * implementation specific baton pointers.
770  *
771  * @see svn_stream_mark().
772  * @since New in 1.7.
773  */
775 
776 /** Mark handler function for a generic stream. @see svn_stream_t and
777  * svn_stream_mark().
778  *
779  * @since New in 1.7.
780  */
781 typedef svn_error_t *(*svn_stream_mark_fn_t)(void *baton,
782  svn_stream_mark_t **mark,
783  apr_pool_t *pool);
784 
785 /** Seek handler function for a generic stream. @see svn_stream_t and
786  * svn_stream_seek().
787  *
788  * @since New in 1.7.
789  */
790 typedef svn_error_t *(*svn_stream_seek_fn_t)(void *baton,
791  const svn_stream_mark_t *mark);
792 
793 /** Create a generic stream. @see svn_stream_t. */
794 svn_stream_t *
795 svn_stream_create(void *baton,
796  apr_pool_t *pool);
797 
798 /** Set @a stream's baton to @a baton */
799 void
801  void *baton);
802 
803 /** Set @a stream's read function to @a read_fn */
804 void
806  svn_read_fn_t read_fn);
807 
808 /** Set @a stream's skip function to @a skip_fn
809  *
810  * @since New in 1.7
811  */
812 void
814  svn_stream_skip_fn_t skip_fn);
815 
816 /** Set @a stream's write function to @a write_fn */
817 void
819  svn_write_fn_t write_fn);
820 
821 /** Set @a stream's close function to @a close_fn */
822 void
824  svn_close_fn_t close_fn);
825 
826 /** Set @a stream's mark function to @a mark_fn
827  *
828  * @since New in 1.7.
829  */
830 void
832  svn_stream_mark_fn_t mark_fn);
833 
834 /** Set @a stream's seek function to @a seek_fn
835  *
836  * @since New in 1.7.
837  */
838 void
840  svn_stream_seek_fn_t seek_fn);
841 
842 /** Create a stream that is empty for reading and infinite for writing. */
843 svn_stream_t *
844 svn_stream_empty(apr_pool_t *pool);
845 
846 /** Return a stream allocated in @a pool which forwards all requests
847  * to @a stream. Destruction is explicitly excluded from forwarding.
848  *
849  * @see notes/destruction-of-stacked-resources
850  *
851  * @since New in 1.4.
852  */
853 svn_stream_t *
855  apr_pool_t *pool);
856 
857 
858 /** Create a stream to read the file at @a path. It will be opened using
859  * the APR_BUFFERED and APR_BINARY flag, and APR_OS_DEFAULT for the perms.
860  * If you'd like to use different values, then open the file yourself, and
861  * use the svn_stream_from_aprfile2() interface.
862  *
863  * The stream will be returned in @a stream, and allocated from @a result_pool.
864  * Temporary allocations will be performed in @a scratch_pool.
865  *
866  * @since New in 1.6
867  */
868 svn_error_t *
870  const char *path,
871  apr_pool_t *result_pool,
872  apr_pool_t *scratch_pool);
873 
874 
875 /** Create a stream to write a file at @a path. The file will be *created*
876  * using the APR_BUFFERED and APR_BINARY flag, and APR_OS_DEFAULT for the
877  * perms. The file will be created "exclusively", so if it already exists,
878  * then an error will be thrown. If you'd like to use different values, or
879  * open an existing file, then open the file yourself, and use the
880  * svn_stream_from_aprfile2() interface.
881  *
882  * The stream will be returned in @a stream, and allocated from @a result_pool.
883  * Temporary allocations will be performed in @a scratch_pool.
884  *
885  * @since New in 1.6
886  */
887 svn_error_t *
889  const char *path,
890  apr_pool_t *result_pool,
891  apr_pool_t *scratch_pool);
892 
893 
894 /** Create a writable stream to a file in the directory @a dirpath.
895  * The file will have an arbitrary and unique name, and the full path
896  * will be returned in @a temp_path. The stream will be returned in
897  * @a stream. Both will be allocated from @a result_pool.
898  *
899  * If @a dirpath is @c NULL, use the path returned from svn_io_temp_dir().
900  * (Note that when using the system-provided temp directory, it may not
901  * be possible to atomically rename the resulting file due to cross-device
902  * issues.)
903  *
904  * The file will be deleted according to @a delete_when.
905  *
906  * Temporary allocations will be performed in @a scratch_pool.
907  *
908  * @since New in 1.6
909  * @see svn_io_open_unique_file3()
910  */
911 svn_error_t *
913  const char **temp_path,
914  const char *dirpath,
915  svn_io_file_del_t delete_when,
916  apr_pool_t *result_pool,
917  apr_pool_t *scratch_pool);
918 
919 
920 /** Create a stream from an APR file. For convenience, if @a file is
921  * @c NULL, an empty stream created by svn_stream_empty() is returned.
922  *
923  * This function should normally be called with @a disown set to FALSE,
924  * in which case closing the stream will also close the underlying file.
925  *
926  * If @a disown is TRUE, the stream will disown the underlying file,
927  * meaning that svn_stream_close() will not close the file.
928  *
929  * @since New in 1.4.
930  */
931 svn_stream_t *
932 svn_stream_from_aprfile2(apr_file_t *file,
933  svn_boolean_t disown,
934  apr_pool_t *pool);
935 
936 /** Similar to svn_stream_from_aprfile2(), except that the file will
937  * always be disowned.
938  *
939  * @note The stream returned is not considered to "own" the underlying
940  * file, meaning that svn_stream_close() on the stream will not
941  * close the file.
942  *
943  * @deprecated Provided for backward compatibility with the 1.3 API.
944  */
946 svn_stream_t *
947 svn_stream_from_aprfile(apr_file_t *file,
948  apr_pool_t *pool);
949 
950 /** Set @a *in to a generic stream connected to stdin, allocated in
951  * @a pool. The stream and its underlying APR handle will be closed
952  * when @a pool is cleared or destroyed.
953  *
954  * @since New in 1.7.
955  */
956 svn_error_t *
958  apr_pool_t *pool);
959 
960 /** Set @a *err to a generic stream connected to stderr, allocated in
961  * @a pool. The stream and its underlying APR handle will be closed
962  * when @a pool is cleared or destroyed.
963  *
964  * @since New in 1.7.
965  */
966 svn_error_t *
968  apr_pool_t *pool);
969 
970 /** Set @a *out to a generic stream connected to stdout, allocated in
971  * @a pool. The stream and its underlying APR handle will be closed
972  * when @a pool is cleared or destroyed.
973  */
974 svn_error_t *
976  apr_pool_t *pool);
977 
978 /** Return a generic stream connected to stringbuf @a str. Allocate the
979  * stream in @a pool.
980  */
981 svn_stream_t *
983  apr_pool_t *pool);
984 
985 /** Return a generic read-only stream connected to string @a str.
986  * Allocate the stream in @a pool.
987  */
988 svn_stream_t *
990  apr_pool_t *pool);
991 
992 /** Return a stream that decompresses all data read and compresses all
993  * data written. The stream @a stream is used to read and write all
994  * compressed data. All compression data structures are allocated on
995  * @a pool. If compression support is not compiled in then
996  * svn_stream_compressed() returns @a stream unmodified. Make sure you
997  * call svn_stream_close() on the stream returned by this function,
998  * so that all data are flushed and cleaned up.
999  *
1000  * @note From 1.4, compression support is always compiled in.
1001  */
1002 svn_stream_t *
1004  apr_pool_t *pool);
1005 
1006 /** Return a stream that calculates checksums for all data read
1007  * and written. The stream @a stream is used to read and write all data.
1008  * The stream and the resulting digests are allocated in @a pool.
1009  *
1010  * When the stream is closed, @a *read_checksum and @a *write_checksum
1011  * are set to point to the resulting checksums, of type @a read_checksum_kind
1012  * and @a write_checksum_kind, respectively.
1013  *
1014  * Both @a read_checksum and @a write_checksum can be @c NULL, in which case
1015  * the respective checksum isn't calculated.
1016  *
1017  * If @a read_all is TRUE, make sure that all data available on @a
1018  * stream is read (and checksummed) when the stream is closed.
1019  *
1020  * Read and write operations can be mixed without interfering.
1021  *
1022  * The @a stream passed into this function is closed when the created
1023  * stream is closed.
1024  *
1025  * @since New in 1.6.
1026  */
1027 svn_stream_t *
1029  svn_checksum_t **read_checksum,
1030  svn_checksum_t **write_checksum,
1031  svn_checksum_kind_t checksum_kind,
1032  svn_boolean_t read_all,
1033  apr_pool_t *pool);
1034 
1035 /**
1036  * Similar to svn_stream_checksummed2(), but always returning the MD5
1037  * checksum in @a read_digest and @a write_digest.
1038  *
1039  * @since New in 1.4.
1040  * @deprecated Provided for backward compatibility with the 1.5 API.
1041  */
1043 svn_stream_t *
1045  const unsigned char **read_digest,
1046  const unsigned char **write_digest,
1047  svn_boolean_t read_all,
1048  apr_pool_t *pool);
1049 
1050 /** Read from a generic stream. @see svn_stream_t. */
1051 svn_error_t *
1053  char *buffer,
1054  apr_size_t *len);
1055 
1056 /**
1057  * Skip @a len bytes from a generic @a stream. If the stream is exhausted
1058  * before @a len bytes have been read, return an error.
1059  *
1060  * @note No assumption can be made on the semantics of this function
1061  * other than that the stream read pointer will be advanced by *len
1062  * bytes. Depending on the capabilities of the underlying stream
1063  * implementation, this may for instance be translated into a sequence
1064  * of reads or a simple seek operation. If the stream implementation has
1065  * not provided a skip function, this will read from the stream and
1066  * discard the data.
1067  */
1068 svn_error_t *
1070  apr_size_t len);
1071 
1072 /** Write to a generic stream. @see svn_stream_t. */
1073 svn_error_t *
1075  const char *data,
1076  apr_size_t *len);
1077 
1078 /** Close a generic stream. @see svn_stream_t. */
1079 svn_error_t *
1081 
1082 /** Reset a generic stream back to its origin. E.g. On a file this would be
1083  * implemented as a seek to position 0). This function returns a
1084  * #SVN_ERR_STREAM_RESET_NOT_SUPPORTED error when the stream doesn't
1085  * implement resetting.
1086  *
1087  * @since New in 1.7.
1088  */
1089 svn_error_t *
1091 
1092 /** Returns @c TRUE if the generic @a stream supports svn_stream_mark().
1093  *
1094  * @see svn_stream_mark()
1095  * @since New in 1.7.
1096  */
1099 
1100 /** Set a @a mark at the current position of a generic @a stream,
1101  * which can later be sought back to using svn_stream_seek().
1102  * The @a mark is allocated in @a pool.
1103  *
1104  * This function returns the #SVN_ERR_STREAM_SEEK_NOT_SUPPORTED error
1105  * if the stream doesn't implement seeking.
1106  *
1107  * @see svn_stream_seek()
1108  * @since New in 1.7.
1109  */
1110 svn_error_t *
1112  svn_stream_mark_t **mark,
1113  apr_pool_t *pool);
1114 
1115 /** Seek to a @a mark in a generic @a stream.
1116  * This function returns the #SVN_ERR_STREAM_SEEK_NOT_SUPPORTED error
1117  * if the stream doesn't implement seeking. Passing NULL as @a mark,
1118  * seeks to the start of the stream.
1119  *
1120  * @see svn_stream_mark()
1121  * @since New in 1.7.
1122  */
1123 svn_error_t *
1124 svn_stream_seek(svn_stream_t *stream, const svn_stream_mark_t *mark);
1125 
1126 /** Return a writable stream which, when written to, writes to both of the
1127  * underlying streams. Both of these streams will be closed upon closure of
1128  * the returned stream; use svn_stream_disown() if this is not the desired
1129  * behavior. One or both of @a out1 and @a out2 may be @c NULL. If both are
1130  * @c NULL, @c NULL is returned.
1131  *
1132  * @since New in 1.7.
1133  */
1134 svn_stream_t *
1136  svn_stream_t *out2,
1137  apr_pool_t *pool);
1138 
1139 
1140 /** Write to @a stream using a printf-style @a fmt specifier, passed through
1141  * apr_psprintf() using memory from @a pool.
1142  */
1143 svn_error_t *
1145  apr_pool_t *pool,
1146  const char *fmt,
1147  ...)
1148  __attribute__((format(printf, 3, 4)));
1149 
1150 /** Write to @a stream using a printf-style @a fmt specifier, passed through
1151  * apr_psprintf() using memory from @a pool. The resulting string
1152  * will be translated to @a encoding before it is sent to @a stream.
1153  *
1154  * @note Use @c APR_LOCALE_CHARSET to translate to the encoding of the
1155  * current locale.
1156  *
1157  * @since New in 1.3.
1158  */
1159 svn_error_t *
1161  const char *encoding,
1162  apr_pool_t *pool,
1163  const char *fmt,
1164  ...)
1165  __attribute__((format(printf, 4, 5)));
1166 
1167 /** Allocate @a *stringbuf in @a pool, and read into it one line (terminated
1168  * by @a eol) from @a stream. The line-terminator is read from the stream,
1169  * but is not added to the end of the stringbuf. Instead, the stringbuf
1170  * ends with a usual '\\0'.
1171  *
1172  * If @a stream runs out of bytes before encountering a line-terminator,
1173  * then set @a *eof to @c TRUE, otherwise set @a *eof to FALSE.
1174  */
1175 svn_error_t *
1177  svn_stringbuf_t **stringbuf,
1178  const char *eol,
1179  svn_boolean_t *eof,
1180  apr_pool_t *pool);
1181 
1182 /**
1183  * Read the contents of the readable stream @a from and write them to the
1184  * writable stream @a to calling @a cancel_func before copying each chunk.
1185  *
1186  * @a cancel_func may be @c NULL.
1187  *
1188  * @note both @a from and @a to will be closed upon successful completion of
1189  * the copy (but an error may still be returned, based on trying to close
1190  * the two streams). If the closure is not desired, then you can use
1191  * svn_stream_disown() to protect either or both of the streams from
1192  * being closed.
1193  *
1194  * @since New in 1.6.
1195  */
1196 svn_error_t *
1198  svn_stream_t *to,
1199  svn_cancel_func_t cancel_func,
1200  void *cancel_baton,
1201  apr_pool_t *pool);
1202 
1203 /**
1204  * Same as svn_stream_copy3() but the streams are not closed.
1205  *
1206  * @since New in 1.5.
1207  * @deprecated Provided for backward compatibility with the 1.5 API.
1208  */
1210 svn_error_t *
1212  svn_stream_t *to,
1213  svn_cancel_func_t cancel_func,
1214  void *cancel_baton,
1215  apr_pool_t *pool);
1216 
1217 /**
1218  * Same as svn_stream_copy3(), but without the cancellation function
1219  * or stream closing.
1220  *
1221  * @since New in 1.1.
1222  * @deprecated Provided for backward compatibility with the 1.4 API.
1223  */
1225 svn_error_t *
1227  svn_stream_t *to,
1228  apr_pool_t *pool);
1229 
1230 
1231 /** Set @a *same to TRUE if @a stream1 and @a stream2 have the same
1232  * contents, else set it to FALSE.
1233  *
1234  * Both streams will be closed before this function returns (regardless of
1235  * the result, or any possible error).
1236  *
1237  * Use @a scratch_pool for temporary allocations.
1238  *
1239  * @since New in 1.7.
1240  */
1241 svn_error_t *
1243  svn_stream_t *stream1,
1244  svn_stream_t *stream2,
1245  apr_pool_t *pool);
1246 
1247 
1248 /**
1249  * Same as svn_stream_contents_same2(), but the streams will not be closed.
1250  *
1251  * @since New in 1.4.
1252  * @deprecated Provided for backward compatibility with the 1.6 API.
1253  */
1255 svn_error_t *
1257  svn_stream_t *stream1,
1258  svn_stream_t *stream2,
1259  apr_pool_t *pool);
1260 
1261 
1262 /** Read the contents of @a stream into memory, returning the data in
1263  * @a result. The stream will be closed when it has been successfully and
1264  * completely read.
1265  *
1266  * The returned memory is allocated in @a result_pool, and any temporary
1267  * allocations are performed in @a scratch_pool.
1268  *
1269  * @note due to memory pseudo-reallocation behavior (due to pools), this
1270  * can be a memory-intensive operation for large files.
1271  *
1272  * @since New in 1.6
1273  */
1274 svn_error_t *
1276  svn_stream_t *stream,
1277  apr_pool_t *result_pool,
1278  apr_pool_t *scratch_pool);
1279 
1280 
1281 /** @} */
1282 
1283 /** Set @a *result to a string containing the contents of @a
1284  * filename, which is either "-" (indicating that stdin should be
1285  * read) or the utf8-encoded path of a real file.
1286  *
1287  * @warning Callers should be aware of possible unexpected results
1288  * when using this function to read from stdin where additional
1289  * stdin-reading processes abound. For example, if a program tries
1290  * both to invoke an external editor and to read from stdin, stdin
1291  * could be trashed and the editor might act funky or die outright.
1292  *
1293  * @note due to memory pseudo-reallocation behavior (due to pools), this
1294  * can be a memory-intensive operation for large files.
1295  *
1296  * @since New in 1.5.
1297  */
1298 svn_error_t *
1300  const char *filename,
1301  apr_pool_t *pool);
1302 
1303 /** Similar to svn_stringbuf_from_file2(), except that if @a filename
1304  * is "-", return the error #SVN_ERR_UNSUPPORTED_FEATURE and don't
1305  * touch @a *result.
1306  *
1307  * @deprecated Provided for backwards compatibility with the 1.4 API.
1308  */
1310 svn_error_t *
1312  const char *filename,
1313  apr_pool_t *pool);
1314 
1315 /** Sets @a *result to a string containing the contents of the already opened
1316  * @a file. Reads from the current position in file to the end. Does not
1317  * close the file or reset the cursor position.
1318  *
1319  * @note due to memory pseudo-reallocation behavior (due to pools), this
1320  * can be a memory-intensive operation for large files.
1321  */
1322 svn_error_t *
1324  apr_file_t *file,
1325  apr_pool_t *pool);
1326 
1327 /** Remove file @a path, a utf8-encoded path. This wraps apr_file_remove(),
1328  * converting any error to a Subversion error. If @a ignore_enoent is TRUE, and
1329  * the file is not present (APR_STATUS_IS_ENOENT returns TRUE), then no
1330  * error will be returned.
1331  *
1332  * The file will be removed even if it is not writable. (On Windows and
1333  * OS/2, this function first clears the file's read-only bit.)
1334  *
1335  * @since New in 1.7.
1336  */
1337 svn_error_t *
1338 svn_io_remove_file2(const char *path,
1339  svn_boolean_t ignore_enoent,
1340  apr_pool_t *scratch_pool);
1341 
1342 /** Similar to svn_io_remove_file2(), except with @a ignore_enoent set to FALSE.
1343  *
1344  * @deprecated Provided for backwards compatibility with the 1.6 API.
1345  */
1347 svn_error_t *
1348 svn_io_remove_file(const char *path,
1349  apr_pool_t *pool);
1350 
1351 /** Recursively remove directory @a path. @a path is utf8-encoded.
1352  * If @a ignore_enoent is @c TRUE, don't fail if the target directory
1353  * doesn't exist. Use @a pool for temporary allocations.
1354  *
1355  * Because recursive delete of a directory tree can be a lengthy operation,
1356  * provide @a cancel_func and @a cancel_baton for interruptibility.
1357  *
1358  * @since New in 1.5.
1359  */
1360 svn_error_t *
1361 svn_io_remove_dir2(const char *path,
1362  svn_boolean_t ignore_enoent,
1363  svn_cancel_func_t cancel_func,
1364  void *cancel_baton,
1365  apr_pool_t *pool);
1366 
1367 /** Similar to svn_io_remove_dir2(), but with @a ignore_enoent set to
1368  * @c FALSE and @a cancel_func and @a cancel_baton set to @c NULL.
1369  *
1370  * @deprecated Provided for backward compatibility with the 1.4 API
1371  */
1373 svn_error_t *
1374 svn_io_remove_dir(const char *path,
1375  apr_pool_t *pool);
1376 
1377 /** Read all of the disk entries in directory @a path, a utf8-encoded
1378  * path. Set @a *dirents to a hash mapping dirent names (<tt>char *</tt>) to
1379  * undefined non-NULL values, allocated in @a pool.
1380  *
1381  * @note The `.' and `..' directories normally returned by
1382  * apr_dir_read() are NOT returned in the hash.
1383  *
1384  * @since New in 1.4.
1385  * @deprecated Provided for backward compatibility with the 1.6 API.
1386  */
1388 svn_error_t *
1389 svn_io_get_dir_filenames(apr_hash_t **dirents,
1390  const char *path,
1391  apr_pool_t *pool);
1392 
1393 /** Read all of the disk entries in directory @a path, a utf8-encoded
1394  * path. Set @a *dirents to a hash mapping dirent names (<tt>char *</tt>) to
1395  * #svn_io_dirent2_t structures, allocated in @a pool.
1396  *
1397  * If @a only_check_type is set to @c TRUE, only the kind and special
1398  * fields of the svn_io_dirent2_t are filled.
1399  *
1400  * @note The `.' and `..' directories normally returned by
1401  * apr_dir_read() are NOT returned in the hash.
1402  *
1403  * @note The kind field in the @a dirents is set according to the mapping
1404  * as documented for svn_io_check_path().
1405  *
1406  * @since New in 1.7.
1407  */
1408 svn_error_t *
1409 svn_io_get_dirents3(apr_hash_t **dirents,
1410  const char *path,
1411  svn_boolean_t only_check_type,
1412  apr_pool_t *result_pool,
1413  apr_pool_t *scratch_pool);
1414 
1415 
1416 /** Similar to svn_io_get_dirents3, but returns a mapping to svn_io_dirent_t
1417  * structures instead of svn_io_dirent2_t and with only a single pool.
1418  *
1419  * @since New in 1.3.
1420  * @deprecated Provided for backward compatibility with the 1.6 API.
1421  */
1423 svn_error_t *
1424 svn_io_get_dirents2(apr_hash_t **dirents,
1425  const char *path,
1426  apr_pool_t *pool);
1427 
1428 /** Similar to svn_io_get_dirents2(), but @a *dirents is a hash table
1429  * with #svn_node_kind_t values.
1430  *
1431  * @deprecated Provided for backwards compatibility with the 1.2 API.
1432  */
1434 svn_error_t *
1435 svn_io_get_dirents(apr_hash_t **dirents,
1436  const char *path,
1437  apr_pool_t *pool);
1438 
1439 /** Create a svn_io_dirent2_t instance for path. Specialized variant of
1440  * svn_io_stat() that directly translates node_kind and special.
1441  *
1442  * If @a ignore_enoent is set to @c TRUE, set *dirent_p->kind to
1443  * svn_node_none instead of returning an error.
1444  *
1445  * @since New in 1.7.
1446  */
1447 svn_error_t *
1448 svn_io_stat_dirent(const svn_io_dirent2_t **dirent_p,
1449  const char *path,
1450  svn_boolean_t ignore_enoent,
1451  apr_pool_t *result_pool,
1452  apr_pool_t *scratch_pool);
1453 
1454 
1455 /** Callback function type for svn_io_dir_walk() */
1456 typedef svn_error_t * (*svn_io_walk_func_t)(void *baton,
1457  const char *path,
1458  const apr_finfo_t *finfo,
1459  apr_pool_t *pool);
1460 
1461 /** Recursively walk the directory rooted at @a dirname, a
1462  * utf8-encoded path, invoking @a walk_func (with @a walk_baton) for
1463  * each item in the tree. For a given directory, invoke @a walk_func
1464  * on the directory itself before invoking it on any children thereof.
1465  *
1466  * Deliver to @a walk_func the information specified by @a wanted,
1467  * which is a combination of @c APR_FINFO_* flags, plus the
1468  * information specified by @c APR_FINFO_TYPE and @c APR_FINFO_NAME.
1469  *
1470  * Use @a pool for all allocations.
1471  *
1472  * @note This function does not currently pass all file types to @a
1473  * walk_func -- only APR_DIR, APR_REG, and APR_LNK. We reserve the
1474  * right to pass additional file types through this interface in the
1475  * future, though, so implementations of this callback should
1476  * explicitly test FINFO->filetype. See the APR library's
1477  * apr_filetype_e enum for the various filetypes and their meanings.
1478  *
1479  * @since New in 1.7.
1480  */
1481 svn_error_t *
1482 svn_io_dir_walk2(const char *dirname,
1483  apr_int32_t wanted,
1484  svn_io_walk_func_t walk_func,
1485  void *walk_baton,
1486  apr_pool_t *pool);
1487 
1488 /** Similar to svn_io_dir_walk(), but only calls @a walk_func for
1489  * files of type APR_DIR (directory) and APR_REG (regular file).
1490  *
1491  * @deprecated Provided for backwards compatibility with the 1.6 API.
1492  */
1494 svn_error_t *
1495 svn_io_dir_walk(const char *dirname,
1496  apr_int32_t wanted,
1497  svn_io_walk_func_t walk_func,
1498  void *walk_baton,
1499  apr_pool_t *pool);
1500 
1501 /**
1502  * Start @a cmd with @a args, using utf8-encoded @a path as working
1503  * directory. Return the process handle for the invoked program in @a
1504  * *cmd_proc.
1505  *
1506  * If @a infile_pipe is TRUE, connect @a cmd's stdin to a pipe;
1507  * otherwise, connect it to @a infile (which may be NULL). If
1508  * @a outfile_pipe is TRUE, connect @a cmd's stdout to a pipe; otherwise,
1509  * connect it to @a outfile (which may be NULL). If @a errfile_pipe
1510  * is TRUE, connect @a cmd's stderr to a pipe; otherwise, connect it
1511  * to @a errfile (which may be NULL). (Callers must pass FALSE for
1512  * each of these boolean values for which the corresponding file
1513  * handle is non-NULL.)
1514  *
1515  * @a args is a list of utf8-encoded <tt>const char *</tt> arguments,
1516  * terminated by @c NULL. @a args[0] is the name of the program, though it
1517  * need not be the same as @a cmd.
1518  *
1519  * If @a inherit is TRUE, the invoked program inherits its environment from
1520  * the caller and @a cmd, if not absolute, is searched for in PATH.
1521  * Otherwise, the invoked program runs with an empty environment and @a cmd
1522  * must be an absolute path.
1523  *
1524  * @note On some platforms, failure to execute @a cmd in the child process
1525  * will result in error output being written to @a errfile, if non-NULL, and
1526  * a non-zero exit status being returned to the parent process.
1527  *
1528  * @since New in 1.7.
1529  */
1530 svn_error_t *svn_io_start_cmd2(apr_proc_t *cmd_proc,
1531  const char *path,
1532  const char *cmd,
1533  const char *const *args,
1534  svn_boolean_t inherit,
1535  svn_boolean_t infile_pipe,
1536  apr_file_t *infile,
1537  svn_boolean_t outfile_pipe,
1538  apr_file_t *outfile,
1539  svn_boolean_t errfile_pipe,
1540  apr_file_t *errfile,
1541  apr_pool_t *pool);
1542 
1543 /**
1544  * Similar to svn_io_start_cmd2() but with @a infile_pipe, @a
1545  * outfile_pipe, and @a errfile_pipe always FALSE.
1546  *
1547  * @deprecated Provided for backward compatibility with the 1.6 API
1548  * @since New in 1.3.
1549  */
1551 svn_error_t *
1552 svn_io_start_cmd(apr_proc_t *cmd_proc,
1553  const char *path,
1554  const char *cmd,
1555  const char *const *args,
1556  svn_boolean_t inherit,
1557  apr_file_t *infile,
1558  apr_file_t *outfile,
1559  apr_file_t *errfile,
1560  apr_pool_t *pool);
1561 
1562 /**
1563  * Wait for the process @a *cmd_proc to complete and optionally retrieve
1564  * its exit code. @a cmd is used only in error messages.
1565  *
1566  * If @a exitcode is not NULL, set @a *exitcode to the exit code of the
1567  * process and do not consider any exit code to be an error. If @a exitcode
1568  * is NULL, then if the exit code of the process is non-zero then return an
1569  * #SVN_ERR_EXTERNAL_PROGRAM error.
1570  *
1571  * If @a exitwhy is not NULL, set @a *exitwhy to indicate why the process
1572  * terminated and do not consider any reason to be an error. If @a exitwhy
1573  * is NULL, then if the termination reason is not @c APR_PROC_CHECK_EXIT()
1574  * then return an #SVN_ERR_EXTERNAL_PROGRAM error.
1575  *
1576  * @since New in 1.3.
1577  */
1578 svn_error_t *
1579 svn_io_wait_for_cmd(apr_proc_t *cmd_proc,
1580  const char *cmd,
1581  int *exitcode,
1582  apr_exit_why_e *exitwhy,
1583  apr_pool_t *pool);
1584 
1585 /** Run a command to completion, by first calling svn_io_start_cmd() and
1586  * then calling svn_io_wait_for_cmd(). The parameters correspond to
1587  * the same-named parameters of those two functions.
1588  */
1589 svn_error_t *
1590 svn_io_run_cmd(const char *path,
1591  const char *cmd,
1592  const char *const *args,
1593  int *exitcode,
1594  apr_exit_why_e *exitwhy,
1595  svn_boolean_t inherit,
1596  apr_file_t *infile,
1597  apr_file_t *outfile,
1598  apr_file_t *errfile,
1599  apr_pool_t *pool);
1600 
1601 /** Invoke the configured @c diff program, with @a user_args (an array
1602  * of utf8-encoded @a num_user_args arguments) if they are specified
1603  * (that is, if @a user_args is non-NULL), or "-u" if they are not.
1604  * If @a user_args is NULL, the value of @a num_user_args is ignored.
1605  *
1606  * Diff runs in utf8-encoded @a dir, and its exit status is stored in
1607  * @a exitcode, if it is not @c NULL.
1608  *
1609  * If @a label1 and/or @a label2 are not NULL they will be passed to the diff
1610  * process as the arguments of "-L" options. @a label1 and @a label2 are also
1611  * in utf8, and will be converted to native charset along with the other args.
1612  *
1613  * @a from is the first file passed to diff, and @a to is the second. The
1614  * stdout of diff will be sent to @a outfile, and the stderr to @a errfile.
1615  *
1616  * @a diff_cmd must be non-NULL.
1617  *
1618  * Do all allocation in @a pool.
1619  * @since New in 1.6.0.
1620  */
1621 svn_error_t *
1622 svn_io_run_diff2(const char *dir,
1623  const char *const *user_args,
1624  int num_user_args,
1625  const char *label1,
1626  const char *label2,
1627  const char *from,
1628  const char *to,
1629  int *exitcode,
1630  apr_file_t *outfile,
1631  apr_file_t *errfile,
1632  const char *diff_cmd,
1633  apr_pool_t *pool);
1634 
1635 /** Similar to svn_io_run_diff2() but with @a diff_cmd encoded in internal
1636  * encoding used by APR.
1637  *
1638  * @deprecated Provided for backwards compatibility with the 1.5 API. */
1640 svn_error_t *
1641 svn_io_run_diff(const char *dir,
1642  const char *const *user_args,
1643  int num_user_args,
1644  const char *label1,
1645  const char *label2,
1646  const char *from,
1647  const char *to,
1648  int *exitcode,
1649  apr_file_t *outfile,
1650  apr_file_t *errfile,
1651  const char *diff_cmd,
1652  apr_pool_t *pool);
1653 
1654 
1655 
1656 /** Invoke the configured @c diff3 program, in utf8-encoded @a dir
1657  * like this:
1658  *
1659  * diff3 -E -m @a mine @a older @a yours > @a merged
1660  *
1661  * (See the diff3 documentation for details.)
1662  *
1663  * If @a user_args is non-NULL, replace "-E" with the <tt>const char*</tt>
1664  * elements that @a user_args contains.
1665  *
1666  * @a mine, @a older and @a yours are utf8-encoded paths (relative to
1667  * @a dir or absolute) to three files that already exist.
1668  *
1669  * @a merged is an open file handle, and is left open after the merge
1670  * result is written to it. (@a merged should *not* be the same file
1671  * as @a mine, or nondeterministic things may happen!)
1672  *
1673  * @a mine_label, @a older_label, @a yours_label are utf8-encoded label
1674  * parameters for diff3's -L option. Any of them may be @c NULL, in
1675  * which case the corresponding @a mine, @a older, or @a yours parameter is
1676  * used instead.
1677  *
1678  * Set @a *exitcode to diff3's exit status. If @a *exitcode is anything
1679  * other than 0 or 1, then return #SVN_ERR_EXTERNAL_PROGRAM. (Note the
1680  * following from the diff3 info pages: "An exit status of 0 means
1681  * `diff3' was successful, 1 means some conflicts were found, and 2
1682  * means trouble.")
1683  *
1684  * @a diff3_cmd must be non-NULL.
1685  *
1686  * Do all allocation in @a pool.
1687  *
1688  * @since New in 1.4.
1689  */
1690 svn_error_t *
1691 svn_io_run_diff3_3(int *exitcode,
1692  const char *dir,
1693  const char *mine,
1694  const char *older,
1695  const char *yours,
1696  const char *mine_label,
1697  const char *older_label,
1698  const char *yours_label,
1699  apr_file_t *merged,
1700  const char *diff3_cmd,
1701  const apr_array_header_t *user_args,
1702  apr_pool_t *pool);
1703 
1704 /** Similar to svn_io_run_diff3_3(), but with @a diff3_cmd encoded in
1705  * internal encoding used by APR.
1706  *
1707  * @deprecated Provided for backwards compatibility with the 1.5 API.
1708  * @since New in 1.4.
1709  */
1711 svn_error_t *
1712 svn_io_run_diff3_2(int *exitcode,
1713  const char *dir,
1714  const char *mine,
1715  const char *older,
1716  const char *yours,
1717  const char *mine_label,
1718  const char *older_label,
1719  const char *yours_label,
1720  apr_file_t *merged,
1721  const char *diff3_cmd,
1722  const apr_array_header_t *user_args,
1723  apr_pool_t *pool);
1724 
1725 /** Similar to svn_io_run_diff3_2(), but with @a user_args set to @c NULL.
1726  *
1727  * @deprecated Provided for backwards compatibility with the 1.3 API.
1728  */
1730 svn_error_t *
1731 svn_io_run_diff3(const char *dir,
1732  const char *mine,
1733  const char *older,
1734  const char *yours,
1735  const char *mine_label,
1736  const char *older_label,
1737  const char *yours_label,
1738  apr_file_t *merged,
1739  int *exitcode,
1740  const char *diff3_cmd,
1741  apr_pool_t *pool);
1742 
1743 
1744 /** Parse utf8-encoded @a mimetypes_file as a MIME types file (such as
1745  * is provided with Apache HTTP Server), and set @a *type_map to a
1746  * hash mapping <tt>const char *</tt> filename extensions to
1747  * <tt>const char *</tt> MIME types.
1748  *
1749  * @since New in 1.5.
1750  */
1751 svn_error_t *
1752 svn_io_parse_mimetypes_file(apr_hash_t **type_map,
1753  const char *mimetypes_file,
1754  apr_pool_t *pool);
1755 
1756 
1757 /** Examine utf8-encoded @a file to determine if it can be described by a
1758  * known (as in, known by this function) Multipurpose Internet Mail
1759  * Extension (MIME) type. If so, set @a *mimetype to a character string
1760  * describing the MIME type, else set it to @c NULL.
1761  *
1762  * If not @c NULL, @a mimetype_map is a hash mapping <tt>const char *</tt>
1763  * filename extensions to <tt>const char *</tt> MIME types, and is the
1764  * first source consulted regarding @a file's MIME type.
1765  *
1766  * Use @a pool for any necessary allocations.
1767  *
1768  * @since New in 1.5.
1769  */
1770 svn_error_t *
1771 svn_io_detect_mimetype2(const char **mimetype,
1772  const char *file,
1773  apr_hash_t *mimetype_map,
1774  apr_pool_t *pool);
1775 
1776 
1777 /** Like svn_io_detect_mimetype2, but with @a mimetypes_map set to
1778  * @c NULL.
1779  *
1780  * @deprecated Provided for backward compatibility with the 1.4 API
1781  */
1783 svn_error_t *
1784 svn_io_detect_mimetype(const char **mimetype,
1785  const char *file,
1786  apr_pool_t *pool);
1787 
1788 
1789 /** Examine up to @a len bytes of data in @a buf to determine if the
1790  * can be considered binary data, in which case return TRUE.
1791  * If the data can be considered plain-text data, return FALSE.
1792  *
1793  * @since New in 1.7.
1794  */
1796 svn_io_is_binary_data(const void *buf, apr_size_t len);
1797 
1798 
1799 /** Wrapper for apr_file_open(). @a fname is utf8-encoded. */
1800 svn_error_t *
1801 svn_io_file_open(apr_file_t **new_file,
1802  const char *fname,
1803  apr_int32_t flag,
1804  apr_fileperms_t perm,
1805  apr_pool_t *pool);
1806 
1807 
1808 /** Wrapper for apr_file_close(). */
1809 svn_error_t *
1810 svn_io_file_close(apr_file_t *file,
1811  apr_pool_t *pool);
1812 
1813 
1814 /** Wrapper for apr_file_getc(). */
1815 svn_error_t *
1816 svn_io_file_getc(char *ch,
1817  apr_file_t *file,
1818  apr_pool_t *pool);
1819 
1820 
1821 /** Wrapper for apr_file_putc().
1822  * @since New in 1.7
1823  */
1824 svn_error_t *
1825 svn_io_file_putc(char ch,
1826  apr_file_t *file,
1827  apr_pool_t *pool);
1828 
1829 
1830 /** Wrapper for apr_file_info_get(). */
1831 svn_error_t *
1832 svn_io_file_info_get(apr_finfo_t *finfo,
1833  apr_int32_t wanted,
1834  apr_file_t *file,
1835  apr_pool_t *pool);
1836 
1837 
1838 /** Wrapper for apr_file_read(). */
1839 svn_error_t *
1840 svn_io_file_read(apr_file_t *file,
1841  void *buf,
1842  apr_size_t *nbytes,
1843  apr_pool_t *pool);
1844 
1845 
1846 /** Wrapper for apr_file_read_full().
1847  *
1848  * If @a hit_eof is not NULL, EOF will be indicated there and no
1849  * svn_error_t error object will be created upon EOF.
1850  *
1851  * @since New in 1.7
1852  */
1853 svn_error_t *
1854 svn_io_file_read_full2(apr_file_t *file,
1855  void *buf,
1856  apr_size_t nbytes,
1857  apr_size_t *bytes_read,
1858  svn_boolean_t *hit_eof,
1859  apr_pool_t *pool);
1860 
1861 
1862 /** Similar to svn_io_file_read_full2 with hit_eof being set
1863  * to @c NULL.
1864  *
1865  * @deprecated Provided for backward compatibility with the 1.6 API
1866  */
1868 svn_error_t *
1869 svn_io_file_read_full(apr_file_t *file,
1870  void *buf,
1871  apr_size_t nbytes,
1872  apr_size_t *bytes_read,
1873  apr_pool_t *pool);
1874 
1875 
1876 /** Wrapper for apr_file_seek(). */
1877 svn_error_t *
1878 svn_io_file_seek(apr_file_t *file,
1879  apr_seek_where_t where,
1880  apr_off_t *offset,
1881  apr_pool_t *pool);
1882 
1883 
1884 /** Wrapper for apr_file_write(). */
1885 svn_error_t *
1886 svn_io_file_write(apr_file_t *file,
1887  const void *buf,
1888  apr_size_t *nbytes,
1889  apr_pool_t *pool);
1890 
1891 
1892 /** Wrapper for apr_file_write_full(). */
1893 svn_error_t *
1894 svn_io_file_write_full(apr_file_t *file,
1895  const void *buf,
1896  apr_size_t nbytes,
1897  apr_size_t *bytes_written,
1898  apr_pool_t *pool);
1899 
1900 /**
1901  * Open a unique file in @a dirpath, and write @a nbytes from @a buf to
1902  * the file before flushing it to disk and closing it. Return the name
1903  * of the newly created file in @a *tmp_path, allocated in @a pool.
1904  *
1905  * If @a dirpath is @c NULL, use the path returned from svn_io_temp_dir().
1906  * (Note that when using the system-provided temp directory, it may not
1907  * be possible to atomically rename the resulting file due to cross-device
1908  * issues.)
1909  *
1910  * The file will be deleted according to @a delete_when.
1911  *
1912  * @since New in 1.6.
1913  */
1914 svn_error_t *
1915 svn_io_write_unique(const char **tmp_path,
1916  const char *dirpath,
1917  const void *buf,
1918  apr_size_t nbytes,
1919  svn_io_file_del_t delete_when,
1920  apr_pool_t *pool);
1921 
1922 /** Wrapper for apr_file_trunc().
1923  * @since New in 1.6. */
1924 svn_error_t *
1925 svn_io_file_trunc(apr_file_t *file,
1926  apr_off_t offset,
1927  apr_pool_t *pool);
1928 
1929 
1930 /** Wrapper for apr_stat(). @a fname is utf8-encoded. */
1931 svn_error_t *
1932 svn_io_stat(apr_finfo_t *finfo,
1933  const char *fname,
1934  apr_int32_t wanted,
1935  apr_pool_t *pool);
1936 
1937 
1938 /** Rename and/or move the node (not necessarily a regular file) at
1939  * @a from_path to a new path @a to_path within the same filesystem.
1940  * In some cases, an existing node at @a to_path will be overwritten.
1941  *
1942  * A wrapper for apr_file_rename(). @a from_path and @a to_path are
1943  * utf8-encoded.
1944  */
1945 svn_error_t *
1946 svn_io_file_rename(const char *from_path,
1947  const char *to_path,
1948  apr_pool_t *pool);
1949 
1950 
1951 /** Move the file from @a from_path to @a to_path, even across device
1952  * boundaries. Overwrite @a to_path if it exists.
1953  *
1954  * @note This function is different from svn_io_file_rename in that the
1955  * latter fails in the 'across device boundaries' case.
1956  *
1957  * @since New in 1.3.
1958  */
1959 svn_error_t *
1960 svn_io_file_move(const char *from_path,
1961  const char *to_path,
1962  apr_pool_t *pool);
1963 
1964 
1965 /** Wrapper for apr_dir_make(). @a path is utf8-encoded. */
1966 svn_error_t *
1967 svn_io_dir_make(const char *path,
1968  apr_fileperms_t perm,
1969  apr_pool_t *pool);
1970 
1971 /** Same as svn_io_dir_make(), but sets the hidden attribute on the
1972  directory on systems that support it. */
1973 svn_error_t *
1974 svn_io_dir_make_hidden(const char *path,
1975  apr_fileperms_t perm,
1976  apr_pool_t *pool);
1977 
1978 /**
1979  * Same as svn_io_dir_make(), but attempts to set the sgid on the
1980  * directory on systems that support it. Does not return an error if
1981  * the attempt to set the sgid bit fails. On Unix filesystems,
1982  * setting the sgid bit on a directory ensures that files and
1983  * subdirectories created within inherit group ownership from the
1984  * parent instead of from the primary gid.
1985  *
1986  * @since New in 1.1.
1987  */
1988 svn_error_t *
1989 svn_io_dir_make_sgid(const char *path,
1990  apr_fileperms_t perm,
1991  apr_pool_t *pool);
1992 
1993 /** Wrapper for apr_dir_open(). @a dirname is utf8-encoded. */
1994 svn_error_t *
1995 svn_io_dir_open(apr_dir_t **new_dir,
1996  const char *dirname,
1997  apr_pool_t *pool);
1998 
1999 /** Wrapper for apr_dir_close().
2000  *
2001  * @since New in 1.7.
2002  */
2003 svn_error_t *
2004 svn_io_dir_close(apr_dir_t *thedir);
2005 
2006 /** Wrapper for apr_dir_remove(). @a dirname is utf8-encoded.
2007  * @note This function has this name to avoid confusion with
2008  * svn_io_remove_dir2(), which is recursive.
2009  */
2010 svn_error_t *
2011 svn_io_dir_remove_nonrecursive(const char *dirname,
2012  apr_pool_t *pool);
2013 
2014 
2015 /** Wrapper for apr_dir_read(). Ensures that @a finfo->name is
2016  * utf8-encoded, which means allocating @a finfo->name in @a pool,
2017  * which may or may not be the same as @a finfo's pool. Use @a pool
2018  * for error allocation as well.
2019  */
2020 svn_error_t *
2021 svn_io_dir_read(apr_finfo_t *finfo,
2022  apr_int32_t wanted,
2023  apr_dir_t *thedir,
2024  apr_pool_t *pool);
2025 
2026 /** Wrapper for apr_file_name_get(). @a *filename is utf8-encoded.
2027  *
2028  * @note The file name may be NULL.
2029  *
2030  * @since New in 1.7. */
2031 svn_error_t *
2032 svn_io_file_name_get(const char **filename,
2033  apr_file_t *file,
2034  apr_pool_t *pool);
2035 
2036 
2037 
2038 /** Version/format files.
2039  *
2040  * @defgroup svn_io_format_files Version/format files
2041  * @{
2042  */
2043 
2044 /** Set @a *version to the integer that starts the file at @a path. If the
2045  * file does not begin with a series of digits followed by a newline,
2046  * return the error #SVN_ERR_BAD_VERSION_FILE_FORMAT. Use @a pool for
2047  * all allocations.
2048  */
2049 svn_error_t *
2050 svn_io_read_version_file(int *version,
2051  const char *path,
2052  apr_pool_t *pool);
2053 
2054 /** Create (or overwrite) the file at @a path with new contents,
2055  * formatted as a non-negative integer @a version followed by a single
2056  * newline. On successful completion the file will be read-only. Use
2057  * @a pool for all allocations.
2058  */
2059 svn_error_t *
2060 svn_io_write_version_file(const char *path,
2061  int version,
2062  apr_pool_t *pool);
2063 
2064 /** @} */
2065 
2066 #ifdef __cplusplus
2067 }
2068 #endif /* __cplusplus */
2069 
2070 #endif /* SVN_IO_H */