mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-16 02:39:15 +02:00
codetools: fixed TCodeBuffer.FileOnDiskNeedsUpdate/FileOnDiskIsEqual for virtual and created files
git-svn-id: trunk@35942 -
This commit is contained in:
parent
512d8e4f1c
commit
213f110c4c
@ -86,7 +86,7 @@ type
|
|||||||
function SaveToFile(const AFilename: string): boolean; override;
|
function SaveToFile(const AFilename: string): boolean; override;
|
||||||
function Save: boolean;
|
function Save: boolean;
|
||||||
function FileDateOnDisk: longint;
|
function FileDateOnDisk: longint;
|
||||||
function FileNeedsUpdate: boolean;
|
function FileNeedsUpdate: boolean; // needs loading
|
||||||
function FileOnDiskNeedsUpdate: boolean;
|
function FileOnDiskNeedsUpdate: boolean;
|
||||||
function FileOnDiskHasChanged: boolean;
|
function FileOnDiskHasChanged: boolean;
|
||||||
function FileOnDiskIsEqual: boolean;
|
function FileOnDiskIsEqual: boolean;
|
||||||
@ -108,6 +108,7 @@ type
|
|||||||
write FLastIncludedByFile;
|
write FLastIncludedByFile;
|
||||||
property LoadDate: longint read FLoadDate;
|
property LoadDate: longint read FLoadDate;
|
||||||
property LoadDateValid: boolean read FLoadDateValid;
|
property LoadDateValid: boolean read FLoadDateValid;
|
||||||
|
property FileChangeStep: integer read FFileChangeStep; // last loaded/saved changestep, only valid if LoadDateValid=true
|
||||||
property OnSetFilename: TNotifyEvent read FOnSetFilename write FOnSetFilename;
|
property OnSetFilename: TNotifyEvent read FOnSetFilename write FOnSetFilename;
|
||||||
property OnSetScanner: TNotifyEvent read FOnSetScanner write FOnSetScanner;
|
property OnSetScanner: TNotifyEvent read FOnSetScanner write FOnSetScanner;
|
||||||
property Scanner: TLinkScanner read FScanner write SetScanner;
|
property Scanner: TLinkScanner read FScanner write SetScanner;
|
||||||
@ -1451,16 +1452,17 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
function TCodeBuffer.FileOnDiskNeedsUpdate: boolean;
|
function TCodeBuffer.FileOnDiskNeedsUpdate: boolean;
|
||||||
// file on disk needs update (to be saved), if memory is modified or file does not exist
|
// file on disk needs update (= file needs to be saved), if memory is modified or file does not exist
|
||||||
begin
|
begin
|
||||||
if LoadDateValid then
|
if IsVirtual or IsDeleted then exit(false);
|
||||||
Result:=Modified or (FFileChangeStep<>ChangeStep)
|
Result:=Modified
|
||||||
or (not FileExistsCached(Filename))
|
or (not LoadDateValid) // file was created in memory, but not yet saved to disk
|
||||||
else
|
or (FFileChangeStep<>ChangeStep) // file was modified since last load/save
|
||||||
Result:=false;
|
or (not FileExistsCached(Filename));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCodeBuffer.FileOnDiskHasChanged: boolean;
|
function TCodeBuffer.FileOnDiskHasChanged: boolean;
|
||||||
|
// file on disk has changed since last load/save
|
||||||
begin
|
begin
|
||||||
if LoadDateValid and FileExistsCached(Filename) then
|
if LoadDateValid and FileExistsCached(Filename) then
|
||||||
Result:=(FileDateOnDisk<>LoadDate)
|
Result:=(FileDateOnDisk<>LoadDate)
|
||||||
@ -1470,7 +1472,17 @@ end;
|
|||||||
|
|
||||||
function TCodeBuffer.FileOnDiskIsEqual: boolean;
|
function TCodeBuffer.FileOnDiskIsEqual: boolean;
|
||||||
begin
|
begin
|
||||||
Result:=(not FileOnDiskNeedsUpdate) and (not FileOnDiskHasChanged);
|
if IsVirtual then
|
||||||
|
exit(true);
|
||||||
|
if IsDeleted then
|
||||||
|
exit(not FileExistsCached(Filename));
|
||||||
|
if (not LoadDateValid)
|
||||||
|
or Modified or (FFileChangeStep<>ChangeStep)
|
||||||
|
or (not FileExistsCached(Filename))
|
||||||
|
or (FileDateOnDisk<>LoadDate)
|
||||||
|
then
|
||||||
|
exit(false);
|
||||||
|
Result:=true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCodeBuffer.AutoRevertFromDisk: boolean;
|
function TCodeBuffer.AutoRevertFromDisk: boolean;
|
||||||
|
@ -448,8 +448,8 @@ begin
|
|||||||
Laz2_XMLWrite.WriteXMLFile(ADoc, ms, WriteFlags);
|
Laz2_XMLWrite.WriteXMLFile(ADoc, ms, WriteFlags);
|
||||||
ms.Position:=0;
|
ms.Position:=0;
|
||||||
Buf.LoadFromStream(ms);
|
Buf.LoadFromStream(ms);
|
||||||
if not Buf.FileOnDiskNeedsUpdate then exit;
|
if Buf.FileOnDiskIsEqual then exit;
|
||||||
//debugln(['TCodeBufXMLConfig.WriteXMLFile ',AFileName]);
|
//debugln(['TCodeBufXMLConfig.WriteXMLFile writing ',AFileName,' ...']);
|
||||||
if Buf.Save then exit; // success
|
if Buf.Save then exit; // success
|
||||||
finally
|
finally
|
||||||
ms.Free;
|
ms.Free;
|
||||||
|
Loading…
Reference in New Issue
Block a user