4040 */
4141
4242#include <sys/types.h>
43- __FBSDID ("$FreeBSD$" );
44-
4543#include <sys/stat.h>
4644
4745#include <archive.h>
@@ -52,10 +50,6 @@ __FBSDID("$FreeBSD$");
5250#include <string.h>
5351#include <unistd.h>
5452
55- #ifndef NO_CREATE
56- #include "tree.h"
57- #endif
58-
5953/*
6054 * NO_CREATE implies NO_BZIP2_CREATE and NO_GZIP_CREATE and NO_COMPRESS_CREATE.
6155 */
@@ -264,28 +258,71 @@ create(const char *filename, int compress, const char **argv)
264258 archive_read_disk_set_standard_lookup (disk );
265259#endif
266260 while (* argv != NULL ) {
267- struct tree * t = tree_open (* argv );
268- while (tree_next (t )) {
261+ struct archive * disk = archive_read_disk_new ();
262+ int r ;
263+
264+ r = archive_read_disk_open (disk , * argv );
265+ if (r != ARCHIVE_OK ) {
266+ errmsg (archive_error_string (disk ));
267+ errmsg ("\n" );
268+ exit (1 );
269+ }
270+
271+ for (;;) {
272+ int needcr = 0 ;
273+
269274 entry = archive_entry_new ();
270- archive_entry_set_pathname (entry , tree_current_path (t ));
271- archive_read_disk_entry_from_file (disk , entry , -1 ,
272- tree_current_stat (t ));
275+ r = archive_read_next_header2 (disk , entry );
276+ if (r == ARCHIVE_EOF )
277+ break ;
278+ if (r != ARCHIVE_OK ) {
279+ errmsg (archive_error_string (disk ));
280+ errmsg ("\n" );
281+ exit (1 );
282+ }
283+ archive_read_disk_descend (disk );
273284 if (verbose ) {
274285 msg ("a " );
275- msg (tree_current_path (t ));
286+ msg (archive_entry_pathname (entry ));
287+ needcr = 1 ;
288+ }
289+ r = archive_write_header (a , entry );
290+ if (r < ARCHIVE_OK ) {
291+ errmsg (": " );
292+ errmsg (archive_error_string (a ));
293+ needcr = 1 ;
276294 }
277- archive_write_header (a , entry );
278- fd = open (tree_current_access_path (t ), O_RDONLY );
279- len = read (fd , buff , sizeof (buff ));
280- while (len > 0 ) {
281- archive_write_data (a , buff , len );
295+ if (r == ARCHIVE_FATAL )
296+ exit (1 );
297+ if (r > ARCHIVE_FAILED ) {
298+ #if 0
299+ /* Ideally, we would be able to use
300+ * the same code to copy a body from
301+ * an archive_read_disk to an
302+ * archive_write that we use for
303+ * copying data from an archive_read
304+ * to an archive_write_disk.
305+ * Unfortunately, this doesn't quite
306+ * work yet. */
307+ copy_data (disk , a );
308+ #else
309+ /* For now, we use a simpler loop to copy data
310+ * into the target archive. */
311+ fd = open (archive_entry_sourcepath (entry ), O_RDONLY );
282312 len = read (fd , buff , sizeof (buff ));
313+ while (len > 0 ) {
314+ archive_write_data (a , buff , len );
315+ len = read (fd , buff , sizeof (buff ));
316+ }
317+ close (fd );
318+ #endif
283319 }
284- close (fd );
285320 archive_entry_free (entry );
286- if (verbose )
321+ if (needcr )
287322 msg ("\n" );
288323 }
324+ archive_read_close (disk );
325+ archive_read_free (disk );
289326 argv ++ ;
290327 }
291328 archive_write_close (a );
0 commit comments