ShellPkg: Fix file size error upon copy operation.

There was a case where an copy operation of a small file overwriting a larger file would not correctly remove the extra space in the old file.  The resultant file would have the entire source file and then what remained of the original file.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jaben Carsey <Jaben.carsey@intel.com>
reviewed-by: El-Haj-Mahmoud, Samer <samer.el-haj-mahmoud@hp.com>


git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14584 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
Jaben Carsey
2013-08-21 17:32:16 +00:00
committed by jcarsey
parent 18e44b07d4
commit ac8783c8b1

View File

@ -95,23 +95,10 @@ CopySingleFile(
return (SHELL_SUCCESS);
}
//
// Open destination file without create
//
Status = ShellOpenFileByName(Dest, &DestHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, 0);
//
// close file
//
if (DestHandle != NULL) {
ShellCloseFile(&DestHandle);
DestHandle = NULL;
}
//
// if the destination file existed check response and possibly prompt user
//
if (!EFI_ERROR(Status)) {
if (ShellFileExists(Dest) == EFI_SUCCESS) {
if (Response == NULL && !SilentMode) {
Status = ShellPromptForResponseHii(ShellPromptResponseTypeYesNoAllCancel, STRING_TOKEN (STR_GEN_DEST_EXIST_OVR), gShellLevel2HiiHandle, &Response);
}
@ -165,6 +152,8 @@ CopySingleFile(
Size = 0;
}
} else {
Status = ShellDeleteFileByName(Dest);
//
// open file with create enabled
//
@ -549,8 +538,10 @@ ProcessValidateAndCopyFiles(
SHELL_STATUS ShellStatus;
EFI_SHELL_FILE_INFO *List;
EFI_FILE_INFO *FileInfo;
CHAR16 *FullName;
List = NULL;
FullName = NULL;
ShellOpenFileMetaArg((CHAR16*)DestDir, EFI_FILE_MODE_READ, &List);
if (List != NULL && List->Link.ForwardLink != List->Link.BackLink) {
@ -563,18 +554,21 @@ ProcessValidateAndCopyFiles(
FileInfo = NULL;
FileInfo = gEfiShellProtocol->GetFileInfo(((EFI_SHELL_FILE_INFO *)List->Link.ForwardLink)->Handle);
ASSERT(FileInfo != NULL);
StrnCatGrow(&FullName, NULL, ((EFI_SHELL_FILE_INFO *)List->Link.ForwardLink)->FullName, 0);
ShellCloseFileMetaArg(&List);
if ((FileInfo->Attribute & EFI_FILE_READ_ONLY) == 0) {
ShellStatus = ValidateAndCopyFiles(FileList, ((EFI_SHELL_FILE_INFO *)List->Link.ForwardLink)->FullName, SilentMode, RecursiveMode, NULL);
ShellStatus = ValidateAndCopyFiles(FileList, FullName, SilentMode, RecursiveMode, NULL);
} else {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_DEST_ERROR), gShellLevel2HiiHandle);
ShellStatus = SHELL_ACCESS_DENIED;
}
SHELL_FREE_NON_NULL(FileInfo);
ShellCloseFileMetaArg(&List);
} else {
ShellCloseFileMetaArg(&List);
ShellStatus = ValidateAndCopyFiles(FileList, DestDir, SilentMode, RecursiveMode, NULL);
}
SHELL_FREE_NON_NULL(FileInfo);
SHELL_FREE_NON_NULL(FullName);
return (ShellStatus);
}