diff options
author | Laszlo Ersek <lersek@redhat.com> | 2021-01-13 09:54:50 +0100 |
---|---|---|
committer | mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> | 2021-01-19 18:23:28 +0000 |
commit | 70254306a82357ca6b37a6d246b6558c5534e361 (patch) | |
tree | e7d416c6c7ea078cca7637b4e70f7d32e199b01e /ShellPkg | |
parent | 101c55ac0db79b9ccff8b612f11755a3d473a82c (diff) | |
download | edk2-70254306a82357ca6b37a6d246b6558c5534e361.tar.gz edk2-70254306a82357ca6b37a6d246b6558c5534e361.tar.bz2 edk2-70254306a82357ca6b37a6d246b6558c5534e361.zip |
ShellPkg/Ls: sort output by FileName in non-SFO mode
Sorting the LS output in non-SFO mode by FileName is best demonstrated
with two examples.
(1a) Before:
> FS2:\> dir -r apps
> Directory of: FS2:\apps\
> 01/01/1970 01:00 <DIR> r 0 .
> 12/22/2020 17:53 <DIR> 4,096 X64
> 12/22/2020 17:53 <DIR> 4,096 AARCH64
> 01/01/1970 01:00 <DIR> r 0 ..
> 12/22/2020 17:53 <DIR> 4,096 IA32
> 0 File(s) 0 bytes
> 5 Dir(s)
> Directory of: FS2:\apps\X64\
> 12/22/2020 17:52 18,752 DumpDynPcd.efi
> 12/22/2020 17:52 34,240 SmiHandlerProfileInfo.efi
> 01/01/1970 01:00 <DIR> r 0 .
> 12/22/2020 17:52 11,456 VariableInfo.efi
> 12/22/2020 17:52 26,304 MemoryProfileInfo.efi
> 12/22/2020 17:53 126,656 AcpiViewApp.efi
> 12/22/2020 17:53 38,784 Cpuid.efi
> 01/01/1970 01:00 <DIR> r 0 ..
> 6 File(s) 256,192 bytes
> 2 Dir(s)
> Directory of: FS2:\apps\AARCH64\
> 12/22/2020 17:52 32,768 DumpDynPcd.efi
> 01/01/1970 01:00 <DIR> r 0 .
> 12/22/2020 17:52 20,480 VariableInfo.efi
> 12/22/2020 17:52 40,960 MemoryProfileInfo.efi
> 12/22/2020 17:53 139,264 AcpiViewApp.efi
> 01/01/1970 01:00 <DIR> r 0 ..
> 4 File(s) 233,472 bytes
> 2 Dir(s)
> Directory of: FS2:\apps\IA32\
> 12/22/2020 17:52 17,344 DumpDynPcd.efi
> 12/22/2020 17:52 30,720 SmiHandlerProfileInfo.efi
> 01/01/1970 01:00 <DIR> r 0 .
> 12/22/2020 17:52 10,880 VariableInfo.efi
> 12/22/2020 17:52 24,192 MemoryProfileInfo.efi
> 12/22/2020 17:53 105,536 AcpiViewApp.efi
> 12/22/2020 17:53 36,096 Cpuid.efi
> 01/01/1970 01:00 <DIR> r 0 ..
> 6 File(s) 224,768 bytes
> 2 Dir(s)
(1b) After:
> FS2:\> dir -r apps
> Directory of: FS2:\apps\
> 01/01/1970 01:00 <DIR> r 0 .
> 01/01/1970 01:00 <DIR> r 0 ..
> 12/22/2020 17:53 <DIR> 4,096 AARCH64
> 12/22/2020 17:53 <DIR> 4,096 IA32
> 12/22/2020 17:53 <DIR> 4,096 X64
> 0 File(s) 0 bytes
> 5 Dir(s)
> Directory of: FS2:\apps\X64\
> 01/01/1970 01:00 <DIR> r 0 .
> 01/01/1970 01:00 <DIR> r 0 ..
> 12/22/2020 17:53 126,656 AcpiViewApp.efi
> 12/22/2020 17:53 38,784 Cpuid.efi
> 12/22/2020 17:52 18,752 DumpDynPcd.efi
> 12/22/2020 17:52 26,304 MemoryProfileInfo.efi
> 12/22/2020 17:52 34,240 SmiHandlerProfileInfo.efi
> 12/22/2020 17:52 11,456 VariableInfo.efi
> 6 File(s) 256,192 bytes
> 2 Dir(s)
> Directory of: FS2:\apps\AARCH64\
> 01/01/1970 01:00 <DIR> r 0 .
> 01/01/1970 01:00 <DIR> r 0 ..
> 12/22/2020 17:53 139,264 AcpiViewApp.efi
> 12/22/2020 17:52 32,768 DumpDynPcd.efi
> 12/22/2020 17:52 40,960 MemoryProfileInfo.efi
> 12/22/2020 17:52 20,480 VariableInfo.efi
> 4 File(s) 233,472 bytes
> 2 Dir(s)
> Directory of: FS2:\apps\IA32\
> 01/01/1970 01:00 <DIR> r 0 .
> 01/01/1970 01:00 <DIR> r 0 ..
> 12/22/2020 17:53 105,536 AcpiViewApp.efi
> 12/22/2020 17:53 36,096 Cpuid.efi
> 12/22/2020 17:52 17,344 DumpDynPcd.efi
> 12/22/2020 17:52 24,192 MemoryProfileInfo.efi
> 12/22/2020 17:52 30,720 SmiHandlerProfileInfo.efi
> 12/22/2020 17:52 10,880 VariableInfo.efi
> 6 File(s) 224,768 bytes
> 2 Dir(s)
(2a) Before:
> FS2:\> dir apps\*\*.efi
> Directory of: FS2:\apps\*\
> 12/22/2020 17:52 18,752 DumpDynPcd.efi
> 12/22/2020 17:52 34,240 SmiHandlerProfileInfo.efi
> 12/22/2020 17:52 11,456 VariableInfo.efi
> 12/22/2020 17:52 26,304 MemoryProfileInfo.efi
> 12/22/2020 17:53 126,656 AcpiViewApp.efi
> 12/22/2020 17:53 38,784 Cpuid.efi
> 12/22/2020 17:52 32,768 DumpDynPcd.efi
> 12/22/2020 17:52 20,480 VariableInfo.efi
> 12/22/2020 17:52 40,960 MemoryProfileInfo.efi
> 12/22/2020 17:53 139,264 AcpiViewApp.efi
> 12/22/2020 17:52 17,344 DumpDynPcd.efi
> 12/22/2020 17:52 30,720 SmiHandlerProfileInfo.efi
> 12/22/2020 17:52 10,880 VariableInfo.efi
> 12/22/2020 17:52 24,192 MemoryProfileInfo.efi
> 12/22/2020 17:53 105,536 AcpiViewApp.efi
> 12/22/2020 17:53 36,096 Cpuid.efi
> 16 File(s) 714,432 bytes
> 0 Dir(s)
(2b) After:
> FS2:\> dir apps\*\*.efi
> Directory of: FS2:\apps\*\
> 12/22/2020 17:53 126,656 AcpiViewApp.efi
> 12/22/2020 17:53 139,264 AcpiViewApp.efi
> 12/22/2020 17:53 105,536 AcpiViewApp.efi
> 12/22/2020 17:53 38,784 Cpuid.efi
> 12/22/2020 17:53 36,096 Cpuid.efi
> 12/22/2020 17:52 18,752 DumpDynPcd.efi
> 12/22/2020 17:52 32,768 DumpDynPcd.efi
> 12/22/2020 17:52 17,344 DumpDynPcd.efi
> 12/22/2020 17:52 26,304 MemoryProfileInfo.efi
> 12/22/2020 17:52 40,960 MemoryProfileInfo.efi
> 12/22/2020 17:52 24,192 MemoryProfileInfo.efi
> 12/22/2020 17:52 34,240 SmiHandlerProfileInfo.efi
> 12/22/2020 17:52 30,720 SmiHandlerProfileInfo.efi
> 12/22/2020 17:52 11,456 VariableInfo.efi
> 12/22/2020 17:52 20,480 VariableInfo.efi
> 12/22/2020 17:52 10,880 VariableInfo.efi
> 16 File(s) 714,432 bytes
> 0 Dir(s)
(In example (2), note that the sorting is stable; that is, whatever order
is established between identical FileNames by ShellOpenFileMetaArg(), it
is preserved by ShellSortFileList().)
Cc: Philippe Mathieu-Daudé <philmd@redhat.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Zhichao Gao <zhichao.gao@intel.com>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3151
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Zhichao Gao <zhichao.gao@intel.com>
Message-Id: <20210113085453.10168-8-lersek@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Diffstat (limited to 'ShellPkg')
-rw-r--r-- | ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c b/ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c index da2b1acab4..8b97926d7f 100644 --- a/ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c +++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c @@ -489,6 +489,20 @@ PrintLsOutput( PrintSfoVolumeInfoTableEntry(ListHead);
}
+ if (!Sfo) {
+ //
+ // Sort the file list by FileName, stably.
+ //
+ // If the call below fails, then the EFI_SHELL_FILE_INFO list anchored to
+ // ListHead will not be changed in any way.
+ //
+ ShellSortFileList (
+ &ListHead,
+ NULL, // Duplicates
+ ShellSortFileListByFileName
+ );
+ }
+
for ( Node = (EFI_SHELL_FILE_INFO *)GetFirstNode(&ListHead->Link), LongestPath = 0
; !IsNull(&ListHead->Link, &Node->Link)
; Node = (EFI_SHELL_FILE_INFO *)GetNextNode(&ListHead->Link, &Node->Link)
|