Beispiel #1
0
void URLView::CreatePerson( const BString *fullName, const BString *title ) {
	// Read the file defined by the path and the title.
	BFile *file = new BFile( fullName->String(), B_WRITE_ONLY );
		
	// Set the file's MIME type to be a person.
	BNodeInfo *nodeInfo = new BNodeInfo( file );
	nodeInfo->SetType( "application/x-person" );
	delete nodeInfo;
	delete file;

	// Add all the attributes, both those inherrent to person files and any
	// the developer may have defined using AddAttribute().
	DIR *d;
	int fd;
	d = fs_open_attr_dir( fullName->String() );
	if( d ) {
		fd = open( fullName->String(), O_WRONLY );
		fs_write_attr( fd, "META:name", B_STRING_TYPE, 0, title->String(), title->Length() + 1 );
		BString email = GetImportantURL();
		fs_write_attr( fd, "META:email", B_STRING_TYPE, 0, email.String(), email.Length() + 1 );
		WriteAttributes( fd );
		close( fd );
		fs_close_attr_dir( d ); 
	}
}
Beispiel #2
0
// Close
status_t
AttrDirIterator::Close()
{
    if (!fDir)
        return B_BAD_VALUE;

    status_t error = B_OK;
    if (fs_close_attr_dir(fDir) < 0)
        error = errno;

    fDir = NULL;
    return error;
}
void
test_remove_attributes(BFile& file, int32 start, int32 count, int32 removeAt,
	int32 removeIndex1, int32 removeIndex2)
{
	int fd = file.Dup();
	if (fd < 0)
		return;

	int32 index = 0;
	bool seen[4096] = {0};

	if (gVerbose)
		printf("test removeAt %ld\n", removeAt);

	DIR* dir = fs_fopen_attr_dir(fd);
	while (struct dirent* entry = fs_read_attr_dir(dir)) {
		if (gVerbose)
			printf("  %ld. %s\n", index, entry->d_name);
		if (index == removeAt) {
			if (removeIndex1 > 0)
				remove_marker_attribute(file, removeIndex1);
			if (removeIndex2 > 0)
				remove_marker_attribute(file, removeIndex2);
		}
		index++;

		if (is_marker(entry->d_name))
			continue;

		int32 attributeIndex = attribute_index(entry->d_name);
		if (attributeIndex > 0) {
			if (seen[attributeIndex]) {
				printf("attribute index %ld already listed!\n", attributeIndex);
				exit(1);
			} else
				seen[attributeIndex] = true;
		}
	}

	fs_close_attr_dir(dir);
	close(fd);

	for (int32 i = start; i < start + count; i++) {
		if (!seen[i]) {
			printf("attribute index %ld not listed, saw only %ld/%ld!\n", i,
				index, count);
			exit(1);
		}
	}
}
Beispiel #4
0
void URLView::CreateBookmark( const BString *fullName, const BString *title ) {
	// Read the file defined by the path and the title.
	BFile *file = new BFile( fullName->String(), B_WRITE_ONLY );

	// Set the file's MIME type to be a bookmark.
	BNodeInfo *nodeInfo = new BNodeInfo( file );
	nodeInfo->SetType( "application/x-vnd.Be-bookmark" );
	delete nodeInfo;
	delete file;

	// Add all the attributes, both those inherrent to bookmarks and any
	// the developer may have defined using AddAttribute().
	DIR *d;
	int fd;
	d = fs_open_attr_dir( fullName->String() );
	if( d ) {
		fd = open( fullName->String(), O_WRONLY );
		fs_write_attr( fd, "META:title", B_STRING_TYPE, 0, title->String(), title->Length() + 1 );
		fs_write_attr( fd, "META:url", B_STRING_TYPE, 0, url->String(), url->Length() + 1 );
		WriteAttributes( fd );
		close( fd );
		fs_close_attr_dir( d ); 
	}
}