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:
@@ -12,13 +12,16 @@
|
|||||||
|
|
||||||
/* Flags for fs_open_[live_]query() */
|
/* 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();
|
// Note, if you specify B_LIVE_QUERY, you have to use fs_open_live_query();
|
||||||
// it will be ignored in fs_open_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
|
// Only enable this feature for non time-critical things, it might
|
||||||
// take a long time to proceed.
|
// take a long time to proceed.
|
||||||
// Also, not every file system might support this feature.
|
// 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
|
#ifdef __cplusplus
|
||||||
|
|||||||
@@ -39,8 +39,6 @@
|
|||||||
|
|
||||||
# include <util/SinglyLinkedList.h>
|
# include <util/SinglyLinkedList.h>
|
||||||
# include <util/Stack.h>
|
# include <util/Stack.h>
|
||||||
|
|
||||||
# include <query_private.h>
|
|
||||||
#endif // !FS_SHELL
|
#endif // !FS_SHELL
|
||||||
|
|
||||||
#include <file_systems/QueryParserUtils.h>
|
#include <file_systems/QueryParserUtils.h>
|
||||||
|
|||||||
@@ -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 "Inode.h"
|
||||||
#include "Volume.h"
|
#include "Volume.h"
|
||||||
|
|
||||||
#include <query_private.h>
|
|
||||||
#include <file_systems/QueryParser.h>
|
#include <file_systems/QueryParser.h>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,6 @@
|
|||||||
|
|
||||||
#include <MessengerPrivate.h>
|
#include <MessengerPrivate.h>
|
||||||
#include <syscalls.h>
|
#include <syscalls.h>
|
||||||
#include <query_private.h>
|
|
||||||
|
|
||||||
#include "QueryPredicate.h"
|
#include "QueryPredicate.h"
|
||||||
#include "storage_support.h"
|
#include "storage_support.h"
|
||||||
|
|||||||
@@ -57,7 +57,6 @@ All rights reserved.
|
|||||||
#include "Tracker.h"
|
#include "Tracker.h"
|
||||||
|
|
||||||
#include <fs_attr.h>
|
#include <fs_attr.h>
|
||||||
#include <query_private.h>
|
|
||||||
|
|
||||||
|
|
||||||
using std::nothrow;
|
using std::nothrow;
|
||||||
|
|||||||
@@ -14,6 +14,8 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include <fs_query.h>
|
||||||
|
|
||||||
#include <Application.h>
|
#include <Application.h>
|
||||||
#include <Entry.h>
|
#include <Entry.h>
|
||||||
#include <NodeMonitor.h>
|
#include <NodeMonitor.h>
|
||||||
@@ -35,6 +37,7 @@ static const char *kProgramName = __progname;
|
|||||||
static bool sAllVolumes = false; // Query all volumes?
|
static bool sAllVolumes = false; // Query all volumes?
|
||||||
static bool sEscapeMetaChars = true; // Escape metacharacters?
|
static bool sEscapeMetaChars = true; // Escape metacharacters?
|
||||||
static bool sFilesOnly = false; // Show only files?
|
static bool sFilesOnly = false; // Show only files?
|
||||||
|
static bool sWatchAll = false; // Watch all changes?
|
||||||
|
|
||||||
|
|
||||||
class LiveQuery : public BApplication {
|
class LiveQuery : public BApplication {
|
||||||
@@ -84,7 +87,7 @@ LiveQuery::ArgvReceived(int32 argc, char** argv)
|
|||||||
|
|
||||||
// Parse command-line arguments.
|
// Parse command-line arguments.
|
||||||
int opt;
|
int opt;
|
||||||
while ((opt = getopt(argc, argv, "efav:")) != -1) {
|
while ((opt = getopt(argc, argv, "efawv:")) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'e':
|
case 'e':
|
||||||
sEscapeMetaChars = false;
|
sEscapeMetaChars = false;
|
||||||
@@ -98,6 +101,9 @@ LiveQuery::ArgvReceived(int32 argc, char** argv)
|
|||||||
case 'v':
|
case 'v':
|
||||||
strncpy(volumePath, optarg, B_FILE_NAME_LENGTH);
|
strncpy(volumePath, optarg, B_FILE_NAME_LENGTH);
|
||||||
break;
|
break;
|
||||||
|
case 'w':
|
||||||
|
sWatchAll = true;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
_PrintUsage();
|
_PrintUsage();
|
||||||
@@ -170,6 +176,8 @@ LiveQuery::MessageReceived(BMessage* message)
|
|||||||
query->SetVolume(&volume);
|
query->SetVolume(&volume);
|
||||||
query->SetPredicate(predicate);
|
query->SetPredicate(predicate);
|
||||||
query->SetTarget(this);
|
query->SetTarget(this);
|
||||||
|
if (sWatchAll)
|
||||||
|
query->SetFlags(B_QUERY_WATCH_ALL);
|
||||||
|
|
||||||
fQueries.AddItem(query);
|
fQueries.AddItem(query);
|
||||||
_PerformQuery(*query);
|
_PerformQuery(*query);
|
||||||
@@ -184,20 +192,30 @@ LiveQuery::MessageReceived(BMessage* message)
|
|||||||
int32 device;
|
int32 device;
|
||||||
int64 directory;
|
int64 directory;
|
||||||
int64 node;
|
int64 node;
|
||||||
const char* name;
|
|
||||||
message->FindInt32("device", &device);
|
message->FindInt32("device", &device);
|
||||||
message->FindInt64("directory", &directory);
|
message->FindInt64("directory", &directory);
|
||||||
message->FindInt64("node", &node);
|
message->FindInt64("node", &node);
|
||||||
message->FindString("name", &name);
|
|
||||||
|
|
||||||
switch (what) {
|
switch (what) {
|
||||||
case B_ENTRY_CREATED:
|
case B_ENTRY_CREATED:
|
||||||
{
|
printf("CREATED %s\n", message->GetString("name"));
|
||||||
printf("CREATED %s\n", name);
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
case B_ENTRY_REMOVED:
|
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;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -217,6 +235,7 @@ LiveQuery::_PrintUsage()
|
|||||||
" -e\t\tdon't escape meta-characters\n"
|
" -e\t\tdon't escape meta-characters\n"
|
||||||
" -f\t\tshow only files (ie. no directories or symbolic links)\n"
|
" -f\t\tshow only files (ie. no directories or symbolic links)\n"
|
||||||
" -a\t\tperform the query on all volumes\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"
|
" -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"
|
"\t\tfile on that volume. Defaults to the current volume.\n"
|
||||||
" Hint: '%s name=bar' will find files named \"bar\"\n",
|
" Hint: '%s name=bar' will find files named \"bar\"\n",
|
||||||
|
|||||||
Reference in New Issue
Block a user