Tracker: Check return values, CID 991051 & CID 991052

The CIDs are about mkdir, we want to check that either the command
succeeded or failed because the directory already exists.

However, we also want to check the return value of find_directory()
and Append() to make sure they succeeded as well.
This commit is contained in:
John Scipione 2014-07-24 22:14:32 -04:00
parent 1995f1a63d
commit 1e09ea53e3
1 changed files with 24 additions and 22 deletions

View File

@ -37,6 +37,7 @@ All rights reserved.
#include <utility> #include <utility>
#include <errno.h>
#include <fs_attr.h> #include <fs_attr.h>
#include <parsedate.h> #include <parsedate.h>
#include <stdlib.h> #include <stdlib.h>
@ -286,15 +287,15 @@ FindWindow::TryOpening(const entry_ref* ref)
void void
FindWindow::GetDefaultQuery(BEntry &entry) FindWindow::GetDefaultQuery(BEntry& entry)
{ {
BPath path; BPath path;
find_directory(B_USER_DIRECTORY, &path, true); if (find_directory(B_USER_DIRECTORY, &path, true) == B_OK
path.Append("queries"); && path.Append("queries") == B_OK
mkdir(path.Path(), 0777); && (mkdir(path.Path(), 0777) == 0 || errno == EEXIST)) {
BDirectory directory(path.Path()); BDirectory directory(path.Path());
entry.SetTo(&directory, "default");
entry.SetTo(&directory, "default"); }
} }
@ -610,23 +611,24 @@ FindWindow::FindSaveCommon(bool find)
if (newFile) { if (newFile) {
// create query file in the user's directory // create query file in the user's directory
BPath path; BPath path;
find_directory(B_USER_DIRECTORY, &path, true);
path.Append("queries");
// there might be no queries folder yet, create one // there might be no queries folder yet, create one
mkdir(path.Path(), 0777); if (find_directory(B_USER_DIRECTORY, &path, true) == B_OK
&& path.Append("queries") == B_OK
&& (mkdir(path.Path(), 0777) == 0 || errno == EEXIST)) {
// either use the user specified name, or go with the name
// generated from the predicate, etc.
BString name;
if (userSpecifiedName == NULL)
GetDefaultName(name);
else
name << userSpecifiedName;
// either use the user specified name, or go with the name if (path.Append(name.String()) == B_OK) {
// generated from the predicate, etc. entry.SetTo(path.Path());
if (!userSpecifiedName) { entry.Remove();
BString text; entry.GetRef(&fRef);
GetDefaultName(text); }
path.Append(text.String()); }
} else
path.Append(userSpecifiedName);
entry.SetTo(path.Path());
entry.Remove();
entry.GetRef(&fRef);
} }
fFile = new BFile(&entry, O_RDWR | O_CREAT); fFile = new BFile(&entry, O_RDWR | O_CREAT);