Go to the FreeLists Home Page Home Signup Help Login
 



[openbeosstorage] || [Date Prev] [03-2002 Date Index] [Date Next] || [Thread Prev] [03-2002 Thread Index] [Thread Next]

[openbeosstorage] NodeInfo 2nd Try

  • From: Tyler Dauwalder <tyler@xxxxxxxxxxxxx>
  • To: OpenBeOSStorage@xxxxxxxxxxxxx
  • Date: Fri, 29 Mar 2002 00:15:47 +0000
Hmmm, Ectaris did not like my attachment last time for some reason. This on=
e I just inlined it below.
----------------------------------------------------------------------
Thanks for the update :-)

> So any code put into the CVS between now and when I get a net connection =
at
> home will be untested and might not conform 100% to the Open Tracker code
> guild lines. If anyone objects to this, I'll wait until I have a connecti=
on
> at home before checking it in, but I really don't think it'll effect anyo=
ne
> but me, as by the time I get a release-worthy version I will of tested it
> all, and formatted the code.

That's fine with me. You might take NodeInfo.cpp out of the libstorage list=
ing in source/lib/Jamfile, just on the off chance that somebody slurps the =
storage_kit folder out of CVS and tries to compile it and doesn't understan=
d why they get a bunch of errors from NodeInfo, but otherwise don't worry a=
bout it.

> Right so what I am actually up to, well I=92m currently working on BNodeI=
nfo
> and the BStatables tests. However I=92ve hit a block on BNodeInfo.
> GetType(char *type) returns the MIME type for a file, which (as I underst=
and 
> it) checks the attribute BEOS:TYPE then if this does not exist will check
> the file extension,

I don't think it checks the file extension. The NodeInfo docs say that it's=
 only a wrapper around attribute calls. I also wrote a little program to do=
uble check (see below). It creates a new text file called "test.txt" and th=
en gets the MIME type for it. It initially returns an error code, B_ENTRY_N=
OT_FOUND, which I believe is what ReadAttr() would return if you tried to r=
ead an attribute that didn't exist. If you then Identify the file from Trac=
ker and run the program again, it'll get "text/plain" like you'd expect.

As best I can tell, you can only get a pathname from a Node if it's a direc=
tory in R5. You can make an entry ref using a directory's node ref and the =
filename ".", but if you try a similar thing using a regular file's node re=
f, you get an error.

On the other hand, I don't see why we couldn't do that with our own kernel =
when the time comes. That might be a nice feature to add (having NodeInfo o=
bjects decipher the type from the extension if the attribute doesn't exist)=
. For now though, I guess just do what the R5 version does.

-Tyler

----------------------------------------
BEGIN NodeInfoTest.cpp
----------------------------------------
#include <NodeInfo.h>
#include <Node.h>
#include <unistd.h>
#include <iostream>
#include <stdio.h>

void TypeFile(const char *path) {
=09if (path =3D=3D NULL)
=09=09return;
=09=09
=09BNode node(path);
=09
=09BNodeInfo info(&node);
=09char str[B_MIME_TYPE_LENGTH];
=09status_t result =3D info.GetType(str);
=09if (result !=3D B_OK) {
=09=09cout << "Error getting type (0x" << hex << result << dec << ")" << en=
dl;
=09=09return;
=09}
=09
=09cout << "Type =3D=3D '" << str << "'" << endl;
}

int main() {
=09int fd;

=09// Create the file if it doesn't already exist=09
=09fd =3D open("test.txt", O_CREAT);
=09if (fd =3D=3D -1) {
=09=09cout << "Error creating file" << endl;
=09=09return -1;
=09}=09
=09close(fd);
=09
=09// Get the file type
=09TypeFile("test.txt");
=09
=09return 0;
}

----------------------------------------
END NodeInfoTest.cpp
----------------------------------------





[ Home | Signup | Help | Login | Archives | Lists ]

All trademarks and copyrights within the FreeLists archives are owned by their respective owners.
Everything else ©2007 Avenir Technologies, LLC.