From 525bc228caee842a964a20c19b38a2c9d2045b3f Mon Sep 17 00:00:00 2001 From: "darin%meer.net" Date: Thu, 22 Sep 2005 18:18:27 +0000 Subject: [PATCH] Patch for bug 300136 "Update archives may need to contain remove commands" r=chase --- tools/update-packaging/common.sh | 88 +++++++++++++++++++ tools/update-packaging/make_full_update.sh | 55 +++--------- .../make_incremental_update.sh | 61 +++---------- 3 files changed, 111 insertions(+), 93 deletions(-) create mode 100755 tools/update-packaging/common.sh diff --git a/tools/update-packaging/common.sh b/tools/update-packaging/common.sh new file mode 100755 index 000000000000..61fc8e9f6d5e --- /dev/null +++ b/tools/update-packaging/common.sh @@ -0,0 +1,88 @@ +#!/bin/bash +# +# Code shared by update packaging scripts. +# Author: Darin Fisher +# + +# ----------------------------------------------------------------------------- +# By default just assume that these tools exist on our path +MAR=${MAR:-mar} +BZIP2=${BZIP2:-bzip2} +MBSDIFF=${MBSDIFF:-mbsdiff} + +# ----------------------------------------------------------------------------- +# Helper routines + +notice() { + echo $* 1>&2 +} + +get_file_size() { + info=($(ls -l "$1")) + echo ${info[4]} +} + +copy_perm() { + reference="$1" + target="$2" + + if [ -x "$reference" ]; then + chmod 0755 "$target" + else + chmod 0644 "$target" + fi +} + +make_add_instruction() { + f="$1" + is_extension=$(echo "$f" | grep -c 'extensions/.*/') + if [ $is_extension = "1" ]; then + # Use the subdirectory of the extensions folder as the file to test + # before performing this add instruction. + testdir=$(echo "$f" | sed 's/\(extensions\/[^\/]*\)\/.*/\1/') + echo "add-if \"$testdir\" \"$f\"" + else + echo "add \"$f\"" + fi +} + +make_patch_instruction() { + f="$1" + is_extension=$(echo "$f" | grep -c 'extensions/.*/') + if [ $is_extension = "1" ]; then + # Use the subdirectory of the extensions folder as the file to test + # before performing this add instruction. + testdir=$(echo "$f" | sed 's/\(extensions\/[^\/]*\)\/.*/\1/') + echo "patch-if \"$testdir\" \"$f.patch\" \"$f\"" + else + echo "patch \"$f.patch\" \"$f\"" + fi +} + +append_remove_instructions() { + listfile="$1" + if [ -f "$listfile" ]; then + # Map spaces to pipes so that we correctly handle filenames with spaces. + files=($(cat "$listfile" | tr " " "|")) + num_files=${#files[*]} + for ((i=0; $i<$num_files; i=$i+1)); do + f=$(echo ${files[$i]} | tr "|" " " | sed 's/^ *\(.*\) *$/\1/') + # Exclude any blank lines or any lines ending with a slash, which indicate + # directories. The updater doesn't know how to remove entire directories. + if [ -n "$f" ]; then + if [ $(echo "$f" | grep -c '\/$') = 0 ]; then + echo "remove \"$f\"" + else + notice "ignoring remove instruction for directory: $f" + fi + fi + done + fi +} + +# List all files in the current directory, stripping leading "./" +# Skip the channel-prefs.js file as it should not be included in any +# generated MAR files (see bug 306077). +list_files() { + find . -type f ! -name "channel-prefs.js" | sed 's/\.\/\(.*\)/"\1"/' +} diff --git a/tools/update-packaging/make_full_update.sh b/tools/update-packaging/make_full_update.sh index c662feffa9c5..db3ce95a6d3b 100755 --- a/tools/update-packaging/make_full_update.sh +++ b/tools/update-packaging/make_full_update.sh @@ -4,15 +4,12 @@ # Author: Darin Fisher # -# ----------------------------------------------------------------------------- -# By default just assume that these tools exist on our path -MAR=${MAR:-mar} -BZIP2=${BZIP2:-bzip2} +. $(dirname "$0")/common.sh # ----------------------------------------------------------------------------- print_usage() { - echo "Usage: $(basename $0) [OPTIONS] ARCHIVE DIRECTORY" + notice "Usage: $(basename $0) [OPTIONS] ARCHIVE DIRECTORY" } if [ $# = 0 ]; then @@ -22,48 +19,17 @@ fi if [ $1 = -h ]; then print_usage - echo "" - echo "The contents of DIRECTORY will be stored in ARCHIVE." - echo "" - echo "Options:" - echo " -h show this help text" - echo "" + notice "" + notice "The contents of DIRECTORY will be stored in ARCHIVE." + notice "" + notice "Options:" + notice " -h show this help text" + notice "" exit 1 fi # ----------------------------------------------------------------------------- -copy_perm() { - reference="$1" - target="$2" - - if [ -x "$reference" ]; then - chmod 0755 "$target" - else - chmod 0644 "$target" - fi -} - -make_add_instruction() { - f="$1" - is_extension=$(echo "$f" | grep -c 'extensions/.*/') - if [ $is_extension = "1" ]; then - # Use the subdirectory of the extensions folder as the file to test - # before performing this add instruction. - testdir=$(echo "$f" | sed 's/\(extensions\/[^\/]*\)\/.*/\1/') - echo "add-if \"$testdir\" \"$f\"" - else - echo "add \"$f\"" - fi -} - -# List all files in the current directory, stripping leading "./" -# Skip the channel-prefs.js file as it should not be included in any -# generated MAR files (see bug 306077). -list_files() { - find . -type f ! -name "channel-prefs.js" | sed 's/\.\/\(.*\)/"\1"/' -} - archive="$1" targetdir="$2" workdir="$targetdir.work" @@ -82,7 +48,7 @@ num_files=${#files[*]} for ((i=0; $i<$num_files; i=$i+1)); do f=${files[$i]} - echo " processing $f" + notice "processing $f" make_add_instruction "$f" >> $manifest @@ -94,6 +60,9 @@ for ((i=0; $i<$num_files; i=$i+1)); do targetfiles="$targetfiles \"$f\"" done +# Append remove instructions for any dead files. +append_remove_instructions "$targetdir/removed-files" >> $manifest + $BZIP2 -z9 "$manifest" && mv -f "$manifest.bz2" "$manifest" eval "$MAR -C \"$workdir\" -c output.mar $targetfiles" diff --git a/tools/update-packaging/make_incremental_update.sh b/tools/update-packaging/make_incremental_update.sh index 3fc02b8d3b92..f2b514f92637 100755 --- a/tools/update-packaging/make_incremental_update.sh +++ b/tools/update-packaging/make_incremental_update.sh @@ -4,16 +4,12 @@ # Author: Darin Fisher # -# ----------------------------------------------------------------------------- -# By default just assume that these tools exist on our path -MAR=${MAR:-mar} -BZIP2=${BZIP2:-bzip2} -MBSDIFF=${MBSDIFF:-mbsdiff} +. $(dirname "$0")/common.sh # ----------------------------------------------------------------------------- print_usage() { - echo "Usage: $(basename $0) [OPTIONS] ARCHIVE FROMDIR TODIR" + notice "Usage: $(basename $0) [OPTIONS] ARCHIVE FROMDIR TODIR" } if [ $# = 0 ]; then @@ -23,55 +19,17 @@ fi if [ $1 = -h ]; then print_usage - echo "" - echo "The differences between FROMDIR and TODIR will be stored in ARCHIVE." - echo "" - echo "Options:" - echo " -h show this help text" - echo "" + notice "" + notice "The differences between FROMDIR and TODIR will be stored in ARCHIVE." + notice "" + notice "Options:" + notice " -h show this help text" + notice "" exit 1 fi # ----------------------------------------------------------------------------- -get_file_size() { - info=($(ls -l "$1")) - echo ${info[4]} -} - -make_add_instruction() { - f="$1" - is_extension=$(echo "$f" | grep -c 'extensions/.*/') - if [ $is_extension = "1" ]; then - # Use the subdirectory of the extensions folder as the file to test - # before performing this add instruction. - testdir=$(echo "$f" | sed 's/\(extensions\/[^\/]*\)\/.*/\1/') - echo "add-if \"$testdir\" \"$f\"" - else - echo "add \"$f\"" - fi -} - -make_patch_instruction() { - f="$1" - is_extension=$(echo "$f" | grep -c 'extensions/.*/') - if [ $is_extension = "1" ]; then - # Use the subdirectory of the extensions folder as the file to test - # before performing this add instruction. - testdir=$(echo "$f" | sed 's/\(extensions\/[^\/]*\)\/.*/\1/') - echo "patch-if \"$testdir\" \"$f.patch\" \"$f\"" - else - echo "patch \"$f.patch\" \"$f\"" - fi -} - -# List all files in the current directory, stripping leading "./" -# Skip the channel-prefs.js file as it should not be included in any -# generated MAR files (see bug 306077). -list_files() { - find . -type f ! -name "channel-prefs.js" | sed 's/\.\/\(.*\)/"\1"/' -} - archive="$1" olddir="$2" newdir="$3" @@ -144,6 +102,9 @@ for ((i=0; $i<$num_newfiles; i=$i+1)); do archivefiles="$archivefiles \"$f\"" done +# Append remove instructions for any dead files. +append_remove_instructions "$newdir/removed-files" >> $manifest + $BZIP2 -z9 "$manifest" && mv -f "$manifest.bz2" "$manifest" eval "$MAR -C \"$workdir\" -c output.mar $archivefiles"