IDE: Optimise the logic for symlinked files. Issue #32292.

git-svn-id: trunk@55994 -
This commit is contained in:
juha 2017-10-07 13:37:01 +00:00
parent 832ce1039a
commit fd4150950b

View File

@ -339,7 +339,6 @@ function SourceFileMgr: TLazSourceFileManager;
function CreateSrcEditPageName(const AnUnitName, AFilename: string; function CreateSrcEditPageName(const AnUnitName, AFilename: string;
IgnoreEditor: TSourceEditor): string; IgnoreEditor: TSourceEditor): string;
procedure UpdateDefaultPasFileExt; procedure UpdateDefaultPasFileExt;
function SplitSrcPath(const ASearchPath, ACurrentDir: string): string;
// Wrappers for TFileOpener methods. // Wrappers for TFileOpener methods.
// WindowIndex is WindowID // WindowIndex is WindowID
@ -390,9 +389,8 @@ begin
LazProjectFileDescriptors.DefaultPascalFileExt:=DefPasExt; LazProjectFileDescriptors.DefaultPascalFileExt:=DefPasExt;
end; end;
function SplitSrcPath(const ASearchPath, ACurrentDir: string): string; function UseCurrentDirInSrcPath(const ASearchPath, ACurrentDir: string): string;
// Splits a ";" separated list of search paths into a TStringList. // Replace path "." with ACurrentDir in a ";" separated list of search paths.
// Replace path "." with ACurrentDir.
var var
p: Integer; p: Integer;
Dir: String; Dir: String;
@ -1217,30 +1215,27 @@ end;
function TFileOpener.ResolvePossibleSymlink: TModalResult; function TFileOpener.ResolvePossibleSymlink: TModalResult;
// Check if symlink and ask user if the real file should be opened instead. // Check if symlink and ask user if the real file should be opened instead.
// Note that compiler never resolves symlinks, so files in the compiler // Compiler never resolves symlinks, files in compiler search path must not be resolved.
// search path must not be resolved. // If there already is an editor with a "physical" target of a symlink, use it.
var var
Path, Target: String; // Search path and target file for the symlink. SPath, Target: String; // Search path and target file for the symlink.
begin begin
Result := mrOK; Result := mrOK;
Assert(FileExistsCached(FFilename),'TFileOpener.ResolveSymlink: '+FFilename+' does not exist.'); Assert(FileExistsCached(FFilename),'TFileOpener.ResolveSymlink: '+FFilename+' does not exist.');
// Include absolute Project1.Directory in the search path.
Path := SplitSrcPath(CodeToolBoss.GetCompleteSrcPathForDirectory(''), Project1.Directory);
if (SearchDirectoryInSearchPath(Path, ExtractFilePath(FFileName)) > 0)
or Assigned(SourceEditorManager.SourceEditorIntfWithFilename(FFileName))
then // FileName found in search path or in editor -> all good.
Exit;
// File is not in project search path nor open in editor => check for a symlink.
Target := GetPhysicalFilenameCached(FFileName,false); Target := GetPhysicalFilenameCached(FFileName,false);
if Target <> FFilename then if Target = FFilename then Exit; // Not a symlink, continue with FFilename.
begin // A symlink // ToDo: Check if there is an editor with a symlink for this "physical" file.
if (SearchDirectoryInSearchPath(Path, ExtractFilePath(Target)) > 0)
or Assigned(SourceEditorManager.SourceEditorIntfWithFilename(Target)) // Include absolute Project1.Directory in the search path.
then // Target found in search path or in editor -> use Target name. SPath := UseCurrentDirInSrcPath(CodeToolBoss.GetCompleteSrcPathForDirectory(''),
FFileName := Target Project1.Directory);
else // Neither filename nor target was found anywhere, ask user. // Check if "physical" target for a symlink is found in search path or in editor.
Result := ChooseSymlink(FFileName, Target); if (SearchDirectoryInSearchPath(SPath, ExtractFilePath(Target)) > 0)
end; or Assigned(SourceEditorManager.SourceEditorIntfWithFilename(Target))
then // Target found -> use Target name.
FFileName := Target
else // Not found anywhere, ask user.
Result := ChooseSymlink(FFileName, Target);
end; end;
function TFileOpener.OpenEditorFile(APageIndex, AWindowIndex: integer; function TFileOpener.OpenEditorFile(APageIndex, AWindowIndex: integer;