diff options
author | kientzle <kientzle@FreeBSD.org> | 2007-09-18 04:20:21 +0000 |
---|---|---|
committer | kientzle <kientzle@FreeBSD.org> | 2007-09-18 04:20:21 +0000 |
commit | 064bc8a7f983dccc1cd1f2fa2b2f056e81404780 (patch) | |
tree | 4681d895d4a25e95a3337e09f26885b841ee8920 /lib | |
parent | 4e0e5f8feeeb06cfd82f8d93d667eeb4876790ec (diff) | |
download | FreeBSD-src-064bc8a7f983dccc1cd1f2fa2b2f056e81404780.zip FreeBSD-src-064bc8a7f983dccc1cd1f2fa2b2f056e81404780.tar.gz |
Correct the return value from archive_write_data()
(when used to restore files to disk) to match:
* The documentation
* The return values of this function when used
to write files into an archive.
Approved by: re (bmah)
Pointy hat: \me
MFC after: 5 days
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libarchive/archive_write_disk.c | 11 | ||||
-rw-r--r-- | lib/libarchive/test/test_write_disk.c | 27 |
2 files changed, 33 insertions, 5 deletions
diff --git a/lib/libarchive/archive_write_disk.c b/lib/libarchive/archive_write_disk.c index f5fb3aa..0c15b77 100644 --- a/lib/libarchive/archive_write_disk.c +++ b/lib/libarchive/archive_write_disk.c @@ -444,12 +444,14 @@ _archive_write_data_block(struct archive *_a, const void *buff, size_t size, off_t offset) { struct archive_write_disk *a = (struct archive_write_disk *)_a; - ssize_t bytes_written = 0; + ssize_t bytes_written = 0, total_written = 0; __archive_check_magic(&a->archive, ARCHIVE_WRITE_DISK_MAGIC, ARCHIVE_STATE_DATA, "archive_write_disk_block"); - if (a->fd < 0) - return (ARCHIVE_OK); + if (a->fd < 0) { + archive_set_error(&a->archive, 0, "File not open"); + return (ARCHIVE_WARN); + } archive_clear_error(&a->archive); /* Seek if necessary to the specified offset. */ @@ -470,8 +472,9 @@ _archive_write_data_block(struct archive *_a, } size -= bytes_written; a->offset += bytes_written; + total_written += bytes_written; } - return (ARCHIVE_OK); + return (total_written); } static ssize_t diff --git a/lib/libarchive/test/test_write_disk.c b/lib/libarchive/test/test_write_disk.c index 6b28830..d8ab7b9 100644 --- a/lib/libarchive/test/test_write_disk.c +++ b/lib/libarchive/test/test_write_disk.c @@ -50,6 +50,31 @@ static void create(struct archive_entry *ae, const char *msg) st.st_mode, archive_entry_mode(ae)); assert(st.st_mode == (archive_entry_mode(ae) & ~UMASK)); } + +static void create_reg_file(struct archive_entry *ae, const char *msg) +{ + static const char data[]="abcdefghijklmnopqrstuvwxyz"; + struct archive *ad; + struct stat st; + + /* Write the entry to disk. */ + assert((ad = archive_write_disk_new()) != NULL); + failure("%s", msg); + assertEqualIntA(ad, 0, archive_write_header(ad, ae)); + assertEqualIntA(ad, sizeof(data), archive_write_data(ad, data, sizeof(data))); + assertEqualIntA(ad, 0, archive_write_finish_entry(ad)); +#if ARCHIVE_API_VERSION > 1 + assertEqualInt(0, archive_write_finish(ad)); +#else + archive_write_finish(ad); +#endif + /* Test the entries on disk. */ + assert(0 == stat(archive_entry_pathname(ae), &st)); + failure("st.st_mode=%o archive_entry_mode(ae)=%o", + st.st_mode, archive_entry_mode(ae)); + assertEqualInt(st.st_mode, (archive_entry_mode(ae) & ~UMASK)); + assertEqualInt(st.st_size, sizeof(data)); +} #endif DEFINE_TEST(test_write_disk) @@ -66,7 +91,7 @@ DEFINE_TEST(test_write_disk) assert((ae = archive_entry_new()) != NULL); archive_entry_copy_pathname(ae, "file"); archive_entry_set_mode(ae, S_IFREG | 0755); - create(ae, "Test creating a regular file"); + create_reg_file(ae, "Test creating a regular file"); archive_entry_free(ae); /* A regular file over an existing file */ |