From 92fd335690aa9535b868b306f7b096dba0c5242a Mon Sep 17 00:00:00 2001 From: Matthew Wilber Date: Thu, 11 Mar 2004 03:19:03 +0000 Subject: [PATCH] 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 --- src/apps/showimage/ShowImageView.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/apps/showimage/ShowImageView.cpp b/src/apps/showimage/ShowImageView.cpp index 00a31dfe03..ddb6255831 100644 --- a/src/apps/showimage/ShowImageView.cpp +++ b/src/apps/showimage/ShowImageView.cpp @@ -42,6 +42,7 @@ #include #include #include +#include #include #include #include @@ -225,11 +226,32 @@ ShowImageView::~ShowImageView() 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 ShowImageView::IsImage(const entry_ref *pref) { if (!pref) 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); if (file.InitCheck() != B_OK) @@ -320,6 +342,11 @@ ShowImageView::SetImage(const entry_ref *pref) BTranslatorRoster *proster = BTranslatorRoster::Default(); if (!proster) 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); translator_info info; memset(&info, 0, sizeof(translator_info));