gonic
gonic copied to clipboard
Implementation of fsnotify based scan watcher
Tested on Linux.
thanks Brian!! this looks nice . hoping to have a closer look tomorrow
also interestingly, the likes of jellyfin and plex do filewatching too. i wonder do they have some trick up their sleeve to avoid the limits
Re: watch limits -- if someone with more directories starts the watcher they should see errors in the log but it will watch what it can. Then if they have root access they can increase the system limit.
just ran again locally and seems to work quite nice :+1:
i have some questions also
- when starting gonic for the first time, it seems to do a scan of the root dir straight away. it it meant to do that? could be annoying for users with big libraries. and it feels like it shouldn't since there wasn't any explicit event from the kernel
- are delete events supported? i did an
rm *
in my root dir and it didn't seem to pick it up. that's fine though i think. just wondering - perhaps we should debounce the events. eg if i have a folder outside my library like
and copy that into my gonic root dir likeartistname/ artistname/albumname/ artistname/albumname/track1.flac artistname/albumname/track2.flac
it picks up the artistname event straight away but never finds the album or tracks, since we haven't copied at the time of the first artistname/ event. have to do a manual scan. (at least for me in my testing)$ cp -r artistname gonicroot/
- also related to the deboucing, if we do
(which simulates some slower copies - maybe over a remote filesystem or whatever) we doing a lot of scans. which is maybe fine - but if one scan takes longer than it does to copy to files, we miss the second event. i think a debounce helps us here toofor track in somefiles/*.mp3; do cp "$track" gonicroot/someartist/some/album/ end
what do you think? IIRC syncthing for example does some debounce stuff
another QQ, could s.watchMap be replaced by s.watcher.WatchList() ?
also regarding the debounce, if you think it's a good idea, hugo do something similar here https://github.com/gohugoio/hugo/blob/master/watcher/batcher.go
(found from https://github.com/fsnotify/fsnotify/issues/401 )
Re: initial scan -- yes, that was deliberate to make sure the library was up to date as we set the watches, but I'm fine with omitting it if that's what you want. Re: deletion -- I explicitly did not handle deletion as I figured it would get handled in the periodic scan just fine. Re: whole tree copy in -- that should work. I will have a look. Are you sure you didn't hit your max watch limit? Because in that case you'd see exactly the symp[tom you report. Re: watchMap -- we need the mapping back to which music dir root each directory is in in order to pass to the scanCallback
Re: initial scan -- yes, that was deliberate to make sure the library was up to date as we set the watches, but I'm fine with omitting it if that's what you want.
yeah personally i think it would be good to not scan on startup, if that doesn't break anything
Re: deletion -- I explicitly did not handle deletion as I figured it would get handled in the periodic scan just fine.
:+1:
Re: whole tree copy in -- that should work. I will have a look. Are you sure you didn't hit your max watch limit? Because in that case you'd see exactly the symp[tom you report.
thanks, yes this is just testing on my laptop with just a few dirs
Re: watchMap -- we need the mapping back to which music dir root each directory is in in order to pass to the scanCallback
:+1:
ah now it has started working for the whole tree copy. though it produces a lot of event. i think if we debounce/batch (maybe something like the hugo example?) it help a lot. any maybe make sure we don't miss any files
for example: ("watching" message turned off)
https://user-images.githubusercontent.com/6832539/189992502-9cee5b5d-5312-4e90-bb2d-03ad6c93895e.mp4
We could go a couple of routes on the batching:
- Batch them all and just do a full scan when there's a change. Probably pretty wasteful.
- Batch and eliminate dup directories.
- Not bother batching and maybe reduce the logging on this thing so that it's not so noticeable.
I prefer 3 because of sloth :D but I'd be willing to take a stab at 2.
personally like 2
not only seems like a good thing but I think solves the problem I initially had when I first tested (whole tree copied, notified only about first event, no children to add watchers to yet, meaning no children found (though I could be way off on this))
wdyt?
very happy to help out on this if your time is limited
Let me see if I can get to it this week.
Ok check it out.
thanks brian! did some testing and seem to work very well. i just make scanList a map (seems like we can just incase we get duplicate events, then we don't try process them twice. does this make sense?) and removed the "watching folder" log message, since it's a lot with a big library
is this ok?
OK by me. Thanks!