Stricter !delfile error/warning handling

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@7008 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
anders_k 2018-06-14 22:13:23 +00:00
parent f309612920
commit a39cba6f27
2 changed files with 24 additions and 14 deletions

View file

@ -91,6 +91,8 @@ typedef enum {
DW_PLUGIN_NOUNLOAD_PLACEMENT = 6080, // reserved ..6099 DW_PLUGIN_NOUNLOAD_PLACEMENT = 6080, // reserved ..6099
DW_PP_PRAGMA_UNKNOWN = 6100, // reserved ..6199 DW_PP_PRAGMA_UNKNOWN = 6100, // reserved ..6199
DW_PP_PRAGMA_INVALID = 6101, DW_PP_PRAGMA_INVALID = 6101,
DW_PP_DELFILE_DELERROR = 6149,
DW_PP_DELFILE_NOMATCH = DW_PP_DELFILE_DELERROR,
DW_PP_VERBOSE_POP_EMPTY_STACK = 6150, DW_PP_VERBOSE_POP_EMPTY_STACK = 6150,
//DW_PP_VERBOSE_BAD_LEVEL = 6151?, // 2.x failed to issue a warning. 3.x currently aborts with hard error. //DW_PP_VERBOSE_BAD_LEVEL = 6151?, // 2.x failed to issue a warning. 3.x currently aborts with hard error.
DW_INCLUDE_NONFATAL_NOT_FOUND = 7000, // reserved ..7009 DW_INCLUDE_NONFATAL_NOT_FOUND = 7000, // reserved ..7009

View file

@ -491,9 +491,8 @@ int CEXEBuild::pp_tempfile(LineParser&line)
int CEXEBuild::pp_delfile(LineParser&line) int CEXEBuild::pp_delfile(LineParser&line)
{ {
int fatal = 1; UINT fatal = true, a = 1, matchcount = 0;
int a = 1; const TCHAR *fc = line.gettoken_str(a);
TCHAR *fc = line.gettoken_str(a);
if (line.getnumtokens()==3) if (line.getnumtokens()==3)
{ {
if (!_tcsicmp(fc,_T("/nonfatal"))) if (!_tcsicmp(fc,_T("/nonfatal")))
@ -502,7 +501,8 @@ int CEXEBuild::pp_delfile(LineParser&line)
PRINTHELP(); PRINTHELP();
} }
SCRIPT_MSG(_T("!delfile: \"%") NPRIs _T("\"\n"), line.gettoken_str(a)); SCRIPT_MSG(_T("!delfile: \"%") NPRIs _T("\"\n"), fc);
const TCHAR *fmt = _T("!delfile: \"%") NPRIs _T("\" couldn't be deleted.\n");
tstring dir = get_dir_name(fc), spec = get_file_name(fc); tstring dir = get_dir_name(fc), spec = get_file_name(fc);
tstring basedir = dir + PLATFORM_PATH_SEPARATOR_STR; tstring basedir = dir + PLATFORM_PATH_SEPARATOR_STR;
@ -510,24 +510,32 @@ int CEXEBuild::pp_delfile(LineParser&line)
boost::scoped_ptr<dir_reader> dr( new_dir_reader() ); boost::scoped_ptr<dir_reader> dr( new_dir_reader() );
dr->read(dir); // BUGBUG: PATH_CONVERT? dr->read(dir); // BUGBUG: PATH_CONVERT?
dir_reader::iterator files_itr = dr->files().begin();
for (dir_reader::iterator files_itr = dr->files().begin(); for (; files_itr != dr->files().end(); files_itr++)
files_itr != dr->files().end();
files_itr++)
{ {
if (!dir_reader::matches(*files_itr, spec)) if (!dir_reader::matches(*files_itr, spec))
continue; continue;
++matchcount;
tstring file = basedir + *files_itr; // BUGBUG: PATH_CONVERT? tstring file = basedir + *files_itr; // BUGBUG: PATH_CONVERT?
fc = file.c_str();
int result = _tunlink(file.c_str()); if (-1 == _tunlink(fc))
if (result == -1)
{ {
ERROR_MSG(_T("!delfile: \"%") NPRIs _T("\" couldn't be deleted.\n"), file.c_str()); if (fatal)
if (fatal) return PS_ERROR; return (ERROR_MSG(fmt, fc), PS_ERROR);
else
warning_fl(DW_PP_DELFILE_DELERROR, fmt, fc);
} }
else else
SCRIPT_MSG(_T("!delfile: deleted \"%") NPRIs _T("\"\n"), file.c_str()); SCRIPT_MSG(_T("!delfile: deleted \"%") NPRIs _T("\"\n"), fc);
}
if (!matchcount)
{
if (fatal)
return (ERROR_MSG(fmt, fc), PS_ERROR);
else
warning_fl(DW_PP_DELFILE_NOMATCH, fmt, fc);
} }
return PS_OK; return PS_OK;
} }