Răsfoiți Sursa

* linux: make use of statx in Sysutils.FileAge if available

git-svn-id: trunk@48457 -
florian 4 ani în urmă
părinte
comite
f39f8d0f1a
3 a modificat fișierele cu 29 adăugiri și 0 ștergeri
  1. 1 0
      .gitattributes
  2. 18 0
      rtl/unix/sysutils.pp
  3. 10 0
      tests/test/units/sysutils/tfileage.pp

+ 1 - 0
.gitattributes

@@ -16245,6 +16245,7 @@ tests/test/units/sysutils/tfexpand2.pp svneol=native#text/plain
 tests/test/units/sysutils/tffirst.pp svneol=native#text/plain
 tests/test/units/sysutils/tffirst.pp svneol=native#text/plain
 tests/test/units/sysutils/tfile1.pp svneol=native#text/plain
 tests/test/units/sysutils/tfile1.pp svneol=native#text/plain
 tests/test/units/sysutils/tfile2.pp svneol=native#text/plain
 tests/test/units/sysutils/tfile2.pp svneol=native#text/plain
+tests/test/units/sysutils/tfileage.pp svneol=native#text/pascal
 tests/test/units/sysutils/tfilename.pp svneol=native#text/plain
 tests/test/units/sysutils/tfilename.pp svneol=native#text/plain
 tests/test/units/sysutils/tfloattostr.pp svneol=native#text/plain
 tests/test/units/sysutils/tfloattostr.pp svneol=native#text/plain
 tests/test/units/sysutils/tformat.pp svneol=native#text/plain
 tests/test/units/sysutils/tformat.pp svneol=native#text/plain

+ 18 - 0
rtl/unix/sysutils.pp

@@ -55,6 +55,10 @@ uses
 {$DEFINE HAVECLOCKGETTIME}
 {$DEFINE HAVECLOCKGETTIME}
 {$ENDIF}
 {$ENDIF}
 
 
+{$if defined(LINUX)}
+{$DEFINE HAS_STATX}
+{$endif}
+
 { Include platform independent interface part }
 { Include platform independent interface part }
 {$i sysutilh.inc}
 {$i sysutilh.inc}
 
 
@@ -547,12 +551,26 @@ begin
     end;
     end;
 end;
 end;
 
 
+
 Function FileAge (Const FileName : RawByteString): Int64;
 Function FileAge (Const FileName : RawByteString): Int64;
 Var
 Var
   Info : Stat;
   Info : Stat;
   SystemFileName: RawByteString;
   SystemFileName: RawByteString;
+{$ifdef HAS_STATX}
+  Infox : Statx;
+{$endif HAS_STATX}
 begin
 begin
   SystemFileName:=ToSingleByteFileSystemEncodedFileName(FileName);
   SystemFileName:=ToSingleByteFileSystemEncodedFileName(FileName);
+
+{$ifdef HAS_STATX}
+  { first try statx }
+  if (Fpstatx(0,pchar(SystemFileName),0,STATX_MTIME or STATX_MODE,Infox)>=0) and not(fpS_ISDIR(Infox.stx_mode)) then
+    begin
+      Result:=Infox.stx_mtime.tv_sec;
+      exit;
+    end;
+{$endif HAS_STATX}
+
   If  (fpstat(pchar(SystemFileName),Info)<0) or fpS_ISDIR(info.st_mode) then
   If  (fpstat(pchar(SystemFileName),Info)<0) or fpS_ISDIR(info.st_mode) then
     exit(-1)
     exit(-1)
   else 
   else 

+ 10 - 0
tests/test/units/sysutils/tfileage.pp

@@ -0,0 +1,10 @@
+uses
+  sysutils;
+begin
+  if 3600*24*(now()-FileDateToDateTime(FileAge(paramstr(0))))>7200 then
+    begin
+      writeln('FileAge returns: ',FileDateToDateTime(FileAge(paramstr(0))));
+      writeln('Compilation time and run time differ too much, SysUtils.FileAge buggy?');
+      halt(1);
+    end;
+end.