mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-20 11:09:42 +02:00
pastojs: more information when unable to write file
git-svn-id: trunk@38998 -
This commit is contained in:
parent
faca63449f
commit
4bc761193d
@ -21,10 +21,10 @@ unit Pas2jsCompiler;
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, AVL_Tree, contnrs,
|
||||
PScanner, PParser, PasTree, PasResolver, PasUseAnalyzer, PasResolveEval,
|
||||
jstree, jswriter, JSSrcMap, FPPas2Js, FPPJsSrcMap,
|
||||
Pas2jsFileUtils, Pas2jsLogger, Pas2jsFileCache, Pas2jsPParser, Pas2JsFiler;
|
||||
Classes, SysUtils, RtlConsts, AVL_Tree, contnrs, PScanner, PParser, PasTree,
|
||||
PasResolver, PasUseAnalyzer, PasResolveEval, jstree, jswriter, JSSrcMap,
|
||||
FPPas2Js, FPPJsSrcMap, Pas2jsFileUtils, Pas2jsLogger, Pas2jsFileCache,
|
||||
Pas2jsPParser, Pas2JsFiler;
|
||||
|
||||
const
|
||||
VersionMajor = 0;
|
||||
@ -2421,7 +2421,8 @@ begin
|
||||
end;
|
||||
except
|
||||
on E: Exception do begin
|
||||
Log.LogPlain('Error: '+E.Message);
|
||||
if E.Message<>SafeFormat(SFCreateError,[DestFileName]) then
|
||||
Log.LogPlain('Error: '+E.Message);
|
||||
Log.LogMsg(nUnableToWriteFile,[QuoteStr(FileCache.FormatPath(DestFilename))]);
|
||||
Terminate(ExitCodeWriteError);
|
||||
end;
|
||||
@ -2445,7 +2446,8 @@ begin
|
||||
end;
|
||||
except
|
||||
on E: Exception do begin
|
||||
Log.LogPlain('Error: '+E.Message);
|
||||
if E.Message<>SafeFormat(SFCreateError,[DestFileName]) then
|
||||
Log.LogPlain('Error: '+E.Message);
|
||||
Log.LogMsg(nUnableToWriteFile,[QuoteStr(FileCache.FormatPath(MapFilename))]);
|
||||
Terminate(ExitCodeWriteError);
|
||||
end;
|
||||
@ -3624,7 +3626,7 @@ begin
|
||||
r(mtDebug,nHandlingOption,sHandlingOption);
|
||||
r(mtDebug,nQuickHandlingOption,sQuickHandlingOption);
|
||||
r(mtFatal,nOutputDirectoryNotFound,sOutputDirectoryNotFound);
|
||||
r(mtInfo,nUnableToWriteFile,sUnableToWriteFile);
|
||||
r(mtError,nUnableToWriteFile,sUnableToWriteFile);
|
||||
r(mtInfo,nWritingFile,sWritingFile);
|
||||
r(mtFatal,nCompilationAborted,sCompilationAborted);
|
||||
r(mtDebug,nCfgDirective,sCfgDirective);
|
||||
|
@ -2081,6 +2081,7 @@ procedure TPas2jsFilesCache.SaveToFile(ms: TMemoryStream; Filename: string);
|
||||
var
|
||||
s: string;
|
||||
l: Int64;
|
||||
i: Integer;
|
||||
begin
|
||||
if Assigned(OnWriteFile) then
|
||||
begin
|
||||
@ -2095,7 +2096,20 @@ begin
|
||||
OnWriteFile(Filename,s);
|
||||
end else
|
||||
begin
|
||||
ms.SaveToFile(Filename);
|
||||
try
|
||||
ms.SaveToFile(Filename);
|
||||
except
|
||||
on E: Exception do begin
|
||||
i:=GetLastOSError;
|
||||
if i<>0 then
|
||||
Log.LogPlain('Note: '+SysErrorMessage(i));
|
||||
if not SysUtils.DirectoryExists(ChompPathDelim(ExtractFilePath(Filename))) then
|
||||
Log.LogPlain('Note: file cache inconsistency: folder does not exist "'+ChompPathDelim(ExtractFilePath(Filename))+'"');
|
||||
if SysUtils.FileExists(Filename) and not FileIsWritable(Filename) then
|
||||
Log.LogPlain('Note: file is not writable "'+Filename+'"');
|
||||
raise;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
@ -51,6 +51,7 @@ function GetPhysicalFilename(const Filename: string;
|
||||
function ResolveSymLinks(const Filename: string;
|
||||
{%H-}ExceptionOnError: boolean): string; // if a link is broken returns ''
|
||||
function MatchGlobbing(Mask, Name: string): boolean;
|
||||
function FileIsWritable(const AFilename: string): boolean;
|
||||
|
||||
function GetEnvironmentVariableCountUTF8: Integer;
|
||||
function GetEnvironmentStringUTF8(Index: Integer): string;
|
||||
|
@ -143,6 +143,11 @@ begin
|
||||
Result:='';
|
||||
end;
|
||||
|
||||
function FileIsWritable(const AFilename: string): boolean;
|
||||
begin
|
||||
Result := BaseUnix.FpAccess(AFilename, BaseUnix.W_OK) = 0;
|
||||
end;
|
||||
|
||||
function GetEnvironmentVariableCountUTF8: Integer;
|
||||
begin
|
||||
Result:=GetEnvironmentVariableCount;
|
||||
|
@ -411,6 +411,16 @@ begin
|
||||
Result:=Filename;
|
||||
end;
|
||||
|
||||
function FileGetAttrUTF8(const FileName: String): Longint;
|
||||
begin
|
||||
Result:=Integer(Windows.GetFileAttributesW(PWideChar(UTF8Decode(FileName))));
|
||||
end;
|
||||
|
||||
function FileIsWritable(const AFilename: string): boolean;
|
||||
begin
|
||||
Result:=((FileGetAttrUTF8(AFilename) and faReadOnly) = 0);
|
||||
end;
|
||||
|
||||
function GetEnvironmentVariableCountUTF8: Integer;
|
||||
var
|
||||
hp,p : PWideChar;
|
||||
|
Loading…
Reference in New Issue
Block a user