X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=ShellPkg%2FLibrary%2FUefiShellLevel2CommandsLib%2FRm.c;h=e4176adfe0a122be5becd6556a30a3ff9a5cee79;hb=db906063a71d8ddd90c2883d57bdea2c305fad6f;hp=ea3792a3be1fb8a33b44c623643e507f244ee974;hpb=b54fd049bdfa0d9520a40d8a1783aa681b40d751;p=mirror_edk2.git diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/Rm.c b/ShellPkg/Library/UefiShellLevel2CommandsLib/Rm.c index ea3792a3be..e4176adfe0 100644 --- a/ShellPkg/Library/UefiShellLevel2CommandsLib/Rm.c +++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/Rm.c @@ -1,7 +1,8 @@ /** @file Main file for attrib shell level 2 function. - Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.
+ (C) Copyright 2015 Hewlett-Packard Development Company, L.P.
+ Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -33,17 +34,17 @@ IsDirectoryEmpty ( IN EFI_HANDLE FileHandle ) { - EFI_STATUS Status; EFI_FILE_INFO *FileInfo; BOOLEAN NoFile; BOOLEAN RetVal; RetVal = TRUE; NoFile = FALSE; + FileInfo = NULL; - for (Status = FileHandleFindFirstFile(FileHandle, &FileInfo) + for (FileHandleFindFirstFile(FileHandle, &FileInfo) ; !NoFile - ; Status = FileHandleFindNextFile(FileHandle, FileInfo, &NoFile) + ; FileHandleFindNextFile(FileHandle, FileInfo, &NoFile) ){ if (StrStr(FileInfo->FileName, L".") != FileInfo->FileName &&StrStr(FileInfo->FileName, L"..") != FileInfo->FileName) { @@ -76,6 +77,8 @@ CascadeDelete( EFI_SHELL_FILE_INFO *Node2; EFI_STATUS Status; SHELL_PROMPT_RESPONSE *Resp; + CHAR16 *TempName; + UINTN NewSize; Resp = NULL; ShellStatus = SHELL_SUCCESS; @@ -83,7 +86,7 @@ CascadeDelete( Status = EFI_SUCCESS; if ((Node->Info->Attribute & EFI_FILE_READ_ONLY) == EFI_FILE_READ_ONLY) { - ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_RM_LOG_DETELE_RO), gShellLevel2HiiHandle, Node->FullName); + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_RM_LOG_DETELE_RO), gShellLevel2HiiHandle, L"rm", Node->FullName); return (SHELL_ACCESS_DENIED); } @@ -92,7 +95,6 @@ CascadeDelete( if (!Quiet) { Status = ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_RM_LOG_DELETE_CONF), gShellLevel2HiiHandle, Node->FullName); Status = ShellPromptForResponse(ShellPromptResponseTypeYesNo, NULL, (VOID**)&Resp); - ASSERT_EFI_ERROR(Status); ASSERT(Resp != NULL); if (EFI_ERROR(Status) || *Resp != ShellPromptResponseYes) { SHELL_FREE_NON_NULL(Resp); @@ -121,7 +123,32 @@ CascadeDelete( continue; } Node2->Status = gEfiShellProtocol->OpenFileByName (Node2->FullName, &Node2->Handle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE); - ShellStatus = CascadeDelete(Node2, Quiet); + if (EFI_ERROR(Node2->Status) && StrStr(Node2->FileName, L":") == NULL) { + // + // Update the node filename to have full path with file system identifier + // + NewSize = StrSize(Node->FullName) + StrSize(Node2->FullName); + TempName = AllocateZeroPool(NewSize); + if (TempName == NULL) { + ShellStatus = SHELL_OUT_OF_RESOURCES; + } else { + StrnCpy(TempName, Node->FullName, NewSize/sizeof(CHAR16) -1); + TempName[StrStr(TempName, L":")+1-TempName] = CHAR_NULL; + StrnCat(TempName, Node2->FullName, NewSize/sizeof(CHAR16) -1 - StrLen(TempName)); + FreePool((VOID*)Node2->FullName); + Node2->FullName = TempName; + + // + // Now try again to open the file + // + Node2->Status = gEfiShellProtocol->OpenFileByName (Node2->FullName, &Node2->Handle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE); + } + } + if (!EFI_ERROR(Node2->Status)) { + ShellStatus = CascadeDelete(Node2, Quiet); + } else if (ShellStatus == SHELL_SUCCESS) { + ShellStatus = (SHELL_STATUS)(Node2->Status&(~0x80000000)); + } if (ShellStatus != SHELL_SUCCESS) { if (List!=NULL) { gEfiShellProtocol->FreeFileList(&List); @@ -139,7 +166,9 @@ CascadeDelete( // // now delete the current node... // - ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_RM_LOG_DELETE), gShellLevel2HiiHandle, Node->FullName); + if (!Quiet) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_RM_LOG_DELETE), gShellLevel2HiiHandle, Node->FullName); + } Status = gEfiShellProtocol->DeleteFile(Node->Handle); Node->Handle = NULL; } @@ -151,7 +180,9 @@ CascadeDelete( ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_RM_LOG_DELETE_ERR), gShellLevel2HiiHandle, Status); return (SHELL_ACCESS_DENIED); } else { - ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_RM_LOG_DELETE_COMP), gShellLevel2HiiHandle); + if (!Quiet) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_RM_LOG_DELETE_COMP), gShellLevel2HiiHandle); + } return (SHELL_SUCCESS); } } @@ -172,27 +203,54 @@ IsValidDeleteTarget( ) { CONST CHAR16 *TempLocation; - CHAR16 *Temp2; + BOOLEAN RetVal; + CHAR16 *SearchString; + CHAR16 *Pattern; UINTN Size; + if (Node == NULL || Node->FullName == NULL) { + return (FALSE); + } + TempLocation = StrStr(Node->FullName, L":"); - if (StrLen(TempLocation) == 2) { + if (StrLen(TempLocation) <= 2) { // // Deleting the root directory is invalid. // return (FALSE); } + TempLocation = ShellGetCurrentDir(NULL); - Size = 0; - Temp2 = NULL; - StrnCatGrow(&Temp2, &Size, TempLocation, 0); - if (StrStr(Temp2, Node->FullName) != NULL) { - FreePool(Temp2); - return (FALSE); + if (TempLocation == NULL) { + // + // No working directory is specified so whatever is left is ok. + // + return (TRUE); + } + + Pattern = NULL; + SearchString = NULL; + Size = 0; + Pattern = StrnCatGrow(&Pattern , NULL, TempLocation , 0); + SearchString = StrnCatGrow(&SearchString, &Size, Node->FullName, 0); + if (!EFI_ERROR(ShellIsDirectory(SearchString))) { + SearchString = StrnCatGrow(&SearchString, &Size, L"\\", 0); + SearchString = StrnCatGrow(&SearchString, &Size, L"*", 0); } - FreePool(Temp2); - return (TRUE); + if (Pattern == NULL || SearchString == NULL) { + RetVal = FALSE; + } else { + RetVal = TRUE; + if (gUnicodeCollation->MetaiMatch(gUnicodeCollation, Pattern, SearchString)) { + RetVal = FALSE; + } + } + + SHELL_FREE_NON_NULL(Pattern ); + SHELL_FREE_NON_NULL(SearchString); + + return (RetVal); } /** @@ -234,7 +292,7 @@ ShellCommandRunRm ( Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE); if (EFI_ERROR(Status)) { if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) { - ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, ProblemParam); + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, L"rm", ProblemParam); FreePool(ProblemParam); ShellStatus = SHELL_INVALID_PARAMETER; } else { @@ -251,7 +309,7 @@ ShellCommandRunRm ( // // we insufficient parameters // - ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel2HiiHandle); + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel2HiiHandle, L"rm"); ShellStatus = SHELL_INVALID_PARAMETER; } else { // @@ -264,7 +322,7 @@ ShellCommandRunRm ( ){ Status = ShellOpenFileMetaArg((CHAR16*)Param, EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ, &FileList); if (EFI_ERROR(Status) || FileList == NULL || IsListEmpty(&FileList->Link)) { - ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NF), gShellLevel2HiiHandle, (CHAR16*)Param); + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NF), gShellLevel2HiiHandle, L"rm", (CHAR16*)Param); ShellStatus = SHELL_NOT_FOUND; break; }