mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-18 17:09:16 +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
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, AVL_Tree, contnrs,
|
Classes, SysUtils, RtlConsts, AVL_Tree, contnrs, PScanner, PParser, PasTree,
|
||||||
PScanner, PParser, PasTree, PasResolver, PasUseAnalyzer, PasResolveEval,
|
PasResolver, PasUseAnalyzer, PasResolveEval, jstree, jswriter, JSSrcMap,
|
||||||
jstree, jswriter, JSSrcMap, FPPas2Js, FPPJsSrcMap,
|
FPPas2Js, FPPJsSrcMap, Pas2jsFileUtils, Pas2jsLogger, Pas2jsFileCache,
|
||||||
Pas2jsFileUtils, Pas2jsLogger, Pas2jsFileCache, Pas2jsPParser, Pas2JsFiler;
|
Pas2jsPParser, Pas2JsFiler;
|
||||||
|
|
||||||
const
|
const
|
||||||
VersionMajor = 0;
|
VersionMajor = 0;
|
||||||
@ -2421,6 +2421,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
except
|
except
|
||||||
on E: Exception do begin
|
on E: Exception do begin
|
||||||
|
if E.Message<>SafeFormat(SFCreateError,[DestFileName]) then
|
||||||
Log.LogPlain('Error: '+E.Message);
|
Log.LogPlain('Error: '+E.Message);
|
||||||
Log.LogMsg(nUnableToWriteFile,[QuoteStr(FileCache.FormatPath(DestFilename))]);
|
Log.LogMsg(nUnableToWriteFile,[QuoteStr(FileCache.FormatPath(DestFilename))]);
|
||||||
Terminate(ExitCodeWriteError);
|
Terminate(ExitCodeWriteError);
|
||||||
@ -2445,6 +2446,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
except
|
except
|
||||||
on E: Exception do begin
|
on E: Exception do begin
|
||||||
|
if E.Message<>SafeFormat(SFCreateError,[DestFileName]) then
|
||||||
Log.LogPlain('Error: '+E.Message);
|
Log.LogPlain('Error: '+E.Message);
|
||||||
Log.LogMsg(nUnableToWriteFile,[QuoteStr(FileCache.FormatPath(MapFilename))]);
|
Log.LogMsg(nUnableToWriteFile,[QuoteStr(FileCache.FormatPath(MapFilename))]);
|
||||||
Terminate(ExitCodeWriteError);
|
Terminate(ExitCodeWriteError);
|
||||||
@ -3624,7 +3626,7 @@ begin
|
|||||||
r(mtDebug,nHandlingOption,sHandlingOption);
|
r(mtDebug,nHandlingOption,sHandlingOption);
|
||||||
r(mtDebug,nQuickHandlingOption,sQuickHandlingOption);
|
r(mtDebug,nQuickHandlingOption,sQuickHandlingOption);
|
||||||
r(mtFatal,nOutputDirectoryNotFound,sOutputDirectoryNotFound);
|
r(mtFatal,nOutputDirectoryNotFound,sOutputDirectoryNotFound);
|
||||||
r(mtInfo,nUnableToWriteFile,sUnableToWriteFile);
|
r(mtError,nUnableToWriteFile,sUnableToWriteFile);
|
||||||
r(mtInfo,nWritingFile,sWritingFile);
|
r(mtInfo,nWritingFile,sWritingFile);
|
||||||
r(mtFatal,nCompilationAborted,sCompilationAborted);
|
r(mtFatal,nCompilationAborted,sCompilationAborted);
|
||||||
r(mtDebug,nCfgDirective,sCfgDirective);
|
r(mtDebug,nCfgDirective,sCfgDirective);
|
||||||
|
@ -2081,6 +2081,7 @@ procedure TPas2jsFilesCache.SaveToFile(ms: TMemoryStream; Filename: string);
|
|||||||
var
|
var
|
||||||
s: string;
|
s: string;
|
||||||
l: Int64;
|
l: Int64;
|
||||||
|
i: Integer;
|
||||||
begin
|
begin
|
||||||
if Assigned(OnWriteFile) then
|
if Assigned(OnWriteFile) then
|
||||||
begin
|
begin
|
||||||
@ -2095,7 +2096,20 @@ begin
|
|||||||
OnWriteFile(Filename,s);
|
OnWriteFile(Filename,s);
|
||||||
end else
|
end else
|
||||||
begin
|
begin
|
||||||
|
try
|
||||||
ms.SaveToFile(Filename);
|
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;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -51,6 +51,7 @@ function GetPhysicalFilename(const Filename: string;
|
|||||||
function ResolveSymLinks(const Filename: string;
|
function ResolveSymLinks(const Filename: string;
|
||||||
{%H-}ExceptionOnError: boolean): string; // if a link is broken returns ''
|
{%H-}ExceptionOnError: boolean): string; // if a link is broken returns ''
|
||||||
function MatchGlobbing(Mask, Name: string): boolean;
|
function MatchGlobbing(Mask, Name: string): boolean;
|
||||||
|
function FileIsWritable(const AFilename: string): boolean;
|
||||||
|
|
||||||
function GetEnvironmentVariableCountUTF8: Integer;
|
function GetEnvironmentVariableCountUTF8: Integer;
|
||||||
function GetEnvironmentStringUTF8(Index: Integer): string;
|
function GetEnvironmentStringUTF8(Index: Integer): string;
|
||||||
|
@ -143,6 +143,11 @@ begin
|
|||||||
Result:='';
|
Result:='';
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function FileIsWritable(const AFilename: string): boolean;
|
||||||
|
begin
|
||||||
|
Result := BaseUnix.FpAccess(AFilename, BaseUnix.W_OK) = 0;
|
||||||
|
end;
|
||||||
|
|
||||||
function GetEnvironmentVariableCountUTF8: Integer;
|
function GetEnvironmentVariableCountUTF8: Integer;
|
||||||
begin
|
begin
|
||||||
Result:=GetEnvironmentVariableCount;
|
Result:=GetEnvironmentVariableCount;
|
||||||
|
@ -411,6 +411,16 @@ begin
|
|||||||
Result:=Filename;
|
Result:=Filename;
|
||||||
end;
|
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;
|
function GetEnvironmentVariableCountUTF8: Integer;
|
||||||
var
|
var
|
||||||
hp,p : PWideChar;
|
hp,p : PWideChar;
|
||||||
|
Loading…
Reference in New Issue
Block a user