Skip to content
Extraits de code Groupes Projets
Valider 9da6db01 rédigé par Elliu's avatar Elliu
Parcourir les fichiers

Properly delete deleted stickers

parent dbed17a1
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -757,7 +757,7 @@ __pack() { ...@@ -757,7 +757,7 @@ __pack() {
if [ ! -f "$SUM_FILE" ]; then if [ ! -f "$SUM_FILE" ]; then
touch $SUM_FILE touch $SUM_FILE
fi fi
local -A hashes unchangedFiles updatedFiles deletedFiles skipFiles local -A hashes unchangedFiles updatedFiles deletedFiles
local TEMP_CHECK=`mktemp --suffix=.stpkg` local TEMP_CHECK=`mktemp --suffix=.stpkg`
md5sum -c $SUM_FILE &>/dev/null >$TEMP_CHECK md5sum -c $SUM_FILE &>/dev/null >$TEMP_CHECK
while read -r _hash _file; do while read -r _hash _file; do
...@@ -766,32 +766,25 @@ __pack() { ...@@ -766,32 +766,25 @@ __pack() {
for i in `cat $TEMP_CHECK | grep ': OK$' | sed 's/\(.*\): OK/\1/'`; do for i in `cat $TEMP_CHECK | grep ': OK$' | sed 's/\(.*\): OK/\1/'`; do
if [ "x$i" = "x" ]; then continue; fi if [ "x$i" = "x" ]; then continue; fi
echo "$FILE is OK"
if [ "x$STPKG_REUPLOAD_SAME_FILE" = "xyes" ]; then if [ "x$STPKG_REUPLOAD_SAME_FILE" = "xyes" ]; then
echo "$FILE is updated"
updatedFiles["$i"]="${hashes["$i"]}" updatedFiles["$i"]="${hashes["$i"]}"
else else
echo "$FILE is unchanged"
unchangedFiles["$i"]="${hashes["$i"]}" unchangedFiles["$i"]="${hashes["$i"]}"
fi fi
echo "unset $FILE"
unset hashes["$i"]
skipFiles[$i]=""
done done
for i in `cat $TEMP_CHECK | grep ': FAILED$' | sed 's/\(.*\): FAILED/\1/'`; do for i in `cat $TEMP_CHECK | grep ': FAILED$' | sed 's/\(.*\): FAILED/\1/'`; do
if [ "x$i" = "x" ]; then continue; fi if [ "x$i" = "x" ]; then continue; fi
updatedFiles["$i"]="${hashes["$i"]}" updatedFiles["$i"]="${hashes["$i"]}"
unset hashes["$i"]
skipFiles[$i]=""
done done
for i in `cat $TEMP_CHECK | grep ': FAILED open or read$' | sed 's/\(.*\): FAILED open or read/\1/'`; do for i in `cat $TEMP_CHECK | grep ': FAILED open or read$' | sed 's/\(.*\): FAILED open or read/\1/'`; do
if [ "x$i" = "x" ]; then continue; fi if [ "x$i" == "x" ]; then continue; fi
deletedFiles["$i"]="${hashes["$i"]}" deletedFiles["$i"]="${hashes["$i"]}"
unset hashes["$i"] echo "add $i to deleted"
skipFiles[$i]=""
done done
local ST_JSON="" local ST_JSON=""
echo "----- Pack -----"
{
for FILE in *; do for FILE in *; do
# Add a ',' only if it's not the first in the array # Add a ',' only if it's not the first in the array
echo -n "$FIRST_IN_ARRAY" >> $TEMP_JSON echo -n "$FIRST_IN_ARRAY" >> $TEMP_JSON
...@@ -801,18 +794,12 @@ __pack() { ...@@ -801,18 +794,12 @@ __pack() {
if [[ -v unchangedFiles[$FILE] ]]; then if [[ -v unchangedFiles[$FILE] ]]; then
STICKER_STATUS="Unchanged" STICKER_STATUS="Unchanged"
ST_JSON=`jq ".stickers[] | select(.body == \"$STICKER_NAME\")" < "$DEST_INDEX"` ST_JSON=`jq ".stickers[] | select(.body == \"$STICKER_NAME\")" < "$DEST_INDEX"`
elif [[ -v deletedFiles[$FILE] ]]; then
STICKER_STATUS="Deleted"
ST_JSON=`jq ".stickers[] | select(.body == \"$STICKER_NAME\")" < "$DEST_INDEX"`
#TODO: remove from checksum?
else else
if [[ -v updatedFiles[$FILE] ]]; then if [[ -v updatedFiles[$FILE] ]]; then
STICKER_STATUS="Updated" STICKER_STATUS="`__yellow Updated`"
#TODO: deleted old checksum
sed -i "/[0-9a-f]\{32\} $FILE/d" $SUM_FILE sed -i "/[0-9a-f]\{32\} $FILE/d" $SUM_FILE
else else
STICKER_STATUS="New" STICKER_STATUS="`__green New`"
if [[ "`md5sum $FILE | sed -e 's/\([0-9a-f]\{32\}\) .*$/\1/'`" = "$(cat $SUM_FILE | grep "$FILE" | sed -e 's/\([0-9a-f]\{32\}\) .*$/\1/')" ]]; then if [[ "`md5sum $FILE | sed -e 's/\([0-9a-f]\{32\}\) .*$/\1/'`" = "$(cat $SUM_FILE | grep "$FILE" | sed -e 's/\([0-9a-f]\{32\}\) .*$/\1/')" ]]; then
die "New file is replacing existing file, that should not be happening" die "New file is replacing existing file, that should not be happening"
fi fi
...@@ -829,24 +816,27 @@ __pack() { ...@@ -829,24 +816,27 @@ __pack() {
FIRST_IN_ARRAY="," FIRST_IN_ARRAY=","
local report="`echo -ne "$ST_JSON" | jq -r '[.body, .url, .info.mimetype, .info.w, .info.h]|join(" ")'` $STICKER_STATUS" local report="`echo -ne "$ST_JSON" | jq -r '[.body, .url, .info.mimetype, .info.w, .info.h]|join(" ")'` $STICKER_STATUS"
echo "$report" echo "$report"
done
for i in "${!deletedFiles[@]}"; do
local STICKER_NAME=$(file_get_name "$i")
ST_JSON=`jq ".stickers[] | select(.body == \"$STICKER_NAME\")" < "$DEST_INDEX"`
sed -i "/[0-9a-f]\{32\} $i/d" $SUM_FILE
local report="`echo -ne "$ST_JSON" | jq -r '[.body, .url, .info.mimetype, .info.w, .info.h]|join(" ")'` `__red Deleted`"
echo "$report"
done
} | column -t
echo "----------------"
done | column -t
# Update the sum file:
# Keep deleted but kept
# Remove deleted and deleted
# Update updated
# Keep unchanged
# Add new
# Create the preview
#montage "$DEST_FOLDER/*.{png,gif}" -background none "$DEST_FOLDER/preview.png"
#echo -ne "# $PACK_NAME\n![Preview of $PACK_NAME](preview.png)" > "$DEST_FOLDER/README.md"
echo -ne "# $PACK_NAME\n(no preview)" > "$DEST_FOLDER/README.md" echo -ne "# $PACK_NAME\n(no preview)" > "$DEST_FOLDER/README.md"
find $DEST_FOLDER -type f \( ! -name "preview.png" -and ! -name "$PACK_NAME.json" -and ! -name '.*.checksums' \) -exec rm {} \; find $DEST_FOLDER -type f \( ! -name "preview.png" -and ! -name "$PACK_NAME.json" -and ! -name '.*.checksums' \) -exec rm {} \;
echo -n "]}" >> $TEMP_JSON echo -n "]}" >> $TEMP_JSON
cat $TEMP_JSON | jq > $DEST_INDEX cat $TEMP_JSON | jq > $DEST_INDEX
echo $TEMP_JSON
# Sort checksums to get better diffs
cat $SUM_FILE | sort | sponge $SUM_FILE
info "Pack created, you can now commit it and create a MR to share it with other users" info "Pack created, you can now commit it and create a MR to share it with other users"
} }
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter