On 26.02.2024 22:27, Paul D wrote:
diff --git a/package/base-files/files/lib/upgrade/tar.sh
b/package/base-files/files/lib/upgrade/tar.sh
new file mode 100644
index 0000000000..00057dd760
--- /dev/null
+++ b/package/base-files/files/lib/upgrade/tar.sh
@@ -0,0 +1,84 @@
No shebang?
Files /lib/upgrade/*.sh are for including.
+# SPDX-License-Identifier: GPL-2.0-or-later OR MIT
+
+__tar_print_padding() {
+ [ $1 -eq 0 ] || dd if=/dev/zero bs=$1 count=1 2>/dev/null
+}
+
+__tar_make_member() {
+ local name="$1"
+ local content="$2"
+ local username="$3"
+ local groupname="$4"
+ local mtime="$5"
+ local mode=644
+ local uid=0
+ local gid=0
+ local size=${#content}
+ local type=0
+ local link=""
+
recommend that they're ordered here same as struct order:
struct posix_header
{ /* byte offset */
char name[100]; /* 0 */
char mode[8]; /* 100 */
char uid[8]; /* 108 */
char gid[8]; /* 116 */
char size[12]; /* 124 */
char mtime[12]; /* 136 */
char chksum[8]; /* 148 */
char typeflag; /* 156 */
char linkname[100]; /* 157 */
char magic[6]; /* 257 */
char version[2]; /* 263 */
char uname[32]; /* 265 */
char gname[32]; /* 297 */
char devmajor[8]; /* 329 */
char devminor[8]; /* 337 */
char prefix[155]; /* 345 */
/* 500 */
};
I'm not sure about it. In the first place I want code to be easy to
understand and maintain. Using some non-natural order (like messing with
order of argument variables and local variables) will be confusing.
+ local
pad=$'\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1'
+
maybe try:
local pad=$(printf '\1%.0s' $(seq 100))
They produce the same result I believe:
# echo
$'\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1'
| md5sum
59c89925a4ef5bee948db1ec5dc9a4c4 -
# echo $(printf '\1%.0s' $(seq 100)) | md5sum
59c89925a4ef5bee948db1ec5dc9a4c4 -
The first is longer however it avoids two subshell executions. I don't
think there's a single winner here.
_______________________________________________
openwrt-devel mailing list
[email protected]
https://lists.openwrt.org/mailman/listinfo/openwrt-devel