Forum > Linux

Directory-age?!?

(1/2) > >>

cdbc:
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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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 <directory-name>');  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...  :D
Regards Benny
edit: typo

MarkMLl:
You need to use FAM. The details will vary a bit depending on OS but see for example the attached.

MarkMLl

cdbc:
Thanks Mark, will have a LookSee  :)
Regards Benny

MarkMLl:
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:
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  :D 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

Navigation

[0] Message Index

[#] Next page

Go to full version