Check-in [5bdc276f57]
Overview
Comment:Added a CPIO input mode for "appfs-mkfs"
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:5bdc276f5794ff801eb26916a17998f098c1e36f
User & Date: rkeene on 2014-11-11 18:38:11
Other Links: manifest | tags
Context
2014-11-11
18:45
Updated to skip files in packages directory check-in: 78bd73355f user: rkeene tags: trunk
18:38
Added a CPIO input mode for "appfs-mkfs" check-in: 5bdc276f57 user: rkeene tags: trunk
17:48
Updated to not continue to reset interpreters forever after a restart request check-in: 65a6138eb6 user: rkeene tags: trunk
Changes

Modified appfs-mkfs from [7f99548475] to [2461e4ba43].

     1      1   #! /usr/bin/env bash
     2      2   
     3      3   if [ "$1" == '--cpio' ]; then
            4  +	shift
            5  +
     4      6   	mode='file'
     5      7   
     6      8   	pkgfile="$1"
     7      9   else
     8     10   	mode='dir'
     9     11   
    10     12   	pkgsdir="$1"
................................................................................
    91     93   			echo "${type},${stat_data},${filename}"
    92     94   		else
    93     95   			echo "${type},${stat_data},${extra_data},${filename}"
    94     96   		fi
    95     97   	done
    96     98   }
    97     99   
          100  +packagelistfile="${appfsdir}/sha1/${RANDOM}${RANDOM}${RANDOM}${RANDOM}${RANDOM}.tmp"
          101  +default_isLatest='0'
          102  +
    98    103   case "${mode}" in
    99    104   	dir)
   100    105   		cd "${pkgsdir}" || exit 1
   101    106   		;;
   102    107   	file)
   103         -		echo 'Unsupported' >&2
   104         -		exit 1
          108  +		oldpackagelistfile="${appfsdir}/sha1/$(cat "${appfsdir}/index" | head -n 1 | cut -f 1 -d ',')"
          109  +
          110  +		workdir="${appfsdir}/.workdir-${RANDOM}${RANDOM}${RANDOM}${RANDOM}"
          111  +		mkdir "${workdir}"
          112  +
          113  +		cat "${pkgfile}" | ( cd "${workdir}" && cpio -imd ) || exit 1
          114  +		cd "${workdir}" || exit 1
          115  +
          116  +		dirdate="$(find . -type f -printf '%TY%Tm%Td%TH%TM.%TS\n' -quit | cut -f 1-2 -d '.')"
          117  +		find . -type d -print0 | xargs -0 -- touch -t "${dirdate}"
          118  +
          119  +		# If this archive contains exactly one package mark it as the latest version
          120  +		chk_package="$(echo *)"
          121  +		if [ -d "${chk_package}" ]; then
          122  +			default_isLatest='1'
          123  +		fi
          124  +
          125  +		cat "${oldpackagelistfile}" 2>/dev/null | (
          126  +			if [ -d "${chk_package}" ]; then
          127  +				sed 's@^\('"{chk_package}"',.*\),1@\1,0@'
          128  +			else
          129  +				cat
          130  +			fi
          131  +		) > "${packagelistfile}"
          132  +
   105    133   		;;
   106    134   esac
   107    135   
   108         -packagelistfile="${appfsdir}/sha1/${RANDOM}${RANDOM}${RANDOM}${RANDOM}${RANDOM}.tmp"
   109    136   for package in *; do
   110    137   	(
   111    138   		cd "${package}" || exit 1
   112    139   
   113    140   		for os_cpuArch in *; do
   114    141   			os="$(echo "${os_cpuArch}" | cut -f 1 -d '-')"
   115    142   			cpuArch="$(echo "${os_cpuArch}" | cut -f 2- -d '-')"
................................................................................
   131    158   						emit_manifest
   132    159   					) > "${manifestfile}"
   133    160   
   134    161   					manifestfile_hash="$(sha1 "${manifestfile}")"
   135    162   					mv "${manifestfile}" "${appfsdir}/sha1/${manifestfile_hash}"
   136    163   
   137    164   					# XXX:TODO: Determine if this is the latest version
   138         -					isLatest='0'
          165  +					isLatest="${default_isLatest:-0}"
   139    166   
   140    167   					echo "${package},${version},${os},${cpuArch},${manifestfile_hash},${isLatest}"
   141    168   				done
   142    169   
   143    170   			)
   144    171   		done
   145    172   	)
          173  +done >> "${packagelistfile}"
          174  +
          175  +# Ensure package list file does not contain duplicate versions
          176  +cat "${packagelistfile}" | awk -F ',' '
          177  +	{
          178  +		package = $1;
          179  +		version = $2;
          180  +		os = $3;
          181  +		cpuArch = $4;
          182  +		hash = $5;
          183  +		isLatest = $6;
          184  +
          185  +		key = package "," version "," os "," cpuArch;
          186  +
          187  +		if (isLatest == "1") {
          188  +			keys_latest[key] = hash;
          189  +		}
          190  +		keys[key] = hash;
          191  +	}
          192  +
          193  +	END{
          194  +		for (key in keys) {
          195  +			if (keys_latest[key] != "") {
          196  +				isLatest = "1";
          197  +				hash = keys_latest[key];
          198  +			} else {
          199  +				isLatest = "0";
          200  +				hash = keys[key];
          201  +			}
   146    202   
   147         -done > "${packagelistfile}"
          203  +			print key "," hash "," isLatest;
          204  +		}
          205  +	}  
          206  +' | sort -u > "${packagelistfile}.new"
          207  +cat "${packagelistfile}.new" > "${packagelistfile}"
          208  +rm -f "${packagelistfile}.new"
          209  +
   148    210   packagelistfile_hash="$(sha1 "${packagelistfile}")"
   149    211   mv "${packagelistfile}" "${appfsdir}/sha1/${packagelistfile_hash}"
   150    212   
   151    213   echo "${packagelistfile_hash},sha1" > "${appfsdir}/index"
          214  +
          215  +case "${mode}" in
          216  +	file)
          217  +		cd /
          218  +		rm -rf "${workdir}"
          219  +		;;
          220  +esac