public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH] ShellPkg/Touch: Create file if it doesn't exist
@ 2017-05-15 21:01 Jeff Westfahl
  2017-05-15 21:08 ` Tim Lewis
  0 siblings, 1 reply; 3+ messages in thread
From: Jeff Westfahl @ 2017-05-15 21:01 UTC (permalink / raw)
  To: edk2-devel; +Cc: Jeff Westfahl, Ruiyu Ni, Jaben Carsey

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



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] ShellPkg/Touch: Create file if it doesn't exist
  2017-05-15 21:01 [PATCH] ShellPkg/Touch: Create file if it doesn't exist Jeff Westfahl
@ 2017-05-15 21:08 ` Tim Lewis
  2017-05-15 21:27   ` Jeff Westfahl
  0 siblings, 1 reply; 3+ messages in thread
From: Tim Lewis @ 2017-05-15 21:08 UTC (permalink / raw)
  To: Jeff Westfahl, edk2-devel@lists.01.org; +Cc: Ruiyu Ni, Jaben Carsey

I don't think it is good to change the behavior of the tool beyond what is in the specification. Further, this tool has existed for quite a long time in the EDK shell and now the UEFI shell without this behavior. So the de-facto standard of this environment is "don't create". Leaving behind stray 0 byte files would be an unwanted side effect for existing scripts that use this command.

Further, this doesn't add any corresponding command-line options to , and certainly not without corresponding command-line options like -c to disable this behavior.

Thanks,

Tim


-----Original Message-----
From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Jeff Westfahl
Sent: Monday, May 15, 2017 2:02 PM
To: edk2-devel@lists.01.org
Cc: Ruiyu Ni <ruiyu.ni@intel.com>; Jaben Carsey <jaben.carsey@intel.com>
Subject: [edk2] [PATCH] ShellPkg/Touch: Create file if it doesn't exist

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

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] ShellPkg/Touch: Create file if it doesn't exist
  2017-05-15 21:08 ` Tim Lewis
@ 2017-05-15 21:27   ` Jeff Westfahl
  0 siblings, 0 replies; 3+ messages in thread
From: Jeff Westfahl @ 2017-05-15 21:27 UTC (permalink / raw)
  To: Tim Lewis; +Cc: Jeff Westfahl, edk2-devel@lists.01.org, Ruiyu Ni, Jaben Carsey

Hi Tim,

I think those are reasonable arguments. It's probably best to just leave 
the touch command alone. It sounds like we've gotten along fine with the 
existing behavior for quite a while.

Regards,
Jeff

On Mon, 15 May 2017, Tim Lewis wrote:

> I don't think it is good to change the behavior of the tool beyond what is in the specification. Further, this tool has existed for quite a long time in the EDK shell and now the UEFI shell without this behavior. So the de-facto standard of this environment is "don't create". Leaving behind stray 0 byte files would be an unwanted side effect for existing scripts that use this command.
>
> Further, this doesn't add any corresponding command-line options to , and certainly not without corresponding command-line options like -c to disable this behavior.
>
> Thanks,
>
> Tim
>
>
> -----Original Message-----
> From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Jeff Westfahl
> Sent: Monday, May 15, 2017 2:02 PM
> To: edk2-devel@lists.01.org
> Cc: Ruiyu Ni <ruiyu.ni@intel.com>; Jaben Carsey <jaben.carsey@intel.com>
> Subject: [edk2] [PATCH] ShellPkg/Touch: Create file if it doesn't exist
>
> 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
>
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel
>


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-05-15 21:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-15 21:01 [PATCH] ShellPkg/Touch: Create file if it doesn't exist Jeff Westfahl
2017-05-15 21:08 ` Tim Lewis
2017-05-15 21:27   ` Jeff Westfahl

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox