Esempio n. 1
1
/*
 * Verify that test_read_extract correctly works with
 * Zip entries that use length-at-end.
 */
static void
verify_extract_length_at_end(struct archive *a, int seek_checks)
{
	struct archive_entry *ae;

	assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));

	assertEqualInt(archive_entry_is_encrypted(ae), 0);
	assertEqualIntA(a, archive_read_has_encrypted_entries(a), 0);
	assertEqualString("hello.txt", archive_entry_pathname(ae));
	if (seek_checks) {
		assertEqualInt(AE_IFREG | 0644, archive_entry_mode(ae));
		assert(archive_entry_size_is_set(ae));
		assertEqualInt(6, archive_entry_size(ae));
	} else {
		assert(!archive_entry_size_is_set(ae));
		assertEqualInt(0, archive_entry_size(ae));
	}

	if (archive_zlib_version() != NULL) {
		assertEqualIntA(a, ARCHIVE_OK, archive_read_extract(a, ae, 0));
		assertFileContents("hello\x0A", 6, "hello.txt");
	} else {
		assertEqualIntA(a, ARCHIVE_FAILED, archive_read_extract(a, ae, 0));
		assertEqualString(archive_error_string(a),
		    "Unsupported ZIP compression method (deflation)");
		assert(archive_errno(a) != 0);
	}

	assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
	assertEqualIntA(a, ARCHIVE_OK, archive_read_free(a));
}
Esempio n. 2
0
static void
verify_files(const char *target)
{
	assertChdir(target);

	/* Regular file with 2 links. */
	failure("%s", target);
	assertIsReg("file", -1);
	failure("%s", target);
	assertFileSize("file", 10);
	failure("%s", target);
	assertFileContents("123456789", 10, "file");
	failure("%s", target);
	assertFileNLinks("file", 2);

	/* Another name for the same file. */
	failure("%s", target);
	assertIsReg("linkfile", -1);
	failure("%s", target);
	assertFileSize("linkfile", 10);
	assertFileContents("123456789", 10, "linkfile");
	assertFileNLinks("linkfile", 2);
	assertIsHardlink("file", "linkfile");

	/* Symlink */
	if (canSymlink())
		assertIsSymlink("symlink", "file", 0);

	/* dir */
	failure("%s", target);
	assertIsDir("dir", 0775);
	assertChdir("..");
}
Esempio n. 3
0
static void create_reg_file2(struct archive_entry *ae, const char *msg)
{
	const int datasize = 100000;
	char *data;
	struct archive *ad;
	int i;

	data = malloc(datasize);
	for (i = 0; i < datasize; i++)
		data[i] = (char)(i % 256);

	/* Write the entry to disk. */
	assert((ad = archive_write_disk_new()) != NULL);
	failure("%s", msg);
	/*
	 * See above for an explanation why this next call
	 * is necessary.
	 */
	archive_entry_set_size(ae, datasize);
	assertEqualIntA(ad, 0, archive_write_header(ad, ae));
	for (i = 0; i < datasize - 999; i += 1000) {
		assertEqualIntA(ad, ARCHIVE_OK,
		    archive_write_data_block(ad, data + i, 1000, i));
	}
	assertEqualIntA(ad, 0, archive_write_finish_entry(ad));
	assertEqualInt(0, archive_write_finish(ad));

	/* Test the entries on disk. */
	assertIsReg(archive_entry_pathname(ae), archive_entry_mode(ae) & 0777);
	assertFileSize(archive_entry_pathname(ae), i);
	assertFileContents(data, datasize, archive_entry_pathname(ae));
	free(data);
}
Esempio n. 4
0
static void
verify_tree(size_t limit)
{
	char name1[260];
	char name2[260];
	size_t i, LOOP_MAX;

	LOOP_MAX = compute_loop_max();

	/* Generate the names we know should be there and verify them. */
	for (i = 1; i < LOOP_MAX; i++) {
		/* Verify a file named "f/abcdef..." */
		sprintf(name1, "f/%s", filenames[i]);
		if (i <= limit) {
			assertFileExists(name1);
			assertFileContents(name1, (int)strlen(name1), name1);
		}

		sprintf(name2, "l/%s", filenames[i]);
		if (i + 2 <= limit) {
			/* Verify hardlink "l/abcdef..." */
			assertIsHardlink(name1, name2);
			/* Verify hardlink "m/abcdef..." */
			name2[0] = 'm';
			assertIsHardlink(name1, name2);
		}

		if (canSymlink()) {
			/* Verify symlink "s/abcdef..." */
			sprintf(name1, "s/%s", filenames[i]);
			sprintf(name2, "../f/%s", filenames[i]);
			if (strlen(name2) <= limit)
				assertIsSymlink(name1, name2);
		}

		/* Verify dir "d/abcdef...". */
		sprintf(name1, "d/%s", filenames[i]);
		if (i + 1 <= limit) { /* +1 for trailing slash */
			if (assertIsDir(name1, -1)) {
				/* TODO: opendir/readdir this
				 * directory and make sure
				 * it's empty.
				 */
			}
		}
	}

#if !defined(_WIN32) || defined(__CYGWIN__)
	{
		const char *dp;
		/* Now make sure nothing is there that shouldn't be. */
		for (dp = "dflms"; *dp != '\0'; ++dp) {
			DIR *d;
			struct dirent *de;
			char dir[2];
			dir[0] = *dp; dir[1] = '\0';
			d = opendir(dir);
			failure("Unable to open dir '%s'", dir);
			if (!assert(d != NULL))
				continue;
			while ((de = readdir(d)) != NULL) {
				char *p = de->d_name;
				if (p[0] == '.')
					continue;
				switch(dp[0]) {
				case 'l': case 'm': case 'd':
					failure("strlen(p)=%d", strlen(p));
					assert(strlen(p) < limit);
					assertEqualString(p,
					    filenames[strlen(p)]);
					break;
				case 'f': case 's':
					failure("strlen(p)=%d", strlen(p));
					assert(strlen(p) < limit + 1);
					assertEqualString(p,
					    filenames[strlen(p)]);
					break;
				default:
					failure("File %s shouldn't be here", p);
					assert(0);
				}
			}
			closedir(d);
		}
	}
#endif
}