mirror of https://github.com/acidanthera/audk.git
ShellPkg/mkdir: support creating nested directories
Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Huajing Li <huajing.li@intel.com> Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
This commit is contained in:
parent
88f9acd6cc
commit
bb3d1a6198
|
@ -30,6 +30,9 @@ ShellCommandRunMkDir (
|
|||
{
|
||||
EFI_STATUS Status;
|
||||
CONST CHAR16 *NewDirName;
|
||||
CHAR16 *NewDirNameCopy;
|
||||
CHAR16 *SplitName;
|
||||
CHAR16 SaveSplitChar;
|
||||
UINTN DirCreateCount;
|
||||
LIST_ENTRY *Package;
|
||||
CHAR16 *ProblemParam;
|
||||
|
@ -37,7 +40,9 @@ ShellCommandRunMkDir (
|
|||
SHELL_STATUS ShellStatus;
|
||||
|
||||
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);
|
||||
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);
|
||||
ShellStatus = SHELL_ACCESS_DENIED;
|
||||
break;
|
||||
}
|
||||
SHELL_FREE_NON_NULL (NewDirNameCopy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue