Skip to content

Commit a246013

Browse files
committed
spotlight: add support for localsearch indexing of home directories
The [Homes] spotlight option (default: inherits from [Global]) controls whether the basedir regex path is submitted to the search indexer, covering all user home directories beneath it. Because [Homes] volumes are resolved per-user at login and never pass through creatvol() in the master process, OPTION_SPOTLIGHT must be set explicitly during config parsing when Homes spotlight is enabled -- otherwise the localsearch dbus infrastructure is never started. Add INIPARSER_GETBOOL macro parallel to the other iniparser wrapper macros.
1 parent f899e55 commit a246013

4 files changed

Lines changed: 41 additions & 4 deletions

File tree

doc/manpages/man5/afp.conf.5.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -732,11 +732,14 @@ of 10000 candidate results. Set a larger nonzero value to raise the
732732
*xapian* cap. The *cnid* backend does not use this option and is limited
733733
by its fixed CNID search reply cap.
734734
735-
spotlight = *BOOLEAN* (default: *yes*) **(G)**/**(V)**
735+
spotlight = *BOOLEAN* (default: *yes*) **(G)**/**(V)**/**(H)**
736736
737737
> Whether to enable Spotlight-compatible searches.
738-
As a global option, this sets the default for volumes. As a volume option,
739-
it overrides the global default for that volume.
738+
As a global option, this sets the default for volumes and home directories.
739+
As a volume or Homes option, it overrides the global default.
740+
When enabled for the Homes section, the directory specified by
741+
**basedir regex** is submitted to the search indexer, covering all user
742+
home directories beneath it.
740743
>
741744
> A volume is searchable only when its effective **spotlight** setting is
742745
enabled and a supported **spotlight backend** is available for that volume.

etc/netatalk/netatalk.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,22 @@ static int set_sl_volumes(void)
169169
}
170170
}
171171

172+
int global_sl = INIPARSER_GETBOOL(obj.iniconfig, INISEC_GLOBAL, "spotlight", 1);
173+
174+
if (INIPARSER_GETBOOL(obj.iniconfig, INISEC_HOMES, "spotlight", global_sl)) {
175+
const char *basedir = INIPARSER_GETSTR(obj.iniconfig, INISEC_HOMES,
176+
"basedir regex", NULL);
177+
178+
if (basedir) {
179+
if (first) {
180+
fprintf(fp, "index-recursive-directories=['%s'", basedir);
181+
first = false;
182+
} else {
183+
fprintf(fp, ", '%s'", basedir);
184+
}
185+
}
186+
}
187+
172188
if (first) {
173189
/* No Spotlight volumes: emit typed empty array so dconf update parses it */
174190
fprintf(fp, "index-recursive-directories=@as []\n");

include/atalk/iniparser_util.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2024-2025 Daniel Markstedt
2+
* Copyright (C) 2024-2026 Daniel Markstedt
33
* All Rights Reserved. See COPYING.
44
*
55
* This program is free software; you can redistribute it and/or modify
@@ -30,6 +30,12 @@
3030
#define INISEC_GLOBAL "global"
3131
#define INISEC_HOMES "homes"
3232

33+
#define INIPARSER_GETBOOL(config, section, key, default) ({ \
34+
char _option[MAXOPTLEN]; \
35+
snprintf(_option, sizeof(_option), "%s:%s", section, key); \
36+
iniparser_getboolean(config, _option, default); \
37+
})
38+
3339
#define INIPARSER_GETSTR(config, section, key, default) ({ \
3440
char _option[MAXOPTLEN]; \
3541
snprintf(_option, sizeof(_option), "%s:%s", section, key); \

libatalk/util/netatalk_conf.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2779,6 +2779,18 @@ int afp_config_parse(AFPObj *AFPObj, char *processname)
27792779
options->flags |= OPTION_SPOTLIGHT_VOL;
27802780
}
27812781

2782+
{
2783+
/* OPTION_SPOTLIGHT is normally set by creatvol() per named volume, but
2784+
* [Homes] volumes are resolved per-user at login and never reach creatvol()
2785+
* in the master process, so we set the flag here if Homes spotlight is on. */
2786+
int global_sl = options->flags & OPTION_SPOTLIGHT_VOL ? 1 : 0;
2787+
2788+
if (getoption_bool(config, INISEC_HOMES, "spotlight", NULL, global_sl)
2789+
&& getoption_str(config, INISEC_HOMES, "basedir regex", NULL, NULL)) {
2790+
options->flags |= OPTION_SPOTLIGHT;
2791+
}
2792+
}
2793+
27822794
if (getoption_bool(config, INISEC_GLOBAL, "veto message", NULL, 0)) {
27832795
options->flags |= OPTION_VETOMSG;
27842796
}

0 commit comments

Comments
 (0)