示例#1
0
static void
copy_indexes(dev_t from, dev_t to, bool verbose)
{
	DIR *indexes = fs_open_index_dir(from);
	
	if (verbose)
		puts("Copying indexes:");

	while (dirent *dirent = fs_read_index_dir(indexes)) {
		if (!strcmp(dirent->d_name, "name")
			|| !strcmp(dirent->d_name, "size")
			|| !strcmp(dirent->d_name, "last_modified"))
			continue;

		index_info info;
		if (fs_stat_index(from, dirent->d_name, &info) != 0) {
			fprintf(stderr, "%s: Skipped index \"%s\": %s\n",
				kProgramName, dirent->d_name, strerror(errno));
			continue;
		}

		if (fs_create_index(to, dirent->d_name, info.type, 0) != 0) {
			if (errno == B_BAD_VALUE || errno == B_FILE_EXISTS) {
				// B_BAD_VALUE is what BeOS returns here...
				continue;
			}
			fprintf(stderr, "%s: Could not create index \"%s\": %s\n",
				kProgramName, dirent->d_name, strerror(errno));
		} else if (verbose)
			printf("\t%s\n", dirent->d_name);
	}
}
示例#2
0
status_t
WorkerThread::_MirrorIndices(const BPath& sourceDirectory,
	const BPath& targetDirectory) const
{
	dev_t sourceDevice = dev_for_path(sourceDirectory.Path());
	if (sourceDevice < 0)
		return (status_t)sourceDevice;
	dev_t targetDevice = dev_for_path(targetDirectory.Path());
	if (targetDevice < 0)
		return (status_t)targetDevice;
	DIR* indices = fs_open_index_dir(sourceDevice);
	if (indices == NULL) {
		printf("%s: fs_open_index_dir(): (%d) %s\n", sourceDirectory.Path(),
			errno, strerror(errno));
		// Opening the index directory will fail for example on ISO-Live
		// CDs. The default indices have already been created earlier, so
		// we simply bail.
		return B_OK;
	}
	while (dirent* index = fs_read_index_dir(indices)) {
		if (strcmp(index->d_name, "name") == 0
			|| strcmp(index->d_name, "size") == 0
			|| strcmp(index->d_name, "last_modified") == 0) {
			continue;
		}

		index_info info;
		if (fs_stat_index(sourceDevice, index->d_name, &info) != B_OK) {
			printf("Failed to mirror index %s: fs_stat_index(): (%d) %s\n",
				index->d_name, errno, strerror(errno));
			continue;
		}

		uint32 flags = 0;
			// Flags are always 0 for the moment.
		if (fs_create_index(targetDevice, index->d_name, info.type, flags)
			!= B_OK) {
			if (errno == B_FILE_EXISTS)
				continue;
			printf("Failed to mirror index %s: fs_create_index(): (%d) %s\n",
				index->d_name, errno, strerror(errno));
			continue;
		}
	}
	fs_close_index_dir(indices);
	return B_OK;
}