* [PATCH 0/2] ShellPkg/mkdir Support creating nested directories
@ 2017-08-16 5:42 Ruiyu Ni
2017-08-16 5:42 ` [PATCH 1/2] Shell/mkdir: Modify the help content to align to spec Ruiyu Ni
2017-08-16 5:42 ` [PATCH 2/2] ShellPkg/mkdir: support creating nested directories Ruiyu Ni
0 siblings, 2 replies; 3+ messages in thread
From: Ruiyu Ni @ 2017-08-16 5:42 UTC (permalink / raw)
To: edk2-devel
Huajing Li (2):
Shell/mkdir: Modify the help content to align to spec.
ShellPkg/mkdir: support creating nested directories
.../Library/UefiShellLevel2CommandsLib/MkDir.c | 54 ++++++++++++++++++----
.../UefiShellLevel2CommandsLib.uni | 15 +++---
2 files changed, 52 insertions(+), 17 deletions(-)
--
2.12.2.windows.2
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 1/2] Shell/mkdir: Modify the help content to align to spec.
2017-08-16 5:42 [PATCH 0/2] ShellPkg/mkdir Support creating nested directories Ruiyu Ni
@ 2017-08-16 5:42 ` Ruiyu Ni
2017-08-16 5:42 ` [PATCH 2/2] ShellPkg/mkdir: support creating nested directories Ruiyu Ni
1 sibling, 0 replies; 3+ messages in thread
From: Ruiyu Ni @ 2017-08-16 5:42 UTC (permalink / raw)
To: edk2-devel; +Cc: Huajing Li
From: Huajing Li <huajing.li@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Huajing Li <huajing.li@intel.com>
Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
---
.../UefiShellLevel2CommandsLib.uni | 15 ++++++---------
1 file changed, 6 insertions(+), 9 deletions(-)
diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.uni b/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.uni
index 60f48f4633..f9c647a035 100644
--- a/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.uni
+++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.uni
@@ -464,18 +464,15 @@
"MKDIR dir [dir...]\r\n"
".SH OPTIONS\r\n"
" \r\n"
-" dir - Specifies the name of a directory or directories to create. (Wildcards are not\r\n"
-" allowed) \r\n"
+" dir - Specifies the name of a directory or directories to create.\r\n"
+" (Wildcards are not allowed)\r\n"
".SH DESCRIPTION\r\n"
" \r\n"
"NOTES:\r\n"
-" 1. The parent directory must already exist.\r\n"
-" 2. If the directory already exists, mkdir will abort.\r\n"
-" 3. Specifying additional directory parameters dependent on previous\r\n"
-" directory parameters is not allowed:\r\n"
-" For example, mkdir new new\Test is not allowed.\r\n"
-" 4. Redirecting output to a file that exists under the directory specified\r\n"
-" by this command is not allowed.\r\n"
+" 1. Mkdir can create one or more new directories.\r\n"
+" 2. If dir includes nested directories, then parent directories will be\r\n"
+" created before child directories.\r\n"
+" 3. If the directory already exists, mkdir will exit with an error.\r\n"
".SH EXAMPLES\r\n"
" \r\n"
"EXAMPLES:\r\n"
--
2.12.2.windows.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 2/2] ShellPkg/mkdir: support creating nested directories
2017-08-16 5:42 [PATCH 0/2] ShellPkg/mkdir Support creating nested directories Ruiyu Ni
2017-08-16 5:42 ` [PATCH 1/2] Shell/mkdir: Modify the help content to align to spec Ruiyu Ni
@ 2017-08-16 5:42 ` Ruiyu Ni
1 sibling, 0 replies; 3+ messages in thread
From: Ruiyu Ni @ 2017-08-16 5:42 UTC (permalink / raw)
To: edk2-devel; +Cc: Huajing Li
From: Huajing Li <huajing.li@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Huajing Li <huajing.li@intel.com>
Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
---
.../Library/UefiShellLevel2CommandsLib/MkDir.c | 54 ++++++++++++++++++----
1 file changed, 46 insertions(+), 8 deletions(-)
diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/MkDir.c b/ShellPkg/Library/UefiShellLevel2CommandsLib/MkDir.c
index 4aade13aac..3a9e037d0e 100644
--- a/ShellPkg/Library/UefiShellLevel2CommandsLib/MkDir.c
+++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/MkDir.c
@@ -30,14 +30,19 @@ ShellCommandRunMkDir (
{
EFI_STATUS Status;
CONST CHAR16 *NewDirName;
+ CHAR16 *NewDirNameCopy;
+ CHAR16 *SplitName;
+ CHAR16 SaveSplitChar;
UINTN DirCreateCount;
LIST_ENTRY *Package;
CHAR16 *ProblemParam;
SHELL_FILE_HANDLE FileHandle;
SHELL_STATUS ShellStatus;
- ShellStatus = SHELL_SUCCESS;
-
+ ShellStatus = SHELL_SUCCESS;
+ NewDirNameCopy = NULL;
+ SplitName = NULL;
+ SaveSplitChar = CHAR_NULL;
//
// initialize the shell lib (we must be in non-auto-init...)
//
@@ -99,21 +104,54 @@ ShellCommandRunMkDir (
ShellCloseFile(&FileHandle);
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MKDIR_ALREADY), gShellLevel2HiiHandle, NewDirName);
ShellStatus = SHELL_INVALID_PARAMETER;
- break;
} else {
ASSERT(FileHandle == NULL);
//
- // create the directory named NewDirName
+ // create the nested directory from parent to child.
+ // if NewDirName = test1\test2\test3, first create "test1\" directory, then "test1\test2\", finally "test1\test2\test3".
//
- Status = ShellCreateDirectory(NewDirName, &FileHandle);
- if (FileHandle != NULL) {
- gEfiShellProtocol->CloseFile(FileHandle);
+ NewDirNameCopy = AllocateCopyPool (StrSize(NewDirName), NewDirName);
+ NewDirNameCopy = PathCleanUpDirectories (NewDirNameCopy);
+ if(NewDirNameCopy == NULL) {
+ ShellStatus = SHELL_OUT_OF_RESOURCES;
+ break;
+ }
+ SplitName = NewDirNameCopy;
+ while (SplitName != NULL) {
+ SplitName = StrStr (SplitName + 1, L"\\");
+ if (SplitName != NULL) {
+ SaveSplitChar = *(SplitName + 1);
+ *(SplitName + 1) = '\0';
+ }
+ //
+ // check if current nested directory already exists... continue to create the child directory.
+ //
+ Status = ShellOpenFileByName (NewDirNameCopy,
+ &FileHandle,
+ EFI_FILE_MODE_READ,
+ EFI_FILE_DIRECTORY
+ );
+ if (!EFI_ERROR(Status)) {
+ ShellCloseFile (&FileHandle);
+ } else {
+ Status = ShellCreateDirectory (NewDirNameCopy, &FileHandle);
+ if (EFI_ERROR(Status)) {
+ break;
+ }
+ if (FileHandle != NULL) {
+ gEfiShellProtocol->CloseFile (FileHandle);
+ }
+ }
+ if (SplitName != NULL) {
+ *(SplitName + 1) = SaveSplitChar;
+ }
}
if (EFI_ERROR(Status)) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MKDIR_CREATEFAIL), gShellLevel2HiiHandle, NewDirName);
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_MKDIR_CREATEFAIL), gShellLevel2HiiHandle, NewDirName);
ShellStatus = SHELL_ACCESS_DENIED;
break;
}
+ SHELL_FREE_NON_NULL (NewDirNameCopy);
}
}
}
--
2.12.2.windows.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-08-16 5:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-08-16 5:42 [PATCH 0/2] ShellPkg/mkdir Support creating nested directories Ruiyu Ni
2017-08-16 5:42 ` [PATCH 1/2] Shell/mkdir: Modify the help content to align to spec Ruiyu Ni
2017-08-16 5:42 ` [PATCH 2/2] ShellPkg/mkdir: support creating nested directories Ruiyu Ni
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox