Date: Sat, 7 Mar 2009 07:23:04 +0000 (UTC) From: Tim Kientzle <kientzle@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r189487 - head/lib/libarchive/test Message-ID: <200903070723.n277N4Cf042123@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: kientzle Date: Sat Mar 7 07:23:04 2009 New Revision: 189487 URL: http://svn.freebsd.org/changeset/base/189487 Log: Merge r718 from libarchive.googlecode.com: Some additional tests of restoring files to disk with unusual characters, specifically to exercise Windows issues. Modified: head/lib/libarchive/test/test_write_disk.c Modified: head/lib/libarchive/test/test_write_disk.c ============================================================================== --- head/lib/libarchive/test/test_write_disk.c Sat Mar 7 07:19:25 2009 (r189486) +++ head/lib/libarchive/test/test_write_disk.c Sat Mar 7 07:23:04 2009 (r189487) @@ -218,6 +218,46 @@ static void create_reg_file4(struct arch failure(msg); assertEqualInt(st.st_size, sizeof(data)); } + +#ifdef _WIN32 +static void create_reg_file_win(struct archive_entry *ae, const char *msg) +{ + static const char data[]="abcdefghijklmnopqrstuvwxyz"; + struct archive *ad; + struct stat st; + char *p, *fname; + size_t l; + + /* Write the entry to disk. */ + assert((ad = archive_write_disk_new()) != NULL); + archive_write_disk_set_options(ad, ARCHIVE_EXTRACT_TIME); + failure("%s", msg); + archive_entry_set_size(ae, sizeof(data)); + archive_entry_set_mtime(ae, 123456789, 0); + assertEqualIntA(ad, 0, archive_write_header(ad, ae)); + assertEqualInt(sizeof(data), archive_write_data(ad, data, sizeof(data))); + assertEqualIntA(ad, 0, archive_write_finish_entry(ad)); +#if ARCHIVE_VERSION_NUMBER < 2000000 + archive_write_finish(ad); +#else + assertEqualInt(0, archive_write_finish(ad)); +#endif + /* Test the entries on disk. */ + l = strlen(archive_entry_pathname(ae)); + fname = malloc(l + 1); + assert(NULL != fname); + strcpy(fname, archive_entry_pathname(ae)); + /* Replace unusable characters in Windows to '_' */ + for (p = fname; *p != '\0'; p++) + if (*p == ':' || *p == '*' || *p == '?' || + *p == '"' || *p == '<' || *p == '>' || *p == '|') + *p = '_'; + assert(0 == stat(fname, &st)); + failure("st.st_mode=%o archive_entry_mode(ae)=%o", + st.st_mode, archive_entry_mode(ae)); + assertEqualInt(st.st_size, sizeof(data)); +} +#endif /* _WIN32 */ #endif DEFINE_TEST(test_write_disk) @@ -285,5 +325,23 @@ DEFINE_TEST(test_write_disk) archive_entry_set_mode(ae, S_IFREG | 0744); create(ae, "Test creating a file over an existing dir."); archive_entry_free(ae); + +#ifdef _WIN32 + /* A file with unusable characters in its file name. */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "f:i*l?e\"f<i>l|e"); + archive_entry_set_mode(ae, S_IFREG | 0755); + create_reg_file_win(ae, "Test creating a regular file" + " with unusable characters in its file name"); + archive_entry_free(ae); + + /* A file with unusable characters in its directory name. */ + assert((ae = archive_entry_new()) != NULL); + archive_entry_copy_pathname(ae, "d:i*r?e\"c<t>o|ry/file1"); + archive_entry_set_mode(ae, S_IFREG | 0755); + create_reg_file_win(ae, "Test creating a regular file" + " with unusable characters in its file name"); + archive_entry_free(ae); +#endif /* _WIN32 */ #endif }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200903070723.n277N4Cf042123>