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:
parent
1995f1a63d
commit
1e09ea53e3
|
@ -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,24 +611,25 @@ 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
|
// either use the user specified name, or go with the name
|
||||||
// generated from the predicate, etc.
|
// generated from the predicate, etc.
|
||||||
if (!userSpecifiedName) {
|
BString name;
|
||||||
BString text;
|
if (userSpecifiedName == NULL)
|
||||||
GetDefaultName(text);
|
GetDefaultName(name);
|
||||||
path.Append(text.String());
|
else
|
||||||
} else
|
name << userSpecifiedName;
|
||||||
path.Append(userSpecifiedName);
|
|
||||||
|
|
||||||
|
if (path.Append(name.String()) == B_OK) {
|
||||||
entry.SetTo(path.Path());
|
entry.SetTo(path.Path());
|
||||||
entry.Remove();
|
entry.Remove();
|
||||||
entry.GetRef(&fRef);
|
entry.GetRef(&fRef);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fFile = new BFile(&entry, O_RDWR | O_CREAT);
|
fFile = new BFile(&entry, O_RDWR | O_CREAT);
|
||||||
ASSERT(fFile->InitCheck() == B_OK);
|
ASSERT(fFile->InitCheck() == B_OK);
|
||||||
|
|
Loading…
Reference in New Issue