mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-12 11:56:45 +02:00
ide: improve BackupFile routing:
- Check if file is Locked. If it is so then use CopyFile instead of RenameFile since RenameFiles leaves lock on backup file on windows. - If RenameFile is failed for some reason then use CopyFile. git-svn-id: trunk@25859 -
This commit is contained in:
parent
1f9a50c44a
commit
f6de16c477
@ -1362,6 +1362,24 @@ end;
|
||||
file attributes
|
||||
-------------------------------------------------------------------------------}
|
||||
function BackupFile(const Filename, BackupFilename: string): boolean;
|
||||
|
||||
function FileIsLocked(const FileName: String): Boolean;
|
||||
{$ifdef Windows}
|
||||
var
|
||||
FHandle: THandle;
|
||||
{$endif}
|
||||
begin
|
||||
{$ifdef Windows}
|
||||
// try to open with all denies
|
||||
FHandle := FileOpen(UTF8ToSys(FileName), fmOpenRead or fmShareDenyRead or fmShareDenyWrite);
|
||||
Result := FHandle = feInvalidHandle;
|
||||
if not Result then
|
||||
FileClose(FHandle);
|
||||
{$else}
|
||||
Result := False;
|
||||
{$endif}
|
||||
end;
|
||||
|
||||
var
|
||||
FHandle: THandle;
|
||||
{$IFdef MSWindows}
|
||||
@ -1379,16 +1397,16 @@ begin
|
||||
FpStat(Filename, OldInfo);
|
||||
{$ENDIF}
|
||||
|
||||
if not FileIsSymlink(Filename) then
|
||||
// if not a symlink => rename old file, create empty new file
|
||||
if not FileIsSymlink(Filename) and
|
||||
not FileIsLocked(Filename) and
|
||||
RenameFileUTF8(Filename, BackupFilename) then
|
||||
begin
|
||||
// not a symlink => rename old file, create empty new file
|
||||
// rename file
|
||||
if not RenameFileUTF8(Filename, BackupFilename) then exit;
|
||||
// create empty file
|
||||
FHandle := FileCreate(FileName);
|
||||
FHandle := FileCreate(UTF8ToSys(FileName));
|
||||
FileClose(FHandle);
|
||||
end
|
||||
else // file is a symlink -> copy file
|
||||
else // file is a symlink or rename failed => copy file
|
||||
if not CopyFile(Filename, BackupFilename) then exit;
|
||||
|
||||
// restore file attributes
|
||||
|
Loading…
Reference in New Issue
Block a user