* Y2K38 problem for linux in sysutils.findfirst/findnext should be solved

git-svn-id: trunk@48473 -
This commit is contained in:
florian 2021-01-31 18:02:55 +00:00
parent b8ab06aae7
commit d402e0b940

View File

@ -607,6 +607,36 @@ begin
end;
{$ifdef USE_STATX}
Function LinuxToWinAttr (const FN : RawByteString; Const Info : Statx) : Longint;
Var
LinkInfo : Stat;
nm : RawByteString;
begin
Result:=faArchive;
If fpS_ISDIR(Info.stx_mode) then
Result:=Result or faDirectory;
nm:=ExtractFileName(FN);
If (Length(nm)>=2) and
(nm[1]='.') and
(nm[2]<>'.') then
Result:=Result or faHidden;
If (Info.stx_Mode and S_IWUSR)=0 Then
Result:=Result or faReadOnly;
If fpS_ISSOCK(Info.stx_mode) or fpS_ISBLK(Info.stx_mode) or fpS_ISCHR(Info.stx_mode) or fpS_ISFIFO(Info.stx_mode) Then
Result:=Result or faSysFile;
If fpS_ISLNK(Info.stx_mode) Then
begin
Result:=Result or faSymLink;
// Windows reports if the link points to a directory.
{ as we are only interested in the st_mode field here, we do not need to use statx }
if (fpstat(pchar(FN),LinkInfo)>=0) and fpS_ISDIR(LinkInfo.st_mode) then
Result := Result or faDirectory;
end;
end;
{$endif USE_STATX}
function FileGetSymLinkTarget(const FileName: RawByteString; out SymLinkRec: TRawbyteSymLinkRec): Boolean;
var
Info : Stat;
@ -894,26 +924,54 @@ end;
Function FindGetFileInfo(const s: RawByteString; var f: TAbstractSearchRec; var Name: RawByteString):boolean;
Var
{$ifdef USE_STATX}
stx : linux.statx;
{$endif USE_STATX}
st : baseunix.stat;
WinAttr : longint;
begin
{$ifdef USE_STATX}
if Assigned(f.FindHandle) and ( (PUnixFindData(F.FindHandle)^.searchattr and faSymlink) > 0) then
FindGetFileInfo:=(fplstat(pointer(s),st)=0)
FindGetFileInfo:=Fpstatx(AT_FDCWD,pointer(s),AT_SYMLINK_NOFOLLOW,STATX_ALL,stx)=0
else
FindGetFileInfo:=(fpstat(pointer(s),st)=0);
if not FindGetFileInfo then
exit;
WinAttr:=LinuxToWinAttr(s,st);
FindGetFileInfo:=(WinAttr and Not(PUnixFindData(f.FindHandle)^.searchattr))=0;
FindGetFileInfo:=Fpstatx(AT_FDCWD,pointer(s),0,STATX_ALL,stx)=0;
if FindGetFileInfo then
begin
Name:=ExtractFileName(s);
f.Attr:=WinAttr;
f.Size:=st.st_Size;
f.Mode:=st.st_mode;
f.Time:=st.st_mtime;
FindGetFileInfo:=true;
WinAttr:=LinuxToWinAttr(s,stx);
FindGetFileInfo:=(WinAttr and Not(PUnixFindData(f.FindHandle)^.searchattr))=0;
if FindGetFileInfo then
begin
Name:=ExtractFileName(s);
f.Attr:=WinAttr;
f.Size:=stx.stx_Size;
f.Mode:=stx.stx_mode;
f.Time:=stx.stx_mtime.tv_sec;
FindGetFileInfo:=true;
end;
end
{ no statx? try stat }
else if fpgeterrno=ESysENOSYS then
{$endif USE_STATX}
begin
if Assigned(f.FindHandle) and ( (PUnixFindData(F.FindHandle)^.searchattr and faSymlink) > 0) then
FindGetFileInfo:=(fplstat(pointer(s),st)=0)
else
FindGetFileInfo:=(fpstat(pointer(s),st)=0);
if not FindGetFileInfo then
exit;
WinAttr:=LinuxToWinAttr(s,st);
FindGetFileInfo:=(WinAttr and Not(PUnixFindData(f.FindHandle)^.searchattr))=0;
if FindGetFileInfo then
begin
Name:=ExtractFileName(s);
f.Attr:=WinAttr;
f.Size:=st.st_Size;
f.Mode:=st.st_mode;
f.Time:=st.st_mtime;
FindGetFileInfo:=true;
end;
end;
end;