Recent

Author Topic: Directory-age?!?  (Read 289 times)

cdbc

  • Hero Member
  • *****
  • Posts: 1656
    • http://www.cdbc.dk
Directory-age?!?
« on: December 06, 2024, 04:49:06 pm »
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][+][-]
  1. program gda;  /// (g)et (d)irectory (a)ge ///
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   {$IFDEF UNIX}
  7.   cthreads, baseunix,
  8.   {$ENDIF}
  9.   Classes,sysutils;
  10.  
  11. function DirAge(const FileName : rawbytestring; out aStat: stat): ptrint;
  12. var
  13.   Info : baseunix.stat;
  14.   SystemFileName: RawByteString;
  15. begin
  16.   SystemFileName:= ToSingleByteFileSystemEncodedFileName(FileName);
  17.  
  18.   if  fpstat(PAnsiChar(SystemFileName),Info) < 0 then
  19.     exit(-1)
  20.   else
  21.     Result:= Info.st_mtime; /// we're mostly interested in 'modified'
  22.   aStat:= Info; /// record copy, but can't use pointer, 'cause info is local and goes outta scope
  23. end;
  24.  
  25. var
  26.   da: ptrint;
  27.   dn: string;
  28.   st: baseunix.stat;
  29.  
  30. begin
  31.   writeln('>> (g)et (d)irectory (a)ge <<');
  32.   writeln('(i) usage: gda <directory-name>');
  33.   if ParamCount < 1 then halt(1);
  34.   dn:= ParamStr(1);
  35.   da:= DirAge(dn,st);
  36.   writeln('>- - - -[ Info about "',dn,'" ]- - - -<');
  37.   writeln('(i) Dir-Mod: ',da,', as DateTime: ',DateTimeToStr(FileDateToDateTime(da)));
  38.   writeln('(i) Dir-Cre: ',st.st_ctime,', as DateTime: ',DateTimeToStr(FileDateToDateTime(st.st_ctime)));
  39.   writeln('(i) Dir-Acc: ',st.st_atime,', as DateTime: ',DateTimeToStr(FileDateToDateTime(st.st_atime)));
  40.   writeln('________________________________________');
  41. 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
« Last Edit: December 06, 2024, 04:52:05 pm by cdbc »
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

MarkMLl

  • Hero Member
  • *****
  • Posts: 8029
Re: Directory-age?!?
« Reply #1 on: December 06, 2024, 05:01:09 pm »
You need to use FAM. The details will vary a bit depending on OS but see for example the attached.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

cdbc

  • Hero Member
  • *****
  • Posts: 1656
    • http://www.cdbc.dk
Re: Directory-age?!?
« Reply #2 on: December 06, 2024, 05:12:02 pm »
Thanks Mark, will have a LookSee  :)
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

MarkMLl

  • Hero Member
  • *****
  • Posts: 8029
Re: Directory-age?!?
« Reply #3 on: December 06, 2024, 05:30:32 pm »
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
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

cdbc

  • Hero Member
  • *****
  • Posts: 1656
    • http://www.cdbc.dk
Re: Directory-age?!?
« Reply #4 on: December 06, 2024, 05:45:08 pm »
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
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

MarkMLl

  • Hero Member
  • *****
  • Posts: 8029
Re: Directory-age?!?
« Reply #5 on: December 06, 2024, 06:08:16 pm »
Yes, sounds about right.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

cdbc

  • Hero Member
  • *****
  • Posts: 1656
    • http://www.cdbc.dk
Re: Directory-age?!?
« Reply #6 on: December 06, 2024, 06:17:07 pm »
Hi
Thanks Mate  :)
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

MarkMLl

  • Hero Member
  • *****
  • Posts: 8029
Re: Directory-age?!?
« Reply #7 on: December 06, 2024, 06:40:04 pm »
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.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

 

TinyPortal © 2005-2018