diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c b/ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c
index 64ce4ae2c0..523096ac22 100644
--- a/ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c
+++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c
@@ -1,7 +1,7 @@
/** @file
Main file for ls shell level 2 function.
- Copyright (c) 2013 Hewlett-Packard Development Company, L.P.
+ Copyright (c) 2013 - 2014, 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
@@ -408,6 +408,10 @@ PrintLsOutput(
; !IsNull(&ListHead->Link, &Node->Link)
; Node = (EFI_SHELL_FILE_INFO *)GetNextNode(&ListHead->Link, &Node->Link)
){
+ if (ShellGetExecutionBreakFlag ()) {
+ ShellStatus = SHELL_ABORTED;
+ break;
+ }
ASSERT(Node != NULL);
if (LongestPath < StrSize(Node->FullName)) {
LongestPath = StrSize(Node->FullName);
@@ -445,12 +449,12 @@ PrintLsOutput(
HeaderPrinted = TRUE;
}
- if (!Sfo) {
+ if (!Sfo && ShellStatus != SHELL_ABORTED) {
PrintNonSfoFooter(FileCount, FileSize, DirCount);
}
}
- if (Rec) {
+ if (Rec && ShellStatus != SHELL_ABORTED) {
//
// Re-Open all the files under the starting path for directories that didnt necessarily match our file filter
//
@@ -493,6 +497,13 @@ PrintLsOutput(
&FoundOne,
Count,
TimeZone);
+
+ //
+ // Since it's running recursively, we have to break immediately when returned SHELL_ABORTED
+ //
+ if (ShellStatus == SHELL_ABORTED) {
+ break;
+ }
}
}
}