Removed directory and symlink special cases from

GuessMimeType(entry_ref*) and placed them in
Database::GuessMimeType(entry_ref*)


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1329 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Tyler Dauwalder
2002-10-01 07:34:15 +00:00
parent 86c6e9c1c1
commit a551958795
+31 -51
View File
@@ -129,9 +129,8 @@ SnifferRules::~SnifferRules()
/*! \brief Guesses a MIME type for the supplied entry_ref. /*! \brief Guesses a MIME type for the supplied entry_ref.
Only the data in the given entry is considered, not the filename or Only the data in the given entry is considered, not the filename or
its extension. its extension. Please see GuessMimeType(BPositionIO*, BString*) for
more details.
Please see GuessMimeType(BPositionIO*, BString*) for more details.
\param ref The entry to sniff \param ref The entry to sniff
\param type Pointer to a pre-allocated BString which is set to the \param type Pointer to a pre-allocated BString which is set to the
@@ -145,57 +144,38 @@ status_t
SnifferRules::GuessMimeType(const entry_ref *ref, BString *type) SnifferRules::GuessMimeType(const entry_ref *ref, BString *type)
{ {
status_t err = ref && type ? B_OK : B_BAD_VALUE; status_t err = ref && type ? B_OK : B_BAD_VALUE;
ssize_t bytes = 0; ssize_t bytes = 0;
char *buffer = NULL; char *buffer = NULL;
// See if we have a directory, a symlink, or a vanilla file BFile file;
BNode node;
struct stat statData; // First find out the max number of bytes we need to read
if (!err) // from the file to fully accomodate all of our currently
err = node.SetTo(ref); // installed sniffer rules
if (!err)
err = node.GetStat(&statData);
if (!err) { if (!err) {
if (S_ISDIR(statData.st_mode)) { bytes = MaxBytesNeeded();
// Directory if (bytes < 0)
type->SetTo(kDirectoryType); err = bytes;
} else if (S_ISLNK(statData.st_mode)) { }
// Symlink
type->SetTo(kSymlinkType); // Next read that many bytes (or fewer, if the file isn't
} else if (S_ISREG(statData.st_mode)) { // that long) into a buffer
// Regular file if (!err) {
BFile file; buffer = new(nothrow) char[bytes];
// First find out the max number of bytes we need to read if (!buffer)
// from the file to fully accomodate all of our currently err = B_NO_MEMORY;
// installed sniffer rules }
if (!err) { if (!err)
bytes = MaxBytesNeeded(); err = file.SetTo(ref, B_READ_ONLY);
if (bytes < 0) if (!err) {
err = bytes; bytes = file.Read(buffer, bytes);
} if (bytes < 0)
// Next read that many bytes (or fewer, if the file isn't err = bytes;
// that long) into a buffer }
if (!err) {
buffer = new(nothrow) char[bytes]; // Now sniff the buffer
if (!buffer) if (!err) {
err = B_NO_MEMORY; BMemoryIO data(buffer, bytes);
} err = GuessMimeType(&data, type);
if (!err)
err = file.SetTo(ref, B_READ_ONLY);
if (!err) {
bytes = file.Read(buffer, bytes);
if (bytes < 0)
err = bytes;
}
// Now sniff the buffer
if (!err) {
BMemoryIO data(buffer, bytes);
err = GuessMimeType(&data, type);
}
} else {
// ?????
err = B_FILE_ERROR;
}
} }
return err; return err;