summaryrefslogtreecommitdiffstats
path: root/patches/0001-tools-mtime.sh-Parse-ls-output-with-read-not-cut.patch
blob: e24ae4ba492b56401e3bfd20a6a43311528e3ec0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
From 0e7634fee188d25165661044c3eb719e333d6ca3 Mon Sep 17 00:00:00 2001
From: Patrick McDermott <patrick.mcdermott@libiquity.com>
Date: Thu, 21 Mar 2019 15:58:08 -0400
Subject: [PATCH] tools/mtime.sh: Parse ls output with read, not cut

cut treats multiple delimiter characters as empty fields, increasing the
field count an indeterminate amount for fields with whitespace delimiter
padding.  BusyBox's ls outputs:

    -rw-r--r--    1 1000     1000          1935 Mar 16 16:31 man/opkbuild.1in

cut counts the owner field, not the month, as field 6.  And fields 7 and
8 are empty.

The shell interpreter's field splitting is better suited for this job,
so just use read.
---
 tools/mtime.sh | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/tools/mtime.sh b/tools/mtime.sh
index c2f9dfa..7207f9e 100755
--- a/tools/mtime.sh
+++ b/tools/mtime.sh
@@ -23,14 +23,19 @@ get_mtime()
 {
 	local file="${1}"
 	shift 1
+	local mode=
+	local links=
+	local owner=
+	local group=
+	local size=
 	local m=
 	local d=
 	local y=
 	local now_m=
 	local now_y=
 
-	read m d y <<-EOF
-		$(LC_ALL=POSIX ls -l "${file}" | cut -d ' ' -f 6-8)
+	read -r mode links owner group size m d y <<-EOF
+		$(LC_ALL=POSIX ls -l "${file}")
 		EOF
 	case "${m}" in
 		'Jan')  m=1;; 'Feb')  m=2;; 'Mar')  m=3;; 'Apr')  m=4;;
-- 
2.1.4