fs_query: Make B_QUERY_WATCH_ALL part of the public API.

It seems to work well enough at this point, and is used in Tracker,
so why not?

Also update live_query to demonstrate the functionality.
This commit is contained in:
Augustin Cavalier
2026-02-04 17:09:50 -05:00
parent c32328567c
commit 53ee2648fb
7 changed files with 31 additions and 24 deletions
+5 -2
View File
@@ -12,13 +12,16 @@
/* Flags for fs_open_[live_]query() */
#define B_LIVE_QUERY 0x00000001
#define B_LIVE_QUERY (1 << 0)
// Note, if you specify B_LIVE_QUERY, you have to use fs_open_live_query();
// it will be ignored in fs_open_query().
#define B_QUERY_NON_INDEXED 0x00000002
#define B_QUERY_NON_INDEXED (1 << 1)
// Only enable this feature for non time-critical things, it might
// take a long time to proceed.
// Also, not every file system might support this feature.
#define B_QUERY_WATCH_ALL (1 << 2)
// Send node monitor (B_ATTR_CHANGED, B_ENTRY_MOVED, etc.) events for all
// attributes on all entries in the query.
#ifdef __cplusplus
@@ -39,8 +39,6 @@
# include <util/SinglyLinkedList.h>
# include <util/Stack.h>
# include <query_private.h>
#endif // !FS_SHELL
#include <file_systems/QueryParserUtils.h>
-10
View File
@@ -1,10 +0,0 @@
#ifndef QUERY_PRIVATE_H
#define QUERY_PRIVATE_H
// Send node monitor (B_ATTR_CHANGED, etc.) events for all
// attributes on all entries in the query.
#define B_QUERY_WATCH_ALL 0x0000F000
#endif
@@ -14,7 +14,6 @@
#include "Inode.h"
#include "Volume.h"
#include <query_private.h>
#include <file_systems/QueryParser.h>
-1
View File
@@ -22,7 +22,6 @@
#include <MessengerPrivate.h>
#include <syscalls.h>
#include <query_private.h>
#include "QueryPredicate.h"
#include "storage_support.h"
-1
View File
@@ -57,7 +57,6 @@ All rights reserved.
#include "Tracker.h"
#include <fs_attr.h>
#include <query_private.h>
using std::nothrow;
+26 -7
View File
@@ -14,6 +14,8 @@
#include <stdlib.h>
#include <unistd.h>
#include <fs_query.h>
#include <Application.h>
#include <Entry.h>
#include <NodeMonitor.h>
@@ -35,6 +37,7 @@ static const char *kProgramName = __progname;
static bool sAllVolumes = false; // Query all volumes?
static bool sEscapeMetaChars = true; // Escape metacharacters?
static bool sFilesOnly = false; // Show only files?
static bool sWatchAll = false; // Watch all changes?
class LiveQuery : public BApplication {
@@ -84,7 +87,7 @@ LiveQuery::ArgvReceived(int32 argc, char** argv)
// Parse command-line arguments.
int opt;
while ((opt = getopt(argc, argv, "efav:")) != -1) {
while ((opt = getopt(argc, argv, "efawv:")) != -1) {
switch (opt) {
case 'e':
sEscapeMetaChars = false;
@@ -98,6 +101,9 @@ LiveQuery::ArgvReceived(int32 argc, char** argv)
case 'v':
strncpy(volumePath, optarg, B_FILE_NAME_LENGTH);
break;
case 'w':
sWatchAll = true;
break;
default:
_PrintUsage();
@@ -170,6 +176,8 @@ LiveQuery::MessageReceived(BMessage* message)
query->SetVolume(&volume);
query->SetPredicate(predicate);
query->SetTarget(this);
if (sWatchAll)
query->SetFlags(B_QUERY_WATCH_ALL);
fQueries.AddItem(query);
_PerformQuery(*query);
@@ -184,20 +192,30 @@ LiveQuery::MessageReceived(BMessage* message)
int32 device;
int64 directory;
int64 node;
const char* name;
message->FindInt32("device", &device);
message->FindInt64("directory", &directory);
message->FindInt64("node", &node);
message->FindString("name", &name);
switch (what) {
case B_ENTRY_CREATED:
{
printf("CREATED %s\n", name);
printf("CREATED %s\n", message->GetString("name"));
break;
}
case B_ENTRY_REMOVED:
printf("REMOVED %s\n", name);
printf("REMOVED %s\n", message->GetString("name"));
break;
case B_ENTRY_MOVED:
printf("MOVED %s -> %s\n", message->GetString("from name"),
message->GetString("name"));
break;
case B_ATTR_CHANGED:
printf("CHANGED %s\n", message->GetString("attr"));
break;
default:
printf("unknown message %d\n", what);
break;
}
break;
@@ -217,6 +235,7 @@ LiveQuery::_PrintUsage()
" -e\t\tdon't escape meta-characters\n"
" -f\t\tshow only files (ie. no directories or symbolic links)\n"
" -a\t\tperform the query on all volumes\n"
" -w\t\twatch all attribute changes\n"
" -v <file>\tperform the query on just one volume; <file> can be any\n"
"\t\tfile on that volume. Defaults to the current volume.\n"
" Hint: '%s name=bar' will find files named \"bar\"\n",