IDE: when compiling a package in a readonly, check parent directories

This commit is contained in:
mattias 2023-06-21 17:59:54 +02:00
parent fa2114cc78
commit 28eccc250c

View File

@ -1051,14 +1051,27 @@ end;
function TLazPackageGraph.OutputDirectoryIsWritable(APackage: TLazPackage;
Directory: string; Verbose: boolean): boolean;
var
CurDir: String;
begin
Result:=false;
//debugln(['TLazPackageGraph.OutputDirectoryIsWritable ',Directory]);
if not FilenameIsAbsolute(Directory) then
exit;
Directory:=ChompPathDelim(Directory);
if not DirPathExistsCached(Directory) then begin
// the directory does not exist => try creating it
if DirPathExistsCached(Directory) then begin
// the directory exist => check writable
Result:=DirectoryIsWritableCached(Directory);
exit;
end;
// the directory does not exist => check parent directory for writable
CurDir:=Directory;
repeat
CurDir:=ChompPathDelim(ExtractFilePath(CurDir));
until (CurDir='') or (CurDir=Directory) or DirPathExistsCached(CurDir);
if not DirectoryIsWritableCached(CurDir) then
exit(false);
// the directory does not exist, and its parent is writable => try creating it
if not ForceDirectoriesUTF8(Directory) then begin
if Verbose then begin
IDEMessageDialog(lisPkgMangUnableToCreateDirectory,
@ -1070,8 +1083,6 @@ begin
exit;
end;
Result:=true;
end else
Result:=DirectoryIsWritableCached(Directory);
end;
function TLazPackageGraph.GetPackageCompilerParams(APackage: TLazPackage