Bug 259953 - net/minidlna: rescan support/fix
Summary: net/minidlna: rescan support/fix
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Only Me
Assignee: Gleb Smirnoff
URL:
Keywords: needs-qa
Depends on:
Blocks:
 
Reported: 2021-11-20 18:48 UTC by gerrit
Modified: 2024-12-29 21:44 UTC (History)
3 users (show)

See Also:


Attachments
Proposed patch to rectify rescan/rebuild commands (470 bytes, text/plain)
2021-11-24 07:50 UTC, gerrit
no flags Details
patch with correct PREFIX path added (470 bytes, text/plain)
2021-11-24 07:54 UTC, gerrit
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description gerrit 2021-11-20 18:48:42 UTC
minidlna comes with a "rescan" command for rc.d. However, this reads

rescan_cmd="$command -R -u $minidlna_uid -f /usr/local/etc/minidlna.conf"

This is in line with the manpage, but obviously wrong when comparing to the commandline help (minidlnad -h):

        -r forces a rescan
        -R forces a rebuild

So "-R" forces a rebuild of the database while a rescan uses "-r". I verified that this is what is actually happening by checking the database file and the time each command takes (rescan is fast and just adds new stuff, rebuild takes much longer and also removed outdated entries). Thus I propose to change the rc.d script to contain

extra_commands="rescan rebuild"
rescan_cmd="$command -r -u $minidlna_uid -f /usr/local/etc/minidlna.conf"
rebuild_cmd="$command -R -u $minidlna_uid -f /usr/local/etc/minidlna.conf"

Furthermore, as this is not handled via signals on the running process, it might be useful to force a stop command before doing either rescan or rebuild.
Comment 1 gerrit 2021-11-24 07:50:18 UTC
Created attachment 229687 [details]
Proposed patch to rectify rescan/rebuild commands

Add proposed patch (so far without forcing stop).
Comment 2 gerrit 2021-11-24 07:51:15 UTC
Comment on attachment 229687 [details]
Proposed patch to rectify rescan/rebuild commands

>--- minidlna.in~	2021-11-24 08:46:30.000000000 +0100
>+++ minidlna.in	2021-11-24 08:47:17.757510000 +0100
>@@ -27,7 +27,8 @@
> start_precmd="install -d -o $minidlna_uid ${pidfile%/*} /var/db/minidlna"
> stop_postcmd="rm -f $pidfile"
> 
>-extra_commands=rescan
>+extra_commands="rescan rebuild"
>+rescan_cmd="$command -r -u $minidlna_uid -f %%PREFIX%%/etc/minidlna.conf"
> rescan_cmd="$command -R -u $minidlna_uid -f %%PREFIX%%/etc/minidlna.conf"
> 
> run_rc_command $1
Comment 3 gerrit 2021-11-24 07:54:34 UTC
Created attachment 229688 [details]
patch with correct PREFIX path added

Sorry for messing up the patch creation before, hopefully this will work now. ;-)
Comment 4 gerrit 2021-11-24 08:07:57 UTC
For the record: There is an open request for minidlna to support signal for rescan unter
https://sourceforge.net/p/minidlna/patches/172/

However, it looks like this hasn't made it into any release, yet.
Comment 5 Gleb Smirnoff freebsd_committer freebsd_triage 2024-12-29 04:16:25 UTC
The patch doesn't seem correct to me. Patched file would have to assignments to $rescan_cmd.

Also, here is what -R does inside minidlnad:

                case 'R':
                        snprintf(buf, sizeof(buf), "rm -rf %s/files.db %s/art_cache", db_path, db_path);
                        if (system(buf) != 0)
                                DPRINTF(E_FATAL, L_GENERAL, "Failed to clean old file cache %s. EXITING\n", db_path);
                        break;

And that's all :(

I also looked at the pull request. Looks like more work needs to be done on the side of the minidlna itself. Not much we can do in our port.
Comment 6 Gleb Smirnoff freebsd_committer freebsd_triage 2024-12-29 04:17:05 UTC
In the last message: s/to assignments/two assignments/.
Comment 7 gerrit 2024-12-29 13:07:25 UTC
(In reply to Gleb Smirnoff from comment #6)

Yeah, and I managed to mess up the suggested patch twice. :-(
Aynway:

extra_commands="rescan rebuild"
rescan_cmd="$command -r -u $minidlna_uid -f /usr/local/etc/minidlna.conf"
rebuild_cmd="$command -R -u $minidlna_uid -f /usr/local/etc/minidlna.conf"


All I can say is that this works for me as advertised in the commandline help. This is useful for me as rescanning the database is more lightweight than rebuilding. From the code:



case 'r':
                        SETFLAG(RESCAN_MASK);
                        break;
Comment 8 Gleb Smirnoff freebsd_committer freebsd_triage 2024-12-29 19:56:28 UTC
What if I just substitute -R with -r in the existing script, without adding any extra commands? What minidlna does with -R seems too stupid for me to officially offer our users :)
Comment 9 gerrit 2024-12-29 20:30:44 UTC
(In reply to Gleb Smirnoff from comment #8)

Well, if the user really wants to rebuild the database, what is he supposed to do? Either find out where the database files live and delete them manually, or stop, minidlna service and call it with the -R option manually on the commandline.

So yeah, substituting -R with -r in the existing script is certainly better than doing nothing, but simply adding the option won't hurt anyone and would imho show more consist behaviour to the user.
Comment 10 commit-hook freebsd_committer freebsd_triage 2024-12-29 21:44:50 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=c56f2a7ef8c8ce8d11277f12343fd2dee1358ec9

commit c56f2a7ef8c8ce8d11277f12343fd2dee1358ec9
Author:     Gleb Smirnoff <glebius@FreeBSD.org>
AuthorDate: 2024-12-29 21:42:09 +0000
Commit:     Gleb Smirnoff <glebius@FreeBSD.org>
CommitDate: 2024-12-29 21:42:09 +0000

    net/minidlna: rescan/rebuild support in rc script

    Fix the rescan command to actually send rescan signal to minidlnad,
    instead of doing a rebuild.  Add rebuild command.

    Submitted by:   gerrit@weinberg2.de
    PR:             259953

 net/minidlna/Makefile          | 2 +-
 net/minidlna/files/minidlna.in | 5 +++--
 2 files changed, 4 insertions(+), 3 deletions(-)