Diff

Differences From Artifact [7f99548475]:

To Artifact [2461e4ba43]:


1
2
3


4
5
6
7
8
9
10
..
91
92
93
94
95
96
97



98
99
100
101
102
103





104


















105
106
107
108
109
110
111
112
113
114
115
...
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145

146

































147

148
149
150
151







#! /usr/bin/env bash

if [ "$1" == '--cpio' ]; then


	mode='file'

	pkgfile="$1"
else
	mode='dir'

	pkgsdir="$1"
................................................................................
			echo "${type},${stat_data},${filename}"
		else
			echo "${type},${stat_data},${extra_data},${filename}"
		fi
	done
}




case "${mode}" in
	dir)
		cd "${pkgsdir}" || exit 1
		;;
	file)
		echo 'Unsupported' >&2





		exit 1


















		;;
esac

packagelistfile="${appfsdir}/sha1/${RANDOM}${RANDOM}${RANDOM}${RANDOM}${RANDOM}.tmp"
for package in *; do
	(
		cd "${package}" || exit 1

		for os_cpuArch in *; do
			os="$(echo "${os_cpuArch}" | cut -f 1 -d '-')"
			cpuArch="$(echo "${os_cpuArch}" | cut -f 2- -d '-')"
................................................................................
						emit_manifest
					) > "${manifestfile}"

					manifestfile_hash="$(sha1 "${manifestfile}")"
					mv "${manifestfile}" "${appfsdir}/sha1/${manifestfile_hash}"

					# XXX:TODO: Determine if this is the latest version
					isLatest='0'

					echo "${package},${version},${os},${cpuArch},${manifestfile_hash},${isLatest}"
				done

			)
		done
	)



































done > "${packagelistfile}"

packagelistfile_hash="$(sha1 "${packagelistfile}")"
mv "${packagelistfile}" "${appfsdir}/sha1/${packagelistfile_hash}"

echo "${packagelistfile_hash},sha1" > "${appfsdir}/index"










>
>







 







>
>
>





|
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>



<







 







|







>

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>




>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
..
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135

136
137
138
139
140
141
142
...
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#! /usr/bin/env bash

if [ "$1" == '--cpio' ]; then
	shift

	mode='file'

	pkgfile="$1"
else
	mode='dir'

	pkgsdir="$1"
................................................................................
			echo "${type},${stat_data},${filename}"
		else
			echo "${type},${stat_data},${extra_data},${filename}"
		fi
	done
}

packagelistfile="${appfsdir}/sha1/${RANDOM}${RANDOM}${RANDOM}${RANDOM}${RANDOM}.tmp"
default_isLatest='0'

case "${mode}" in
	dir)
		cd "${pkgsdir}" || exit 1
		;;
	file)
		oldpackagelistfile="${appfsdir}/sha1/$(cat "${appfsdir}/index" | head -n 1 | cut -f 1 -d ',')"

		workdir="${appfsdir}/.workdir-${RANDOM}${RANDOM}${RANDOM}${RANDOM}"
		mkdir "${workdir}"

		cat "${pkgfile}" | ( cd "${workdir}" && cpio -imd ) || exit 1
		cd "${workdir}" || exit 1

		dirdate="$(find . -type f -printf '%TY%Tm%Td%TH%TM.%TS\n' -quit | cut -f 1-2 -d '.')"
		find . -type d -print0 | xargs -0 -- touch -t "${dirdate}"

		# If this archive contains exactly one package mark it as the latest version
		chk_package="$(echo *)"
		if [ -d "${chk_package}" ]; then
			default_isLatest='1'
		fi

		cat "${oldpackagelistfile}" 2>/dev/null | (
			if [ -d "${chk_package}" ]; then
				sed 's@^\('"{chk_package}"',.*\),1@\1,0@'
			else
				cat
			fi
		) > "${packagelistfile}"

		;;
esac


for package in *; do
	(
		cd "${package}" || exit 1

		for os_cpuArch in *; do
			os="$(echo "${os_cpuArch}" | cut -f 1 -d '-')"
			cpuArch="$(echo "${os_cpuArch}" | cut -f 2- -d '-')"
................................................................................
						emit_manifest
					) > "${manifestfile}"

					manifestfile_hash="$(sha1 "${manifestfile}")"
					mv "${manifestfile}" "${appfsdir}/sha1/${manifestfile_hash}"

					# XXX:TODO: Determine if this is the latest version
					isLatest="${default_isLatest:-0}"

					echo "${package},${version},${os},${cpuArch},${manifestfile_hash},${isLatest}"
				done

			)
		done
	)
done >> "${packagelistfile}"

# Ensure package list file does not contain duplicate versions
cat "${packagelistfile}" | awk -F ',' '
	{
		package = $1;
		version = $2;
		os = $3;
		cpuArch = $4;
		hash = $5;
		isLatest = $6;

		key = package "," version "," os "," cpuArch;

		if (isLatest == "1") {
			keys_latest[key] = hash;
		}
		keys[key] = hash;
	}

	END{
		for (key in keys) {
			if (keys_latest[key] != "") {
				isLatest = "1";
				hash = keys_latest[key];
			} else {
				isLatest = "0";
				hash = keys[key];
			}

			print key "," hash "," isLatest;
		}
	}  
' | sort -u > "${packagelistfile}.new"
cat "${packagelistfile}.new" > "${packagelistfile}"
rm -f "${packagelistfile}.new"

packagelistfile_hash="$(sha1 "${packagelistfile}")"
mv "${packagelistfile}" "${appfsdir}/sha1/${packagelistfile_hash}"

echo "${packagelistfile_hash},sha1" > "${appfsdir}/index"

case "${mode}" in
	file)
		cd /
		rm -rf "${workdir}"
		;;
esac