]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ShellPkg: allow creating of files to create required directory path
authorjaben carsey <jaben.carsey@intel.com>
Tue, 13 Jan 2015 22:16:41 +0000 (22:16 +0000)
committerjcarsey <jcarsey@Edk2>
Tue, 13 Jan 2015 22:16:41 +0000 (22:16 +0000)
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: jaben carsey <jaben.carsey@intel.com>
Reviewed-by: Tapan Shah <tapandshah@hp.com>
Reviewed-by: Joe Peterson <joe.peterson@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16606 6f19259b-4bc3-4df7-8a09-765794883524

ShellPkg/Library/UefiShellLib/UefiShellLib.c
ShellPkg/Library/UefiShellLib/UefiShellLib.inf

index b7ca41b9846b65bb5c91267b5d91a2a7dbb30f5f..844f17abc622b3c7220b3f6707e0fc762d8857d6 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Provides interface to shell functionality for shell commands and applications.\r
 \r
-  Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -15,6 +15,7 @@
 #include "UefiShellLib.h"\r
 #include <ShellBase.h>\r
 #include <Library/SortLib.h>\r
+#include <Library/PathLib.h>\r
 \r
 #define FIND_XXXXX_FILE_BUFFER_SIZE (SIZE_OF_EFI_FILE_INFO + MAX_FILE_NAME_LEN)\r
 \r
@@ -671,6 +672,7 @@ ShellOpenFileByName(
   EFI_DEVICE_PATH_PROTOCOL      *FilePath;\r
   EFI_STATUS                    Status;\r
   EFI_FILE_INFO                 *FileInfo;\r
+  CHAR16                        *FileNameCopy;\r
 \r
   //\r
   // ASSERT if FileName is NULL\r
@@ -682,11 +684,32 @@ ShellOpenFileByName(
   }\r
 \r
   if (gEfiShellProtocol != NULL) {\r
-    if ((OpenMode & EFI_FILE_MODE_CREATE) == EFI_FILE_MODE_CREATE && (Attributes & EFI_FILE_DIRECTORY) == EFI_FILE_DIRECTORY) {\r
-      return ShellCreateDirectory(FileName, FileHandle);\r
+    if ((OpenMode & EFI_FILE_MODE_CREATE) == EFI_FILE_MODE_CREATE) {\r
+\r
+      //\r
+      // Create only a directory\r
+      //\r
+      if ((Attributes & EFI_FILE_DIRECTORY) == EFI_FILE_DIRECTORY) {\r
+        return ShellCreateDirectory(FileName, FileHandle);\r
+      }\r
+\r
+      //\r
+      // Create the directory to create the file in\r
+      //\r
+      FileNameCopy = AllocateCopyPool (StrSize (FileName), FileName);\r
+      if (FileName == NULL) {\r
+        return (EFI_OUT_OF_RESOURCES);\r
+      }\r
+      PathCleanUpDirectories (FileNameCopy);\r
+      if (PathRemoveLastItem (FileNameCopy)) {\r
+        ShellCreateDirectory (FileNameCopy, FileHandle);\r
+        ShellCloseFile (FileHandle);\r
+      }\r
+      SHELL_FREE_NON_NULL (FileNameCopy);\r
     }\r
+\r
     //\r
-    // Use UEFI Shell 2.0 method\r
+    // Use UEFI Shell 2.0 method to create the file\r
     //\r
     Status = gEfiShellProtocol->OpenFileByName(FileName,\r
                                                FileHandle,\r
index ea80aa08a2ba6b853346bba810ea971092dbb260..da06c34884498ee143a99070b62ca3a56d457298 100644 (file)
@@ -1,7 +1,7 @@
 ##  @file\r
 # Provides interface to shell functionality for shell commands and applications.\r
 #\r
-# Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved. <BR>\r
+# Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved. <BR>\r
 #\r
 #  This program and the accompanying materials\r
 #  are licensed and made available under the terms and conditions of the BSD License\r
@@ -48,6 +48,7 @@
   UefiLib\r
   HiiLib\r
   SortLib\r
+  PathLib\r
 \r
 [Protocols]\r
   gEfiSimpleFileSystemProtocolGuid              # ALWAYS_CONSUMED\r