mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-30 11:10:31 +02:00
lcl: fix FileIsSymLink for win32 (although it is not possible to tell whether it is a symlink or a original file)
ide: formatting git-svn-id: trunk@25836 -
This commit is contained in:
parent
4b7f43a42a
commit
ef82b1fefd
@ -1370,39 +1370,36 @@ var
|
||||
OldInfo: Stat;
|
||||
{$ENDIF}
|
||||
begin
|
||||
Result:=false;
|
||||
Result := False;
|
||||
|
||||
// store file attributes
|
||||
{$IFdef MSWindows}
|
||||
OldAttr:=FileGetAttrUTF8(Filename);
|
||||
OldAttr := FileGetAttrUTF8(Filename);
|
||||
{$ELSE}
|
||||
FpStat(Filename,OldInfo);
|
||||
FpStat(Filename, OldInfo);
|
||||
{$ENDIF}
|
||||
|
||||
if not FileIsSymlink(Filename) then begin
|
||||
// not a symlink
|
||||
// rename old file, create empty new file
|
||||
|
||||
if not FileIsSymlink(Filename) then
|
||||
begin
|
||||
// not a symlink => rename old file, create empty new file
|
||||
// rename file
|
||||
if not RenameFileUTF8(Filename,BackupFilename) then exit;
|
||||
if not RenameFileUTF8(Filename, BackupFilename) then exit;
|
||||
// create empty file
|
||||
FHandle:=FileCreate(FileName);
|
||||
FHandle := FileCreate(FileName);
|
||||
FileClose(FHandle);
|
||||
end else begin
|
||||
// file is a symlink
|
||||
// -> copy file
|
||||
if not CopyFile(Filename,BackupFilename) then exit;
|
||||
end;
|
||||
|
||||
end
|
||||
else // file is a symlink -> copy file
|
||||
if not CopyFile(Filename, BackupFilename) then exit;
|
||||
|
||||
// restore file attributes
|
||||
{$IFdef MSWindows}
|
||||
FileSetAttrUTF8(FileName,OldAttr);
|
||||
FileSetAttrUTF8(FileName, OldAttr);
|
||||
{$ELSE}
|
||||
FpChmod(Filename, OldInfo.st_Mode and (STAT_IRWXO+STAT_IRWXG+STAT_IRWXU
|
||||
+STAT_ISUID+STAT_ISGID+STAT_ISVTX));
|
||||
{$ENDIF}
|
||||
|
||||
Result:=true;
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
{-------------------------------------------------------------------------------
|
||||
|
@ -813,11 +813,24 @@ end;
|
||||
function FileIsSymlink(const AFilename: string): boolean;
|
||||
------------------------------------------------------------------------------}
|
||||
function FileIsSymlink(const AFilename: string): boolean;
|
||||
{$IFDEF WINDOWS}
|
||||
var
|
||||
FileHandle: Integer;
|
||||
FileInfo: TBYHANDLEFILEINFORMATION;
|
||||
{$ENDIF}
|
||||
begin
|
||||
{$IFDEF WINDOWS}
|
||||
Result:=false;
|
||||
FileHandle := FileOpen(UTF8ToSys(AFileName), fmOpenRead or fmShareDenyNone);
|
||||
if FileHandle >= 0 then
|
||||
begin
|
||||
GetFileInformationByHandle(HFile(FileHandle), FileInfo);
|
||||
Result := FileInfo.nNumberOfLinks > 1;
|
||||
FileClose(FileHandle);
|
||||
end
|
||||
else
|
||||
Result := False;
|
||||
{$ELSE}
|
||||
Result:=(FpReadLink(AFilename)<>'');
|
||||
Result := FpReadLink(AFilename) <> '';
|
||||
{$ENDIF}
|
||||
end;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user