From a39cba6f27c27adbb644471146154ba9d4fb9f40 Mon Sep 17 00:00:00 2001 From: anders_k Date: Thu, 14 Jun 2018 22:13:23 +0000 Subject: [PATCH] Stricter !delfile error/warning handling git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@7008 212acab6-be3b-0410-9dea-997c60f758d6 --- Source/build.h | 2 ++ Source/scriptpp.cpp | 36 ++++++++++++++++++++++-------------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/Source/build.h b/Source/build.h index 2e267dbc..8d94a4ea 100644 --- a/Source/build.h +++ b/Source/build.h @@ -91,6 +91,8 @@ typedef enum { DW_PLUGIN_NOUNLOAD_PLACEMENT = 6080, // reserved ..6099 DW_PP_PRAGMA_UNKNOWN = 6100, // reserved ..6199 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_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 diff --git a/Source/scriptpp.cpp b/Source/scriptpp.cpp index ccb0df9c..55c78726 100644 --- a/Source/scriptpp.cpp +++ b/Source/scriptpp.cpp @@ -491,9 +491,8 @@ int CEXEBuild::pp_tempfile(LineParser&line) int CEXEBuild::pp_delfile(LineParser&line) { - int fatal = 1; - int a = 1; - TCHAR *fc = line.gettoken_str(a); + UINT fatal = true, a = 1, matchcount = 0; + const TCHAR *fc = line.gettoken_str(a); if (line.getnumtokens()==3) { if (!_tcsicmp(fc,_T("/nonfatal"))) @@ -502,7 +501,8 @@ int CEXEBuild::pp_delfile(LineParser&line) 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 basedir = dir + PLATFORM_PATH_SEPARATOR_STR; @@ -510,24 +510,32 @@ int CEXEBuild::pp_delfile(LineParser&line) boost::scoped_ptr dr( new_dir_reader() ); dr->read(dir); // BUGBUG: PATH_CONVERT? - - for (dir_reader::iterator files_itr = dr->files().begin(); - files_itr != dr->files().end(); - files_itr++) + dir_reader::iterator files_itr = dr->files().begin(); + for (; files_itr != dr->files().end(); files_itr++) { if (!dir_reader::matches(*files_itr, spec)) continue; + ++matchcount; tstring file = basedir + *files_itr; // BUGBUG: PATH_CONVERT? - - int result = _tunlink(file.c_str()); - if (result == -1) + fc = file.c_str(); + if (-1 == _tunlink(fc)) { - ERROR_MSG(_T("!delfile: \"%") NPRIs _T("\" couldn't be deleted.\n"), file.c_str()); - if (fatal) return PS_ERROR; + if (fatal) + return (ERROR_MSG(fmt, fc), PS_ERROR); + else + warning_fl(DW_PP_DELFILE_DELERROR, fmt, fc); } 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; }