Fixed to check if refs are directories and to error properly if they are
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6949 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -42,6 +42,7 @@
|
|||||||
#include <Rect.h>
|
#include <Rect.h>
|
||||||
#include <SupportDefs.h>
|
#include <SupportDefs.h>
|
||||||
#include <Directory.h>
|
#include <Directory.h>
|
||||||
|
#include <Entry.h>
|
||||||
#include <Application.h>
|
#include <Application.h>
|
||||||
#include <Roster.h>
|
#include <Roster.h>
|
||||||
#include <NodeInfo.h>
|
#include <NodeInfo.h>
|
||||||
@@ -225,11 +226,32 @@ ShowImageView::~ShowImageView()
|
|||||||
DeleteBitmap();
|
DeleteBitmap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// returns B_ERROR if problems reading ref
|
||||||
|
// B_OK if ref is not a directory
|
||||||
|
// B_OK + 1 if ref is a directory
|
||||||
|
status_t
|
||||||
|
ent_is_dir(const entry_ref *ref)
|
||||||
|
{
|
||||||
|
BEntry ent(ref);
|
||||||
|
if (ent.InitCheck() != B_OK)
|
||||||
|
return B_ERROR;
|
||||||
|
|
||||||
|
struct stat st;
|
||||||
|
if (ent.GetStat(&st) != B_OK)
|
||||||
|
return B_ERROR;
|
||||||
|
|
||||||
|
return S_ISDIR(st.st_mode) ? (B_OK + 1) : B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
ShowImageView::IsImage(const entry_ref *pref)
|
ShowImageView::IsImage(const entry_ref *pref)
|
||||||
{
|
{
|
||||||
if (!pref)
|
if (!pref)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if (ent_is_dir(pref) != B_OK)
|
||||||
|
// if ref is erroneous or a directory, return false
|
||||||
|
return false;
|
||||||
|
|
||||||
BFile file(pref, B_READ_ONLY);
|
BFile file(pref, B_READ_ONLY);
|
||||||
if (file.InitCheck() != B_OK)
|
if (file.InitCheck() != B_OK)
|
||||||
@@ -320,6 +342,11 @@ ShowImageView::SetImage(const entry_ref *pref)
|
|||||||
BTranslatorRoster *proster = BTranslatorRoster::Default();
|
BTranslatorRoster *proster = BTranslatorRoster::Default();
|
||||||
if (!proster)
|
if (!proster)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|
||||||
|
if (ent_is_dir(pref) != B_OK)
|
||||||
|
// if ref is erroneous or a directory, return error
|
||||||
|
return B_ERROR;
|
||||||
|
|
||||||
BFile file(&ref, B_READ_ONLY);
|
BFile file(&ref, B_READ_ONLY);
|
||||||
translator_info info;
|
translator_info info;
|
||||||
memset(&info, 0, sizeof(translator_info));
|
memset(&info, 0, sizeof(translator_info));
|
||||||
|
|||||||
Reference in New Issue
Block a user