From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 192.55.52.93, mailfrom: steven.shi@intel.com) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by groups.io with SMTP; Sun, 15 Sep 2019 19:51:45 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 15 Sep 2019 19:51:45 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,510,1559545200"; d="scan'208";a="216061786" Received: from jshi19-mobl.ccr.corp.intel.com ([10.254.215.41]) by fmsmga002.fm.intel.com with ESMTP; 15 Sep 2019 19:51:44 -0700 From: "Steven Shi" To: devel@edk2.groups.io Cc: liming.gao@intel.com, bob.c.feng@intel.com Subject: [PATCH] BaseTools: Add more parameter checking for CopyFileOnChange() Date: Mon, 16 Sep 2019 10:51:39 +0800 Message-Id: <20190916025139.10424-1-steven.shi@intel.com> X-Mailer: git-send-email 2.17.1.windows.2 BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=2193 The current CopyFileOnChange() method in Misc.py does not accept the input SrcFile parameter as a dir, but the method does not check the SrcFile is dir or not. This patch is to add more input parameter type checking and error message output for method CopyFileOnChange. Cc: Liming Gao Cc: Bob Feng Signed-off-by: Steven Shi --- BaseTools/Source/Python/Common/Misc.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/BaseTools/Source/Python/Common/Misc.py b/BaseTools/Source/Python/Common/Misc.py index 15ae6a9e40..7c93fc4dca 100755 --- a/BaseTools/Source/Python/Common/Misc.py +++ b/BaseTools/Source/Python/Common/Misc.py @@ -541,6 +541,11 @@ def CopyFileOnChange(SrcFile, Dst, FileLock=None): Dst = LongFilePath(Dst) if not os.path.exists(SrcFile): + EdkLogger.error(None, FILE_COPY_FAILURE, ExtraData='CopyFileOnChange SrcFile does not exists: %s' % SrcFile) + return False + + if os.path.isdir(SrcFile): + EdkLogger.error(None, FILE_COPY_FAILURE, ExtraData='CopyFileOnChange SrcFile is a dir, not a file: %s' % SrcFile) return False if os.path.isdir(Dst): -- 2.17.1.windows.2