BQuery: Add SetFlags() method.

It can be used to set flags on the query, same as fs_open_query()'s
flags parameter.

fLive had 3 bytes of padding after it, so this doesn't break ABI.
This commit is contained in:
Augustin Cavalier
2025-04-30 17:18:16 -04:00
parent 7e740f61ac
commit d26ab46206
2 changed files with 16 additions and 9 deletions
+2 -1
View File
@@ -63,6 +63,7 @@ public:
status_t SetVolume(const BVolume* volume);
status_t SetPredicate(const char* expression);
status_t SetTarget(BMessenger messenger);
void SetFlags(uint32 flags);
bool IsLive() const;
@@ -102,7 +103,7 @@ private:
BPrivate::Storage::QueryStack* fStack;
char* fPredicate;
dev_t fDevice;
bool fLive;
uint32 fFlags;
port_id fPort;
long fToken;
int fQueryFd;
+14 -8
View File
@@ -39,7 +39,7 @@ BQuery::BQuery()
fStack(NULL),
fPredicate(NULL),
fDevice((dev_t)B_ERROR),
fLive(false),
fFlags(0),
fPort(B_ERROR),
fToken(0),
fQueryFd(-1)
@@ -71,7 +71,7 @@ BQuery::Clear()
fPredicate = NULL;
// reset the other parameters
fDevice = (dev_t)B_ERROR;
fLive = false;
fFlags = 0;
fPort = B_ERROR;
fToken = 0;
return error;
@@ -226,17 +226,23 @@ BQuery::SetTarget(BMessenger messenger)
fPort = messengerPrivate.Port();
fToken = (messengerPrivate.IsPreferredTarget()
? -1 : messengerPrivate.Token());
fLive = true;
}
return error;
}
void
BQuery::SetFlags(uint32 flags)
{
fFlags = flags;
}
// Gets whether the query associated with this object is live.
bool
BQuery::IsLive() const
{
return fLive;
return fPort >= 0;
}
@@ -310,14 +316,14 @@ BQuery::Fetch()
BString parsedPredicate;
_ParseDates(parsedPredicate);
fQueryFd = _kern_open_query(fDevice, parsedPredicate.String(),
parsedPredicate.Length(), fLive ? B_LIVE_QUERY : 0, fPort, fToken);
fQueryFd = _kern_open_query(fDevice,
parsedPredicate.String(), parsedPredicate.Length(),
fFlags | ((fPort >= 0) ? B_LIVE_QUERY : 0),
fPort, fToken);
if (fQueryFd < 0)
return fQueryFd;
// set close on exec flag
fcntl(fQueryFd, F_SETFD, FD_CLOEXEC);
return B_OK;
}