Directory-age?!? lazarus / 32-Linux ---------------------------------------------------------------------- cdbc · 2024-12-06 15:49 Hi In my 'PluginMgr', I'm trying to detect changes in the "plugin- directory", i.e.: if someone added a new plugin... If my manager is running in mode 'ActiveOnly', it learns what plugins are actually used and loads only them, cutting the load-times to ~1/10 But I'd like it to automagically detect /new-arrivals/ and reset 'active-cache' and load all plugins to let the user use the new plugin ...and then start learning anew... So I'm fiddling with code like this, to ascertain if the directory has been modified:Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program gda;  /// (g)et (d)irectory (a)ge /// {$mode objfpc}{$H+} uses  {$IFDEF UNIX}  cthreads, baseunix,  {$ENDIF}  Classes,sysutils; function DirAge(const FileName : rawbytestring; out aStat: stat): ptrint;var  Info : baseunix.stat;  SystemFileName: RawByteString;begin  SystemFileName:= ToSingleByteFileSystemEncodedFileName(FileName);   if  fpstat(PAnsiChar(SystemFileName),Info) < 0 then    exit(-1)  else    Result:= Info.st_mtime; /// we're mostly interested in 'modified'  aStat:= Info; /// record copy, but can't use pointer, 'cause info is local and goes outta scopeend; var  da: ptrint;  dn: string;  st: baseunix.stat; begin  writeln('>> (g)et (d)irectory (a)ge <<');  writeln('(i) usage: gda ');  if ParamCount < 1 then halt(1);  dn:= ParamStr(1);  da:= DirAge(dn,st);  writeln('>- - - -[ Info about "',dn,'" ]- - - -<');  writeln('(i) Dir-Mod: ',da,', as DateTime: ',DateTimeToStr(FileDateToDateTime(da)));  writeln('(i) Dir- Cre: ',st.st_ctime,', as DateTime: ',DateTimeToStr(FileDateToDateTime(st.st_ctime)));  writeln('(i) Dir- Acc: ',st.st_atime,', as DateTime: ',DateTimeToStr(FileDateToDateTime(st.st_atime)));  writeln('________________________________________');end.  'DirAge' is a modified version of 'FileAge' in the RTL and I'm wondering if there are some snags ahead that I can't foresee, since it's not in the RTL?!? I'll be happy for any input...  Regards Benny edit: typo ---------------------------------------------------------------------- MarkMLl · 2024-12-06 16:01 You need to use FAM. The details will vary a bit depending on OS but see for example the attached. MarkMLl ---------------------------------------------------------------------- cdbc · 2024-12-06 16:12 Thanks Mark, will have a LookSee  Regards Benny ---------------------------------------------------------------------- MarkMLl · 2024-12-06 16:30 Look at the handful of functions near the end. That's from a program that listens for the output from a logic analyzer in various forms, and disassembles it. So I'm fairly confident that it gets tricky things like the precise format of paths right. MarkMLl ---------------------------------------------------------------------- cdbc · 2024-12-06 16:45 Hi Cool code Mark, thanks. So, inotify is a kernel-thingy, where you can get a /watched/ handle to the object in question, got it. I have to poll this handle regularly to get a heads up on said object. ...and I guess 'fpClose(handle);' when I'm done, to release inotify- resources. Am I right in thinking polling -> Thread? It so happens, I've got this sleeping thread, that I can utilize whenever I want  It's actually used to load plugins on app-startup and I just kept it around just in case... Am I understanding this correctly?!?  Regards Benny ---------------------------------------------------------------------- MarkMLl · 2024-12-06 17:08 Yes, sounds about right. MarkMLl ---------------------------------------------------------------------- cdbc · 2024-12-06 17:17 Hi Thanks Mate  Regards Benny ---------------------------------------------------------------------- MarkMLl · 2024-12-06 17:40 I find I've used that stuff in a couple more places, but not- interestingly- in the program I was tweaking a few weeks ago which reads the content of a DSO (digital 'scope) and can reload the backend dynamic library if it's recompiled. Updated: I've grafted it into the DSO program so that it re-reads the directory containing the backends (each of which has the ISO date and time in its name) only when something's actually changed. The API doesn't, unfortunately, allow wildcards, but the more difficult part of the exercise was working out the structure of my original code (a reload can be triggered by a number of things, including HUP etc.). MarkMLl