public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Jeff Westfahl <jeff.westfahl@ni.com>
To: <edk2-devel@lists.01.org>
Cc: Jeff Westfahl <jeff.westfahl@ni.com>,
	Ruiyu Ni <ruiyu.ni@intel.com>,
	Jaben Carsey <jaben.carsey@intel.com>
Subject: [PATCH] ShellPkg/Touch: Create file if it doesn't exist
Date: Mon, 15 May 2017 16:01:53 -0500	[thread overview]
Message-ID: <1494882113-19051-1-git-send-email-jeff.westfahl@ni.com> (raw)

The UEFI Shell touch command returns an error if a file to be touched
doesn't exist. In other command line operating environments, the touch
command typically creates a file if it doesn't exist. This patch updates
the UEFI Shell touch command to follow this convention.

Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Jaben Carsey <jaben.carsey@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Westfahl <jeff.westfahl@ni.com>
---
 ShellPkg/Library/UefiShellLevel3CommandsLib/Touch.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/ShellPkg/Library/UefiShellLevel3CommandsLib/Touch.c b/ShellPkg/Library/UefiShellLevel3CommandsLib/Touch.c
index 639346f..921de5a 100644
--- a/ShellPkg/Library/UefiShellLevel3CommandsLib/Touch.c
+++ b/ShellPkg/Library/UefiShellLevel3CommandsLib/Touch.c
@@ -175,11 +175,13 @@ ShellCommandRunTouch (
   UINTN               ParamCount;
   EFI_SHELL_FILE_INFO *FileList;
   EFI_SHELL_FILE_INFO *Node;
+  SHELL_FILE_HANDLE   FileHandle;
 
   ProblemParam        = NULL;
   ShellStatus         = SHELL_SUCCESS;
   ParamCount          = 0;
   FileList            = NULL;
+  FileHandle          = NULL;
 
   //
   // initialize the shell lib (we must be in non-auto-init...)
@@ -226,9 +228,17 @@ ShellCommandRunTouch (
          ){
         Status = ShellOpenFileMetaArg((CHAR16*)Param, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, &FileList);
         if (EFI_ERROR(Status)) {
-          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellLevel3HiiHandle, L"touch", (CHAR16*)Param);  
-          ShellStatus = SHELL_NOT_FOUND;
-          break;
+          //
+          // try to create the file in case it doesn't exist
+          //
+          gEfiShellProtocol->CreateFile(Param, 0, &FileHandle);
+          gEfiShellProtocol->CloseFile(FileHandle);
+          Status = ShellOpenFileMetaArg((CHAR16*)Param, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, &FileList);
+          if (EFI_ERROR(Status)) {
+            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellLevel3HiiHandle, L"touch", (CHAR16*)Param);
+            ShellStatus = SHELL_NOT_FOUND;
+            break;
+          }
         }
         //
         // make sure we completed the param parsing sucessfully...
-- 
2.7.4



             reply	other threads:[~2017-05-15 21:02 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-15 21:01 Jeff Westfahl [this message]
2017-05-15 21:08 ` [PATCH] ShellPkg/Touch: Create file if it doesn't exist Tim Lewis
2017-05-15 21:27   ` Jeff Westfahl

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1494882113-19051-1-git-send-email-jeff.westfahl@ni.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox