~svn/ubuntu/raring/subversion/ppa

« back to all changes in this revision

Viewing changes to subversion/include/svn_io.h

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-12-05 01:26:14 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051205012614-qom4xfypgtsqc2xq
Tags: 1.2.3dfsg1-3ubuntu1
Merge with the final Debian release of 1.2.3dfsg1-3, bringing in
fixes to the clean target, better documentation of the libdb4.3
upgrade and build fixes to work with swig1.3_1.3.27.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * @copyright
 
3
 * ====================================================================
 
4
 * Copyright (c) 2000-2004 CollabNet.  All rights reserved.
 
5
 *
 
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.
 
11
 *
 
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
 * ====================================================================
 
16
 * @endcopyright
 
17
 *
 
18
 * @file svn_io.h
 
19
 * @brief General file I/O for Subversion
 
20
 */
 
21
 
 
22
/* ==================================================================== */
 
23
 
 
24
 
 
25
#ifndef SVN_IO_H
 
26
#define SVN_IO_H
 
27
 
 
28
#include <apr.h>
 
29
#include <apr_pools.h>
 
30
#include <apr_file_io.h>
 
31
#include <apr_thread_proc.h>
 
32
 
 
33
#include "svn_types.h"
 
34
#include "svn_error.h"
 
35
#include "svn_string.h"
 
36
 
 
37
#ifdef __cplusplus
 
