BaseTools: Do not create an empty file if Rsa2048Sha256Sign was failed.
authorYingke Liu <yingke.d.liu@intel.com>
Wed, 1 Jul 2015 05:14:28 +0000 (05:14 +0000)
committeryingke <yingke@Edk2>
Wed, 1 Jul 2015 05:14:28 +0000 (05:14 +0000)
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Yingke Liu <yingke.d.liu@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@17774 6f19259b-4bc3-4df7-8a09-765794883524

BaseTools/Source/Python/Rsa2048Sha256Sign/Rsa2048Sha256Sign.py

index b83c9d4d42c43bc163c05417a5d67f51c8f7891d..b3254d82bf353ff63de9e1e1446d3c9ca50e5fc3 100644 (file)
@@ -65,7 +65,7 @@ if __name__ == '__main__':
   group = parser.add_mutually_exclusive_group(required=True)\r
   group.add_argument("-e", action="store_true", dest='Encode', help='encode file')\r
   group.add_argument("-d", action="store_true", dest='Decode', help='decode file')\r
-  parser.add_argument("-o", "--output", dest='OutputFile', type=argparse.FileType('wb'), metavar='filename', help="specify the output filename", required=True)\r
+  parser.add_argument("-o", "--output", dest='OutputFile', type=str, metavar='filename', help="specify the output filename", required=True)\r
   parser.add_argument("--private-key", dest='PrivateKeyFile', type=argparse.FileType('rb'), help="specify the private key filename.  If not specified, a test signing key is used.")\r
   parser.add_argument("-v", "--verbose", dest='Verbose', action="store_true", help="increase output messages")\r
   parser.add_argument("-q", "--quiet", dest='Quiet', action="store_true", help="reduce output messages")\r
@@ -110,10 +110,13 @@ if __name__ == '__main__':
   args.InputFile.close()\r
 \r
   #\r
-  # Save output filename and close output file\r
+  # Save output filename and check if path exists\r
   #\r
-  args.OutputFileName = args.OutputFile.name\r
-  args.OutputFile.close()\r
+  OutputDir = os.path.dirname(args.OutputFile)\r
+  if not os.path.exists(OutputDir):\r
+    print 'ERROR: The output path does not exist: %s' % OutputDir\r
+    sys.exit(1)\r
+  args.OutputFileName = args.OutputFile\r
 \r
   #\r
   # Save private key filename and close private key file\r