IDE: using PathIsInPath instead of FileIsInPath where path=path is allowed

git-svn-id: trunk@61635 -
This commit is contained in:
mattias 2019-07-28 07:36:10 +00:00
parent 5ad5b4600d
commit 05e011f162
4 changed files with 30 additions and 17 deletions

View File

@ -2740,8 +2740,7 @@ begin
CurLazDir:=ChompPathDelim(LazarusDirectory);
if not TTransferMacroList.StrHasMacros(CurLazDir) then begin
BaseDir:=ExtractFilePath(ChompPathDelim(GetPrimaryConfigPath));
if (CompareFilenames(BaseDir,CurLazDir)=0)
or FileIsInPath(CurLazDir,BaseDir) then begin
if PathIsInPath(CurLazDir,BaseDir) then begin
// the pcp directory is in the lazarus directory
// or the lazarus directory is a sibling or a sub dir of a sibling of the pcp
// examples:

View File

@ -61,6 +61,7 @@ function CreateEmptyFile(const Filename: string): boolean;
function FilenameIsPascalSource(const Filename: string): boolean;
function ChompEndNumber(const s: string): string;
function ShortDisplayFilename(const aFileName: string): string;
function PathIsInPath(const Path, Directory: string): boolean;
// find file
function FindFilesCaseInsensitive(const Directory,
@ -516,10 +517,7 @@ function GetNextUsedDirectoryInSearchPath(const SearchPath,
begin
while (NextStartPos<=length(SearchPath)) do begin
Result:=GetNextDirectoryInSearchPath(SearchPath,NextStartPos);
if (Result<>'')
and ((CompareFilenames(Result,FilterDir)=0)
or FileIsInPath(Result,FilterDir))
then
if (Result<>'') and PathIsInPath(Result,FilterDir) then
exit;
end;
Result:=''
@ -750,6 +748,20 @@ begin
Result := aFileName;
end;
function PathIsInPath(const Path, Directory: string): boolean;
var
ExpPath: String;
ExpDir: String;
l: integer;
begin
if Path='' then exit(false);
ExpPath:=ResolveDots(Path);
ExpDir:=AppendPathDelim(ResolveDots(Directory));
l:=length(ExpDir);
Result:=(l>0) and (length(ExpPath)>=l) and (ExpPath[l]=PathDelim)
and (CompareFilenames(ExpDir,LeftStr(ExpPath,l))=0);
end;
function FindFirstFileWithExt(const Directory, Ext: string): string;
var
FileInfo: TSearchRec;

View File

@ -1411,7 +1411,7 @@ begin
and (CheckFPCExeQuality(EnvironmentOptions.GetParsedCompilerFilename,Note,
CodeToolBoss.CompilerDefinesCache.TestFilename)=sddqInvalid)
then begin
debugln(['Warning: (lazarus) invalid compiler: ',EnvironmentOptions.GetParsedCompilerFilename]);
debugln(['Warning: (lazarus) invalid compiler: ',EnvironmentOptions.GetParsedCompilerFilename,' ',Note]);
ShowSetupDialog:=true;
end;
@ -1423,7 +1423,7 @@ begin
if CheckFPCSrcDirQuality(EnvironmentOptions.GetParsedFPCSourceDirectory,Note,
CfgCache.GetFPCVer)=sddqInvalid
then begin
debugln(['Warning: (lazarus) invalid fpc source directory: ',EnvironmentOptions.GetParsedFPCSourceDirectory]);
debugln(['Warning: (lazarus) invalid fpc source directory: ',EnvironmentOptions.GetParsedFPCSourceDirectory,' ',Note]);
ShowSetupDialog:=true;
end;
end;
@ -1434,6 +1434,7 @@ begin
RegisterDebugger(TGDBMIDebugger); // make sure we can read the config
// Todo: add LldbFpDebugger for Mac
// If the default debugger is of a class that is not yet Registered, then the dialog is not shown
Note:='';
if ( (EnvironmentOptions.CurrentDebuggerPropertiesConfig = nil) and // no debugger at all
(not EnvironmentOptions.HasActiveDebuggerEntry) ) // not even with unknown class
or ( (EnvironmentOptions.CurrentDebuggerClass <> nil) // Debugger with known class
@ -1441,7 +1442,7 @@ begin
and (CheckDebuggerQuality(EnvironmentOptions.GetParsedDebuggerFilename, Note)<>sddqCompatible)
)
then begin
debugln(['Warning: (lazarus) missing GDB exe',EnvironmentOptions.GetParsedLazarusDirectory]);
debugln(['Warning: (lazarus) missing GDB exe ',EnvironmentOptions.GetParsedLazarusDirectory,' ',Note]);
ShowSetupDialog:=true;
end;
end;
@ -7023,7 +7024,7 @@ begin
UnitOutputDirectory:=TrimFilename(WorkingDir+PathDelim+UnitOutputDirectory);
if FilenameIsAbsolute(UnitOutputDirectory) then begin
if (not DirPathExistsCached(UnitOutputDirectory)) then begin
if not FileIsInPath(UnitOutputDirectory,WorkingDir) then begin
if not PathIsInPath(UnitOutputDirectory,WorkingDir) then begin
Result:=IDEQuestionDialog(lisCreateDirectory,
Format(lisTheOutputDirectoryIsMissing, [UnitOutputDirectory]),
mtConfirmation, [mrYes, lisCreateIt,
@ -7037,7 +7038,8 @@ begin
end;
end;
if Project1.IsVirtual
and (FileIsInPath(UnitOutputDirectory,EnvironmentOptions.GetParsedTestBuildDirectory))
and (PathIsInPath(UnitOutputDirectory,
EnvironmentOptions.GetParsedTestBuildDirectory))
then begin
// clean up test units
Result:=CleanUpTestUnitOutputDir(UnitOutputDirectory);
@ -7059,7 +7061,7 @@ begin
if Result<>mrIgnore then exit(mrCancel);
end;
end else begin
if not FileIsInPath(AppendPathDelim(TargetExeDirectory)+'dummy',WorkingDir)
if not PathIsInPath(TargetExeDirectory,WorkingDir)
then begin
Result:=IDEQuestionDialog(lisCreateDirectory,
Format(lisTheOutputDirectoryIsMissing, [TargetExeDirectory]),
@ -12011,12 +12013,12 @@ begin
SaveDialog.FileName:=SaveAsFilename;
// if this is a project file, start in project directory
if AnUnitInfo.IsPartOfProject and (not Project1.IsVirtual)
and (not FileIsInPath(SaveDialog.InitialDir,Project1.Directory)) then
and (not PathIsInPath(SaveDialog.InitialDir,Project1.Directory)) then
SaveDialog.InitialDir:=Project1.Directory;
// if this is a package file, then start in package directory
PkgDefaultDirectory:=PkgBoss.GetDefaultSaveDirectoryForFile(AnUnitInfo.Filename);
if (PkgDefaultDirectory<>'')
and (not FileIsInPath(SaveDialog.InitialDir,PkgDefaultDirectory)) then
and (not PathIsInPath(SaveDialog.InitialDir,PkgDefaultDirectory)) then
SaveDialog.InitialDir:=PkgDefaultDirectory;
// show save dialog
if (not SaveDialog.Execute) or (ExtractFileName(SaveDialog.Filename)='') then

View File

@ -4606,13 +4606,13 @@ begin
// if this is a project file, start in project directory
if (AnUnitInfo=nil)
or (AnUnitInfo.IsPartOfProject and (not Project1.IsVirtual)
and (not FileIsInPath(SaveDialog.InitialDir,Project1.Directory)))
and (not PathIsInPath(SaveDialog.InitialDir,Project1.Directory)))
then begin
SaveDialog.InitialDir:=Project1.Directory;
end;
// if this is a package file, then start in package directory
APath:=PkgBoss.GetDefaultSaveDirectoryForFile(AFilename);
if (APath<>'') and (not FileIsInPath(SaveDialog.InitialDir,APath)) then
if (APath<>'') and (not PathIsInPath(SaveDialog.InitialDir,APath)) then
SaveDialog.InitialDir:=APath;
repeat
@ -5387,7 +5387,7 @@ begin
OldLRSFilePath:=ExtractFilePath(LRSCode.Filename);
NewLRSFilePath:=OldLRSFilePath;
if FilenameIsAbsolute(OldFilePath)
and FileIsInPath(OldLRSFilePath,OldFilePath) then begin
and PathIsInPath(OldLRSFilePath,OldFilePath) then begin
// resource code was in the same or in a sub directory of source
// -> try to keep this relationship
NewLRSFilePath:=NewFilePath