38
extern "C" {
 
39
#endif /* __cplusplus */
 
40
 
 
41
 
 
42
 
 
43
/** Determine the @a kind of @a path.
 
44
 *
 
45
 * If utf8-encoded @a path exists, set @a *kind to the appropriate kind,
 
46
 * else set it to @c svn_node_unknown. 
 
47
 *
 
48
 * If @a path is a file, @a *kind is set to @c svn_node_file.
 
49
 *
 
50
 * If @a path is a directory, @a *kind is set to @c svn_node_dir.
 
51
 *
 
52
 * If @a path does not exist in its final component, @a *kind is set to
 
53
 * @c svn_node_none.  
 
54
 *
 
55
 * If intermediate directories on the way to @a path don't exist, an
 
56
 * error is returned, and @a *kind's value is undefined.
 
57
 */
 
58
svn_error_t *svn_io_check_path (const char *path,
 
59
                                svn_node_kind_t *kind,
 
60
                                apr_pool_t *pool);
 
61
 
 
62
/**
 
63
 * @since New in 1.1.
 
64
 *
 
65
 * Like svn_io_check_path(), but also set *is_special to @c TRUE if
 
66
 * the path is not a normal file.
 
67
 */
 
68
svn_error_t *svn_io_check_special_path (const char *path,
 
69
                                        svn_node_kind_t *kind,
 
70
                                        svn_boolean_t *is_special,
 
71
                                        apr_pool_t *pool);
 
72
 
 
73
/** Like svn_io_check_path(), but resolve symlinks.  This returns the
 
74
    same varieties of @a kind as svn_io_check_path(). */ 
 
75
svn_error_t *svn_io_check_resolved_path (const char *path,
 
76
                                         svn_node_kind_t *kind,
 
77
                                         apr_pool_t *pool);
 
78
 
 
79
 
 
80
/** Open a new file (for writing) with a unique name based on utf-8
 
81
 * encoded @a path, in the same directory as @a path.  The file handle is
 
82
 * returned in @a *f, and the name, which ends with @a suffix, is returned
 
83
 * in @a *unique_name_p, also utf8-encoded.  If @a delete_on_close is set,
 
84
 * then the @c APR_DELONCLOSE flag will be used when opening the file. The
 
85
 * @c APR_BUFFERED flag will always be used.
 
86
 *
 
87
 * The first attempt will just append @a suffix.  If the result is not
 
88
 * a unique name, then subsequent attempts will append a dot,
 
89
 * followed by an iteration number ("2", then "3", and so on),
 
90
 * followed by the suffix.  For example, if @a path is
 
91
 *
 
92
 *    tests/t1/A/D/G/pi
 
93
 *
 
94
 * then successive calls to
 
95
 *
 
96
 *    @c svn_io_open_unique_file(&f, &unique_name, @a path, ".tmp", pool) 
 
97
 *
 
98
 * will open
 
99
 *
 
100
 *    tests/t1/A/D/G/pi.tmp
 
101
 *    tests/t1/A/D/G/pi.2.tmp
 
102
 *    tests/t1/A/D/G/pi.3.tmp
 
103
 *    tests/t1/A/D/G/pi.4.tmp
 
104
 *    tests/t1/A/D/G/pi.5.tmp
 
105
 *    ...
 
106
 *
 
107
 * @a *unique_name_p will never be exactly the same as @a path, even
 
108
 * if @a path does not exist.
 
109
 * 
 
110
 * It doesn't matter if @a path is a file or directory, the unique name will
 
111
 * be in @a path's parent either way.
 
112
 *
 
113
 * Allocate @a *f and @a *unique_name_p in @a pool.
 
114
 *
 
115
 * If no unique name can be found, @c SVN_ERR_IO_UNIQUE_NAMES_EXHAUSTED is
 
116
 * the error returned.
 
117
 *
 
118
 * Claim of Historical Inevitability: this function was written
 
119
 * because 
 
120
 *
 
121
 *    - @c tmpnam() is not thread-safe.
 
122
 *    - @c tempname() tries standard system tmp areas first.
 
123
 */
 
124
svn_error_t *svn_io_open_unique_file (apr_file_t **f,
 
125
                                      const char **unique_name_p,
 
126
                                      const char *path,
 
127
                                      const char *suffix,
 
128
                                      svn_boolean_t delete_on_close,
 
129
                                      apr_pool_t *pool);
 
130
 
 
131
/**
 
132
 * @since New in 1.1.
 
133
 *
 
134
 * Like svn_io_open_unique_file, except that instead of creating a
 
135
 * file, a symlink is generated that references the path @a dest.
 
136
 */
 
137
svn_error_t *svn_io_create_unique_link (const char **unique_name_p,
 
138
                                        const char *path,
 
139
                                        const char *dest,
 
140
                                        const char *suffix,
 
141
                                        apr_pool_t *pool);
 
142
 
 
143
 
 
144
/**
 
145
 * @since New in 1.1.
 
146
 *
 
147
 * Set @a *dest to the path that the symlink at @a path references.
 
148
 * Allocate the string from @a pool.
 
149
 */
 
150
svn_error_t *svn_io_read_link (svn_string_t **dest,
 
151
                               const char *path,
 
152
                               apr_pool_t *pool);
 
153
 
 
154
 
 
155
/** Set @a *dir to a directory path (allocated in @a pool) deemed
 
156
 * usable for the creation of temporary files and subdirectories.
 
157
 */
 
158
svn_error_t *svn_io_temp_dir (const char **dir,
 
159
                              apr_pool_t *pool);
 
160
 
 
161
 
 
162
/** Copy @a src to @a dst atomically.  Overwrite @a dst if it exists, else
 
163
 * create it.  Both @a src and @a dst are utf8-encoded filenames.  If
 
164
 * @a copy_perms is true, set @a dst's permissions to match those of @a src.
 
165
 */
 
166
svn_error_t *svn_io_copy_file (const char *src,
 
167
                               const char *dst,
 
168
                               svn_boolean_t copy_perms,
 
169
                               apr_pool_t *pool);
 
170
 
 
171
/** 
 
172
 * @since New in 1.1.
 
173
 *
 
174
 * Copy symbolic link @a src to @a dst atomically.  Overwrite @a dst
 
175
 * if it exists, else create it.  Both @a src and @a dst are
 
176
 * utf8-encoded filenames.  After copying, the @a dst link will point
 
177
 * to the same thing @a src does.
 
178
 */
 
179
svn_error_t *svn_io_copy_link (const char *src,
 
180
                               const char *dst,
 
181
                               apr_pool_t *pool);
 
182
 
 
183
 
 
184
/** Recursively copy directory @a src into @a dst_parent, as a new entry named
 
185
 * @a dst_basename.  If @a dst_basename already exists in @a dst_parent, 
 
186
 * return error.  @a copy_perms will be passed through to @c svn_io_copy_file 
 
187
 * when any files are copied.  @a src, @a dst_parent, and @a dst_basename are 
 
188
 * all utf8-encoded.
 
189
 *
 
190
 * If @a cancel_func is non-null, invoke it with @a cancel_baton at
 
191
 * various points during the operation.  If it returns any error
 
192
 * (typically @c SVN_ERR_CANCELLED), return that error immediately.
 
193
 */ 
 
194
svn_error_t *svn_io_copy_dir_recursively (const char *src,
 
195
                                          const char *dst_parent,
 
196
                                          const char *dst_basename,
 
197
                                          svn_boolean_t copy_perms,
 
198
                                          svn_cancel_func_t cancel_func,
 
199
                                          void *cancel_baton,
 
200
                                          apr_pool_t *pool);
 
201
 
 
202
 
 
203
 
 
204
/** Create directory @a path on the file system, creating intermediate
 
205
 * directories as required, like <tt>mkdir -p</tt>.  Report no error if @a 
 
206
 * path already exists.  @a path is utf8-encoded.
 
207
 *
 
208
 * This is essentially a wrapper for @c apr_dir_make_recursive(), passing
 
209
 * @c APR_OS_DEFAULT as the permissions.
 
210
 */
 
211
svn_error_t *svn_io_make_dir_recursively (const char *path, apr_pool_t *pool);
 
212
 
 
213
 
 
214
/** Set @a *is_empty_p to @c TRUE if directory @a path is empty, else to 
 
215
 * @c FALSE if it is not empty.  @a path must be a directory, and is
 
216
 * utf8-encoded.  Use @a pool for temporary allocation.
 
217
 */
 
218
svn_error_t *
 
219
svn_io_dir_empty (svn_boolean_t *is_empty_p,
 
220
                  const char *path,
 
221
                  apr_pool_t *pool);
 
222
 
 
223
 
 
224
/** Append @a src to @a dst.  @a dst will be appended to if it exists, else it
 
225
 * will be created.  Both @a src and @a dst are utf8-encoded.
 
226
 */
 
227
svn_error_t *svn_io_append_file (const char *src,
 
228
                                 const char *dst,
 
229
                                 apr_pool_t *pool);
 
230
 
 
231
 
 
232
/** Make a file as read-only as the operating system allows.
 
233
 * @a path is the utf8-encoded path to the file. If @a ignore_enoent is
 
234
 * @c TRUE, don't fail if the target file doesn't exist.
 
235
 */
 
236
svn_error_t *svn_io_set_file_read_only (const char *path,
 
237
                                        svn_boolean_t ignore_enoent,
 
238
                                        apr_pool_t *pool);
 
239
 
 
240
 
 
241
/** Make a file as writable as the operating system allows.
 
242
 * @a path is the utf8-encoded path to the file.  If @a ignore_enoent is
 
243
 * @c TRUE, don't fail if the target file doesn't exist.
 
244
 * @warning On Unix this function will do the equivalent of chmod a+w path.
 
245
 * If this is not what you want you should not use this function, but rather
 
246
 * use apr_file_perms_set().
 
247
 */
 
248
svn_error_t *svn_io_set_file_read_write (const char *path,
 
249
                                         svn_boolean_t ignore_enoent,
 
250
                                         apr_pool_t *pool);
 
251
 
 
252
 
 
253
/** Minimally change the read-write permissions of a file.
 
254
 * @since New in 1.1.
 
255
 *
 
256
 * When making @a path read-write on operating systems with unix style
 
257
 * permissions, set the permissions on @a path to the permissions that
 
258
 * are set when a new file is created (effectively honoring the user's
 
259
 * umask).
 
260
 *
 
261
 * When making the file read-only on operating systems with unix style
 
262
 * permissions, remove all write permissions.
 
263
 *
 
264
 * On other operating systems, toggle the file's "writability" as much as
 
265
 * the operating system allows.
 
266
 *
 
267
 * @a path is the utf8-encoded path to the file.  If @a enable_write
 
268
 * is @c TRUE, then make the file read-write.  If @c FALSE, make it
 
269
 * write-only.  If @a ignore_enoent is @c TRUE, don't fail if the target
 
270
 * file doesn't exist.
 
271
 */
 
272
svn_error_t *svn_io_set_file_read_write_carefully (const char *path,
 
273
                                                   svn_boolean_t enable_write,
 
274
                                                   svn_boolean_t ignore_enoent,
 
275
                                                   apr_pool_t *pool);
 
276
    
 
277
/** Toggle a file's "executability".
 
278
 *
 
279
 * When making the file executable on operating systems with unix style
 
280
 * permissions, never add an execute permission where there is not
 
281
 * already a read permission: that is, only make the file executable
 
282
 * for the user, group or world if the corresponding read permission
 
283
 * is already set for user, group or world.
 
284
 *
 
285
 * When making the file non-executable on operating systems with unix style
 
286
 * permissions, remove all execute permissions.
 
287
 *
 
288
 * On other operating systems, toggle the file's "executability" as much as
 
289
 * the operating system allows.
 
290
 *
 
291
 * @a path is the utf8-encoded path to the file.  If @a executable
 
292
 * is @c TRUE, then make the file executable.  If @c FALSE, make in
 
293
 * non-executable.  If @a ignore_enoent is @c TRUE, don't fail if the target
 
294
 * file doesn't exist.
 
295
 */
 
296
svn_error_t *svn_io_set_file_executable (const char *path,
 
297
                                         svn_boolean_t executable,
 
298
                                         svn_boolean_t ignore_enoent,
 
299
                                         apr_pool_t *pool);
 
300
 
 
301
/** Determine whether a file is executable by the current user.  
 
302
 * Set @a *executable to @c TRUE if the file @a path is executable by the 
 
303
 * current user, otherwise set it to @c FALSE.  
 
304
 * 
 
305
 * On Windows and on platforms without userids, always returns @c FALSE.
 
306
 */
 
307
svn_error_t *svn_io_is_file_executable(svn_boolean_t *executable, 
 
308
                                       const char *path, 
 
309
                                       apr_pool_t *pool);
 
310
 
 
311
 
 
312
/** Read a line from @a file into @a buf, but not exceeding @a *limit bytes.
 
313
 * Does not include newline, instead '\\0' is put there.
 
314
 * Length (as in strlen) is returned in @a *limit.
 
315
 * @a buf should be pre-allocated.
 
316
 * @a file should be already opened. 
 
317
 *
 
318
 * When the file is out of lines, @c APR_EOF will be returned.
 
319
 */
 
320
svn_error_t *
 
321
svn_io_read_length_line (apr_file_t *file, char *buf, apr_size_t *limit,
 
322
                         apr_pool_t *pool);
 
323
 
 
324
 
 
325
/** Set @a *apr_time to the time of last modification of the contents of the
 
326
 * file @a path.  @a path is utf8-encoded.
 
327
 *
 
328
 * Note: this is the APR mtime which corresponds to the traditional mtime
 
329
 * on Unix, and the last write time on Windows.
 
330
 */
 
331
svn_error_t *svn_io_file_affected_time (apr_time_t *apr_time,
 
332
                                        const char *path,
 
333
                                        apr_pool_t *pool);
 
334
 
 
335
/** Set the timestamp of file @a path to @a apr_time.  @a path is
 
336
 *  utf8-encoded.
 
337
 *
 
338
 * Note: this is the APR mtime which corresponds to the traditional mtime
 
339
 * on Unix, and the last write time on Windows.
 
340
 */
 
341
svn_error_t *svn_io_set_file_affected_time (apr_time_t apr_time,
 
342
                                            const char *path,
 
343
                                            apr_pool_t *pool);
 
344
 
 
345
 
 
346
 
 
347
/** Set @a *different_p to non-zero if @a file1 and @a file2 have different
 
348
 * sizes, else set to zero.  Both @a file1 and @a file2 are utf8-encoded.
 
349
 *
 
350
 * Setting @a *different_p to zero does not mean the files definitely
 
351
 * have the same size, it merely means that the sizes are not
 
352
 * definitely different.  That is, if the size of one or both files
 
353
 * cannot be determined, then the sizes are not known to be different,
 
354
 * so @a *different_p is set to 0.
 
355
 */
 
356
svn_error_t *svn_io_filesizes_different_p (svn_boolean_t *different_p,
 
357
                                           const char *file1,
 
358
                                           const char *file2,
 
359
                                           apr_pool_t *pool);
 
360
 
 
361
 
 
362
/** Put the md5 checksum of @a file into @a digest.
 
363
 * @a digest points to @c APR_MD5_DIGESTSIZE bytes of storage.
 
364
 * Use @a pool only for temporary allocations.
 
365
 */
 
366
svn_error_t *svn_io_file_checksum (unsigned char digest[],
 
367
                                   const char *file,
 
368
                                   apr_pool_t *pool);
 
369
 
 
370
 
 
371
/** Set @a *same to non-zero if @a file1 and @a file2 have the same
 
372
 * contents, else set it to zero.  Use @a pool for temporary allocations.
 
373
 */
 
374
svn_error_t *svn_io_files_contents_same_p (svn_boolean_t *same,
 
375
                                           const char *file1,
 
376
                                           const char *file2,
 
377
                                           apr_pool_t *pool);
 
378
 
 
379
/** Create file at @a file with contents @a contents.
 
380
 * will be created.  Path @a file is utf8-encoded.
 
381
 * Use @a pool for memory allocations.
 
382
 */
 
383
svn_error_t *svn_io_file_create (const char *file,
 
384
                                 const char *contents,
 
385
                                 apr_pool_t *pool);
 
386
 
 
387
/**
 
388
 * @deprecated Provided for backward compatibility with the 1.0 API.
 
389
 *
 
390
 * Lock file at @a lock_file. If @a exclusive is TRUE,
 
391
 * obtain exclusive lock, otherwise obtain shared lock.
 
392
 * Lock will be automatically released when @a pool is cleared or destroyed.
 
393
 * Use @a pool for memory allocations.
 
394
 */
 
395
svn_error_t *svn_io_file_lock (const char *lock_file,
 
396
                               svn_boolean_t exclusive,
 
397
                               apr_pool_t *pool);
 
398
 
 
399
/**
 
400
 * @since New in 1.1.
 
401
 *
 
402
 * Lock file at @a lock_file. If @a exclusive is TRUE,
 
403
 * obtain exclusive lock, otherwise obtain shared lock.
 
404
 *
 
405
 * If @a nonblocking is TRUE, do not wait for the lock if it
 
406
 * is not available: throw an error instead.
 
407
 *
 
408
 * Lock will be automatically released when @a pool is cleared or destroyed.
 
409
 * Use @a pool for memory allocations.
 
410
 */
 
411
svn_error_t *svn_io_file_lock2 (const char *lock_file,
 
412
                                svn_boolean_t exclusive,
 
413
                                svn_boolean_t nonblocking,
 
414
                                apr_pool_t *pool);
 
415
/**
 
416
 * @since New in 1.1.
 
417
 *
 
418
 * Flush any unwritten data from @a file to disk.  Use @a pool for
 
419
 *  memory allocations.
 
420
 */
 
421
svn_error_t *svn_io_file_flush_to_disk (apr_file_t *file,
 
422
                                        apr_pool_t *pool);
 
423
 
 
424
/** Copy file @a file from location @a src_path to location @a dest_path.
 
425
 * Use @a pool for memory allocations.
 
426
 */
 
427
svn_error_t *svn_io_dir_file_copy (const char *src_path, 
 
428
                                   const char *dest_path, 
 
429
                                   const char *file,
 
430
                                   apr_pool_t *pool);
 
431
 
 
432
 
 
433
/** Generic byte-streams
 
434
 *
 
435
 * @defgroup svn_io_byte_streams generic byte streams
 
436
 * @{
 
437
 */
 
438
 
 
439
/** An abstract stream of bytes--either incoming or outgoing or both.
 
440
 *
 
441
 * The creator of a stream sets functions to handle read and write.
 
442
 * Both of these handlers accept a baton whose value is determined at
 
443
 * stream creation time; this baton can point to a structure
 
444
 * containing data associated with the stream.  If a caller attempts
 
445
 * to invoke a handler which has not been set, it will generate a
 
446
 * runtime assertion failure.  The creator can also set a handler for
 
447
 * close requests so that it can flush buffered data or whatever;
 
448
 * if a close handler is not specified, a close request on the stream
 
449
 * will simply be ignored.  Note that svn_stream_close() does not
 
450
 * deallocate the memory used to allocate the stream structure; free
 
451
 * the pool you created the stream in to free that memory.
 
452
 *
 
453
 * The read and write handlers accept length arguments via pointer.
 
454
 * On entry to the handler, the pointed-to value should be the amount
 
455
 * of data which can be read or the amount of data to write.  When the
 
456
 * handler returns, the value is reset to the amount of data actually
 
457
 * read or written.  Handlers are obliged to complete a read or write
 
458
 * to the maximum extent possible; thus, a short read with no
 
459
 * associated error implies the end of the input stream, and a short
 
460
 * write should never occur without an associated error.
 
461
 */
 
462
typedef struct svn_stream_t svn_stream_t;
 
463
 
 
464
 
 
465
 
 
466
/** Read handler function for a generic stream.  */
 
467
typedef svn_error_t *(*svn_read_fn_t) (void *baton,
 
468
                                       char *buffer,
 
469
                                       apr_size_t *len);
 
470
 
 
471
/** Write handler function for a generic stream.  */
 
472
typedef svn_error_t *(*svn_write_fn_t) (void *baton,
 
473
                                        const char *data,
 
474
                                        apr_size_t *len);
 
475
 
 
476
/** Close handler function for a generic stream.  */
 
477
typedef svn_error_t *(*svn_close_fn_t) (void *baton);
 
478
 
 
479
 
 
480
/** Creating a generic stream.  */
 
481
svn_stream_t *svn_stream_create (void *baton, apr_pool_t *pool);
 
482
 
 
483
/** Set @a stream's baton to @a baton */
 
484
void svn_stream_set_baton (svn_stream_t *stream, void *baton);
 
485
 
 
486
/** Set @a stream's read function to @a read_fn */
 
487
void svn_stream_set_read (svn_stream_t *stream, svn_read_fn_t read_fn);
 
488
 
 
489
/** Set @a stream's write function to @a write_fn */
 
490
void svn_stream_set_write (svn_stream_t *stream, svn_write_fn_t write_fn);
 
491
 
 
492
/** Set @a stream's close function to @a close_fn */
 
493
void svn_stream_set_close (svn_stream_t *stream, svn_close_fn_t close_fn);
 
494
 
 
495
 
 
496
/** Convenience function to create a generic stream which is empty.  */
 
497
svn_stream_t *svn_stream_empty (apr_pool_t *pool);
 
498
 
 
499
 
 
500
/** Convenience function for creating streams which operate on APR
 
501
 * files.  For convenience, if @a file is NULL then @c svn_stream_empty(pool) 
 
502
 * is returned.  Note that the stream returned by these operations is not 
 
503
 * considered to "own" the underlying file, meaning that @c svn_stream_close() 
 
504
 * on the stream will not close the file.
 
505
 */
 
506
svn_stream_t *svn_stream_from_aprfile (apr_file_t *file, apr_pool_t *pool);
 
507
 
 
508
/** Set @a *out to a generic stream connected to stdout, allocated in 
 
509
 * @a pool.  The stream and its underlying APR handle will be closed
 
510
 * when @a pool is cleared or destroyed.
 
511
 */
 
512
svn_error_t *svn_stream_for_stdout (svn_stream_t **out, apr_pool_t *pool);
 
513
 
 
514
/** Return a generic stream connected to stringbuf @a str.  Allocate the
 
515
 * stream in @a pool.
 
516
 */
 
517
svn_stream_t *svn_stream_from_stringbuf (svn_stringbuf_t *str,
 
518
                                         apr_pool_t *pool);
 
519
 
 
520
/** Return a stream that decompresses all data read and compresses all
 
521
 * data written. The stream @a stream is used to read and write all
 
522
 * compressed data. All compression data structures are allocated on
 
523
 * @a pool. If compression support is not compiled in then @c
 
524
 * svn_stream_compressed() returns @a stream unmodified. Make sure you
 
525
 * call @c svn_stream_close() on the stream returned by this function,
 
526
 * so that all data are flushed and cleaned up.
 
527
 */
 
528
svn_stream_t *svn_stream_compressed (svn_stream_t *stream, 
 
529
                                     apr_pool_t *pool);
 
530
 
 
531
/** Read from a generic stream. */
 
532
svn_error_t *svn_stream_read (svn_stream_t *stream, char *buffer,
 
533
                              apr_size_t *len);
 
534
 
 
535
/** Write to a generic stream. */
 
536
svn_error_t *svn_stream_write (svn_stream_t *stream, const char *data,
 
537
                               apr_size_t *len);
 
538
 
 
539
/** Close a generic stream. */
 
540
svn_error_t *svn_stream_close (svn_stream_t *stream);
 
541
 
 
542
 
 
543
/** Write to @a stream using a printf-style @a fmt specifier, passed through
 
544
 * @c apr_psprintf using memory from @a pool.
 
545
 */
 
546
svn_error_t *svn_stream_printf (svn_stream_t *stream,
 
547
                                apr_pool_t *pool,
 
548
                                const char *fmt,
 
549
                                ...)
 
550
       __attribute__ ((format(printf, 3, 4)));
 
551
 
 
552
/** Allocate @a *stringbuf in @a pool, and read into it one line (terminated
 
553
 * by @a eol) from @a stream. The line-terminator is read from the stream,
 
554
 * but is not added to the end of the stringbuf.  Instead, the stringbuf
 
555
 * ends with a usual '\\0'.
 
556
 *
 
557
 * If @a stream runs out of bytes before encountering a line-terminator,
 
558
 * then set @a *eof to @c TRUE, otherwise set @a *eof to FALSE.
 
559
 */
 
560
svn_error_t *
 
561
svn_stream_readline (svn_stream_t *stream,
 
562
                     svn_stringbuf_t **stringbuf,
 
563
                     const char *eol,
 
564
                     svn_boolean_t *eof,
 
565
                     apr_pool_t *pool);
 
566
 
 
567
/**
 
568
 * @since New in 1.1.
 
569
 *
 
570
 * Read the contents of the readable stream @a from and write them to the
 
571
 * writable stream @a to.
 
572
 */
 
573
svn_error_t *svn_stream_copy (svn_stream_t *from, svn_stream_t *to,
 
574
                              apr_pool_t *pool);
 
575
 
 
576
/** @} */
 
577
 
 
578
/** Sets @a *result to a string containing the contents of @a filename, a
 
579
 * utf8-encoded path. 
 
580
 *
 
581
 * If @a filename is "-", return the error @c SVN_ERR_UNSUPPORTED_FEATURE
 
582
 * and don't touch @a *result.
 
583
 *
 
584
 * ### Someday, "-" will fill @a *result from stdin.  The problem right
 
585
 * now is that if the same command invokes the editor, stdin is crap,
 
586
 * and the editor acts funny or dies outright.  One solution is to
 
587
 * disallow stdin reading and invoking the editor, but how to do that
 
588
 * reliably?
 
589
 */
 
590
svn_error_t *svn_stringbuf_from_file (svn_stringbuf_t **result, 
 
591
                                      const char *filename, 
 
592
                                      apr_pool_t *pool);
 
593
 
 
594
/** Sets @a *result to a string containing the contents of the already opened
 
595
 * @a file.  Reads from the current position in file to the end.  Does not
 
596
 * close the file or reset the cursor position.
 
597
 */
 
598
svn_error_t *svn_stringbuf_from_aprfile (svn_stringbuf_t **result,
 
599
                                         apr_file_t *file,
 
600
                                         apr_pool_t *pool);
 
601
 
 
602
/** Remove file @a path, a utf8-encoded path.  This wraps @c apr_file_remove(), 
 
603
 * converting any error to a Subversion error.
 
604
 */
 
605
svn_error_t *svn_io_remove_file (const char *path, apr_pool_t *pool);
 
606
 
 
607
/** Recursively remove directory @a path.  @a path is utf8-encoded. */
 
608
svn_error_t *svn_io_remove_dir (const char *path, apr_pool_t *pool);
 
609
 
 
610
 
 
611
/** Read all of the disk entries in directory @a path, a utf8-encoded
 
612
 * path.  Set @a *dirents to a hash mapping dirent names (<tt>char *</tt>) to
 
613
 * enumerated dirent filetypes (@c svn_node_kind_t *).
 
614
 *
 
615
 * Note:  the `.' and `..' directories normally returned by
 
616
 * @c apr_dir_read are NOT returned in the hash.
 
617
 */
 
618
svn_error_t *svn_io_get_dirents (apr_hash_t **dirents,
 
619
                                 const char *path,
 
620
                                 apr_pool_t *pool);
 
621
 
 
622
 
 
623
/** Callback function type for @c svn_io_dir_walk  */
 
624
typedef svn_error_t * (*svn_io_walk_func_t) (void *baton,
 
625
                                             const char *path,
 
626
                                             const apr_finfo_t *finfo,
 
627
                                             apr_pool_t *pool);
 
628
 
 
629
/** This function will recursively walk over the files and directories
 
630
 * rooted at @a dirname, a utf8-encoded path. For each file or directory,
 
631
 * @a walk_func is invoked, passing in the @a walk_baton, the utf8-encoded
 
632
 * full path to the entry, an @c apr_finfo_t structure, and a temporary
 
633
 * pool for allocations.  For any directory, @a walk_func will be invoked
 
634
 * on the directory itself before being invoked on any subdirectories or
 
635
 * files within the directory.
 
636
 *
 
637
 * The set of information passed to @a walk_func is specified by @a wanted,
 
638
 * and the items specified by @c APR_FINFO_TYPE and @c APR_FINFO_NAME.
 
639
 *
 
640
 * All allocations will be performed in @a pool.
 
641
 */
 
642
svn_error_t *svn_io_dir_walk (const char *dirname,
 
643
                              apr_int32_t wanted,
 
644
                              svn_io_walk_func_t walk_func,
 
645
                              void *walk_baton,
 
646
                              apr_pool_t *pool);
 
647
 
 
648
/** Invoke @a cmd with @a args, using utf8-encoded @a path as working 
 
649
 * directory.  Connect @a cmd's stdin, stdout, and stderr to @a infile, 
 
650
 * @a outfile, and @a errfile, except where they are null.
 
651
 *
 
652
 * If set, @a exitcode will contain the exit code of the process upon return,
 
653
 * and @a exitwhy will indicate why the process terminated. If @a exitwhy is 
 
654
 * not set and the exit reason is not @c APR_PROC_CHECK_EXIT(), or if 
 
655
 * @a exitcode is not set and the exit code is non-zero, then an 
 
656
 * @c SVN_ERR_EXTERNAL_PROGRAM error will be returned.
 
657
 *
 
658
 * @a args is a list of utf8-encoded <tt>const char *</tt> arguments,
 
659
 * terminated by @c NULL.  @a args[0] is the name of the program, though it
 
660
 * need not be the same as @a cmd.
 
661
 *
 
662
 * @a inherit sets whether the invoked program shall inherit its environment or
 
663
 * run "clean".
 
664
 */
 
665
svn_error_t *svn_io_run_cmd (const char *path,
 
666
                             const char *cmd,
 
667
                             const char *const *args,
 
668
                             int *exitcode,
 
669
                             apr_exit_why_e *exitwhy,
 
670
                             svn_boolean_t inherit,
 
671
                             apr_file_t *infile,
 
672
                             apr_file_t *outfile,
 
673
                             apr_file_t *errfile,
 
674
                             apr_pool_t *pool);
 
675
 
 
676
/** Invoke @c the configured diff program, with @a user_args (an array
 
677
 * of utf8-encoded @a num_user_args arguments), if they are specified,
 
678
 * or "-u" if they are not.
 
679
 *
 
680
 * Diff runs in utf8-encoded @a dir, and its exit status is stored in
 
681
 * @a exitcode, if it is not @c NULL.  
 
682
 *
 
683
 * If @a label1 and/or @a label2 are not null they will be passed to the diff
 
684
 * process as the arguments of "-L" options.  @a label1 and @a label2 are also 
 
685
 * in utf8, and will be converted to native charset along with the other args.
 
686
 *
 
687
 * @a from is the first file passed to diff, and @a to is the second.  The
 
688
 * stdout of diff will be sent to @a outfile, and the stderr to @a errfile.
 
689
 *
 
690
 * @a diff_cmd must be non-null.
 
691
 *
 
692
 * Do all allocation in @a pool. 
 
693
 */
 
694
svn_error_t *svn_io_run_diff (const char *dir,
 
695
                              const char *const *user_args,
 
696
                              int num_user_args,
 
697
                              const char *label1,
 
698
                              const char *label2,
 
699
                              const char *from,
 
700
                              const char *to,
 
701
                              int *exitcode,
 
702
                              apr_file_t *outfile,
 
703
                              apr_file_t *errfile,
 
704
                              const char *diff_cmd,
 
705
                              apr_pool_t *pool);
 
706
 
 
707
 
 
708
/** Invoke @c the configured diff3 program, in utf8-encoded @a dir
 
709
 * like this:
 
710
 *
 
711
 *          diff3 -Em @a mine @a older @a yours > @a merged
 
712
 *
 
713
 * (See the diff3 documentation for details.)
 
714
 *
 
715
 * @a mine, @a older, and @a yours are utf8-encoded paths, relative to @a dir, 
 
716
 * to three files that already exist.  @a merged is an open file handle, and
 
717
 * is left open after the merge result is written to it. (@a merged
 
718
 * should *not* be the same file as @a mine, or nondeterministic things
 
719
 * may happen!)
 
720
 *
 
721
 * @a mine_label, @a older_label, @a yours_label are utf8-encoded label
 
722
 * parameters for diff3's -L option.  Any of them may be @c NULL, in
 
723
 * which case the corresponding @a mine, @a older, or @a yours parameter is
 
724
 * used instead.
 
725
 *
 
726
 * Set @a *exitcode to diff3's exit status.  If @a *exitcode is anything
 
727
 * other than 0 or 1, then return @c SVN_ERR_EXTERNAL_PROGRAM.  (Note the
 
728
 * following from the diff3 info pages: "An exit status of 0 means
 
729
 * `diff3' was successful, 1 means some conflicts were found, and 2
 
730
 * means trouble.") 
 
731
 *
 
732
 * @a diff3_cmd must be non-null.
 
733
 *
 
734
 * Do all allocation in @a pool. 
 
735
 */
 
736
svn_error_t *svn_io_run_diff3 (const char *dir,
 
737
                               const char *mine,
 
738
                               const char *older,
 
739
                               const char *yours,
 
740
                               const char *mine_label,
 
741
                               const char *older_label,
 
742
                               const char *yours_label,
 
743
                               apr_file_t *merged,
 
744
                               int *exitcode,
 
745
                               const char *diff3_cmd,
 
746
                               apr_pool_t *pool);
 
747
 
 
748
 
 
749
/** Examine utf8-encoded @a file to determine if it can be described by a
 
750
 * known (as in, known by this function) Multipurpose Internet Mail
 
751
 * Extension (MIME) type.  If so, set @a *mimetype to a character string
 
752
 * describing the MIME type, else set it to @c NULL.  Use @a pool for any
 
753
 * necessary allocations.
 
754
 */
 
755
svn_error_t *svn_io_detect_mimetype (const char **mimetype,
 
756
                                     const char *file,
 
757
                                     apr_pool_t *pool);
 
758
                                      
 
759
 
 
760
/** Wrapper for @c apr_file_open(), which see.  @a fname is utf8-encoded. */
 
761
svn_error_t *
 
762
svn_io_file_open (apr_file_t **new_file, const char *fname,
 
763
                  apr_int32_t flag, apr_fileperms_t perm,
 
764
                  apr_pool_t *pool);
 
765
 
 
766
 
 
767
/** Wrapper for @c apr_file_close(), which see. */
 
768
svn_error_t *
 
769
svn_io_file_close (apr_file_t *file, apr_pool_t *pool);
 
770
 
 
771
 
 
772
/** Wrapper for @c apr_file_getc(), which see. */
 
773
svn_error_t *
 
774
svn_io_file_getc (char *ch, apr_file_t *file, apr_pool_t *pool);
 
775
 
 
776
 
 
777
/** Wrapper for @c apr_file_info_get(), which see. */
 
778
svn_error_t *
 
779
svn_io_file_info_get (apr_finfo_t *finfo, apr_int32_t wanted, 
 
780
                      apr_file_t *file, apr_pool_t *pool);
 
781
 
 
782
 
 
783
/** Wrapper for @c apr_file_read(), which see. */
 
784
svn_error_t *
 
785
svn_io_file_read (apr_file_t *file, void *buf, 
 
786
                  apr_size_t *nbytes, apr_pool_t *pool);
 
787
 
 
788
 
 
789
/** Wrapper for @c apr_file_read_full(), which see. */
 
790
svn_error_t *
 
791
svn_io_file_read_full (apr_file_t *file, void *buf, 
 
792
                       apr_size_t nbytes, apr_size_t *bytes_read,
 
793
                       apr_pool_t *pool);
 
794
 
 
795
 
 
796
/** Wrapper for @c apr_file_seek(), which see. */
 
797
svn_error_t *
 
798
svn_io_file_seek (apr_file_t *file, apr_seek_where_t where, 
 
799
                  apr_off_t *offset, apr_pool_t *pool);
 
800
 
 
801
 
 
802
/** Wrapper for @c apr_file_write(), which see. */
 
803
svn_error_t *
 
804
svn_io_file_write (apr_file_t *file, const void *buf, 
 
805
                   apr_size_t *nbytes, apr_pool_t *pool);
 
806
 
 
807
 
 
808
/** Wrapper for @c apr_file_write_full(), which see. */
 
809
svn_error_t *
 
810
svn_io_file_write_full (apr_file_t *file, const void *buf, 
 
811
                        apr_size_t nbytes, apr_size_t *bytes_written,
 
812
                        apr_pool_t *pool);
 
813
 
 
814
 
 
815
/** Wrapper for @c apr_stat(), which see.  @a fname is utf8-encoded. */
 
816
svn_error_t *
 
817
svn_io_stat (apr_finfo_t *finfo, const char *fname,
 
818
             apr_int32_t wanted, apr_pool_t *pool);
 
819
 
 
820
 
 
821
/** Wrapper for @c apr_file_rename(), which see.  @a from_path and @a to_path
 
822
 * are utf8-encoded.
 
823
 */
 
824
svn_error_t *
 
825
svn_io_file_rename (const char *from_path, const char *to_path,
 
826
                    apr_pool_t *pool);
 
827
 
 
828
 
 
829
/** Wrapper for @c apr_dir_make(), which see.  @a path is utf8-encoded. */
 
830
svn_error_t *
 
831
svn_io_dir_make (const char *path, apr_fileperms_t perm, apr_pool_t *pool);
 
832
 
 
833
/** Same as svn_io_dir_make, but sets the hidden attribute on the
 
834
    directory on systems that support it. */
 
835
svn_error_t *
 
836
svn_io_dir_make_hidden (const char *path, apr_fileperms_t perm,
 
837
                        apr_pool_t *pool);
 
838
 
 
839
/**
 
840
 * @since New in 1.1.
 
841
 *
 
842
 * Same as svn_io_dir_make, but attempts to set the sgid on the
 
843
 * directory on systems that support it.  Does not return an error if
 
844
 * the attempt to set the sgid bit fails.  On Unix filesystems,
 
845
 * setting the sgid bit on a directory ensures that files and
 
846
 * subdirectories created within inherit group ownership from the
 
847
 * parent instead of from the primary gid. */
 
848
svn_error_t *
 
849
svn_io_dir_make_sgid (const char *path, apr_fileperms_t perm,
 
850
                      apr_pool_t *pool);
 
851
 
 
852
/** Wrapper for @c apr_dir_open(), which see.  @a dirname is utf8-encoded. */
 
853
svn_error_t *
 
854
svn_io_dir_open (apr_dir_t **new_dir, const char *dirname, apr_pool_t *pool);
 
855
 
 
856
 
 
857
/** Wrapper for @c apr_dir_remove(), which see.  @a dirname is utf8-encoded.
 
858
 * Note: this function has this name to avoid confusion with
 
859
 * @c svn_io_remove_dir, which is recursive.
 
860
 */
 
861
svn_error_t *
 
862
svn_io_dir_remove_nonrecursive (const char *dirname, apr_pool_t *pool);
 
863
 
 
864
 
 
865
/** Wrapper for @c apr_dir_read, which see.  Ensures that @a finfo->name is
 
866
 * utf8-encoded, which means allocating @a finfo->name in @a pool, which may
 
867
 * or may not be the same as @a finfo's pool.  Use @a pool for error allocation
 
868
 * as well.
 
869
 */
 
870
svn_error_t *
 
871
svn_io_dir_read (apr_finfo_t *finfo,
 
872
                 apr_int32_t wanted,
 
873
                 apr_dir_t *thedir,
 
874
                 apr_pool_t *pool);
 
875
 
 
876
 
 
877
 
 
878
/** Version/format files. 
 
879
 *
 
880
 * @defgroup svn_io_format_files version/format files
 
881
 * @{
 
882
 */
 
883
 
 
884
/** Set @a *version to the integer that starts the file at @a path.  If the
 
885
 * file does not begin with a series of digits followed by a newline,
 
886
 * return the error @c SVN_ERR_BAD_VERSION_FILE_FORMAT.  Use @a pool for
 
887
 * all allocations.
 
888
 */
 
889
svn_error_t *
 
890
svn_io_read_version_file (int *version, const char *path, apr_pool_t *pool);
 
891
 
 
892
/** Create (or overwrite) the file at @a path with new contents,
 
893
 * formatted as a non-negative integer @a version followed by a single
 
894
 * newline.  On successful completion the file will be read-only.  Use
 
895
 * @a pool for all allocations.
 
896
 */
 
897
svn_error_t *
 
898
svn_io_write_version_file (const char *path, int version, apr_pool_t *pool);
 
899
 
 
900
/** @} */
 
901
 
 
902
#ifdef __cplusplus
 
903
}
 
904
#endif /* __cplusplus */
 
905
 
 
906
#endif /* SVN_IO_H */