From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from msmail.insydesw.com.tw (ms.insydesw.com [211.75.113.220]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 6C34321A1349E for ; Mon, 15 May 2017 14:08:05 -0700 (PDT) Received: from msmail.insydesw.com.tw ([fe80::74f7:f173:f4aa:9a05]) by msmail.insydesw.com.tw ([fe80::74f7:f173:f4aa:9a05%11]) with mapi id 14.01.0438.000; Tue, 16 May 2017 05:08:03 +0800 From: Tim Lewis To: Jeff Westfahl , "edk2-devel@lists.01.org" CC: Ruiyu Ni , Jaben Carsey Thread-Topic: [edk2] [PATCH] ShellPkg/Touch: Create file if it doesn't exist Thread-Index: AQHSzb6iO/tQErvXPUecXXy1FQloz6H14l6A Date: Mon, 15 May 2017 21:08:02 +0000 Message-ID: <7236196A5DF6C040855A6D96F556A53F57E66F@msmail.insydesw.com.tw> References: <1494882113-19051-1-git-send-email-jeff.westfahl@ni.com> In-Reply-To: <1494882113-19051-1-git-send-email-jeff.westfahl@ni.com> Accept-Language: en-US, zh-TW X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [192.168.100.111] MIME-Version: 1.0 Subject: Re: [PATCH] ShellPkg/Touch: Create file if it doesn't exist X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 15 May 2017 21:08:06 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable 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-fa= cto 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 t= his command. Further, this doesn't add any corresponding command-line options to , and c= ertainly 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 ; Jaben Carsey 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 t= ypically creates a file if it doesn't exist. This patch updates the UEFI Sh= ell touch command to follow this convention. Cc: Ruiyu Ni Cc: Jaben Carsey Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jeff Westfahl --- 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; =20 ProblemParam =3D NULL; ShellStatus =3D SHELL_SUCCESS; ParamCount =3D 0; FileList =3D NULL; + FileHandle =3D NULL; =20 // // initialize the shell lib (we must be in non-auto-init...) @@ -226,9 += 228,17 @@ ShellCommandRunTouch ( ){ Status =3D 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); =20 - ShellStatus =3D SHELL_NOT_FOUND; - break; + // + // try to create the file in case it doesn't exist + // + gEfiShellProtocol->CreateFile(Param, 0, &FileHandle); + gEfiShellProtocol->CloseFile(FileHandle); + Status =3D ShellOpenFileMetaArg((CHAR16*)Param, EFI_FILE_MODE_RE= AD|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 =3D 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