Guys, this might be a bit cheeky for the -dev list, but here goes... I've been playing around with 'pkgutils', the Crux Linux PM software, and while looking into modifying the manpage-compression function in it's build-script to accommodate hard-links, i think i found a couple of things that could shave a few cpu-cycles off of the BLFS 'compressdoc' script - as illustrated in the attached diff.
The cheeky part is this; I'm a total n00b when it comes to scripting, and as such i would like to ask for feedback, not only on the proposed method change, but also on the relative merits of the optional test-constructs (the liberal comments will hopefully clarify what i mean by that), as well as any other observations about scripting good-practices that i might learn from. Regarding the use of a timestamp, that's a bit of a shot-in-the-dark - in my pkgutils use-case, i'll be able to identify modified files simply by their suffix, and won't have a '--force' option at all. I should also state that i haven't tested the modified script on a working system - instead, i've tested the logic and syntax on a small directory containing a handful of files of all the pertinent types, using the 2nd attachment (assuming it doesn't get bounced), linktest.sh. If any of these small modifications are deemed useful for the published script, and you consider my request for guidance outside of a -support list worthy under such circumstances, then i'll be pleased to have been able to give a little something back to the community, and i thank you in advance for your responses. ;) Dean
--- compressdoc.orig 2009-09-20 19:47:25.000000000 +0100
+++ compressdoc 2009-09-21 13:01:43.000000000 +0100
@@ -362,6 +362,11 @@
exit 0
fi
+# Precede loops with timestamp creation for use in avoiding
+# hard-link repeat-processing
+SCRIPTSTART=/tmp/compressdoc_start
+touch $SCRIPTSTART
+
# I know MAN_DIR has only absolute path names
# I need to take into account the localized man, so I'm going recursive
for DIR in $MAN_DIR; do
@@ -396,6 +401,9 @@
echo "<- Leaving ${DIR}/${FILE}." > $DEST_FD1
else # !dir
+ # Only process hard-linked files once
+ if [ $FILE -nt $SCRIPTSTART ]; then continue; fi
+
if ! check_unique "$DIR" "$FILE"; then continue; fi
# With automatic compression, get the uncompressed file size of
@@ -459,17 +467,18 @@
# else if we have a plain file
elif [ -f "$FILE" ]; then
- # Take care of hard-links: build the list of files hard-linked
- # to the one we are {de,}compressing.
- # NB. This is not optimum has the file will eventually be
- # compressed as many times it has hard-links. But for now,
- # that's the safe way.
- inode=`ls -li "$FILE" | awk '{print $1}'`
- HLINKS=`find . \! -name "$FILE" -inum $inode`
-
- if [ -n "$HLINKS" ]; then
- # We have hard-links! Remove them now.
+ # Identify hard-links with 'stat', like 'ls' does
+ # Two test-constructs are possible; ascii or mathematical -
+ # Don't know if they vary, resource-wise..?
+ #if [ `stat -c %h $FILE` \> 1 ]; then # Ascii ("\>" or "-gt" ?)
+ if (( `stat -c %h $FILE` > 1 )); then # Math
+ # We have hard-links! Record and remove them now.
+ # The '-samefile' test removes the need for an 'inode' var.
+ HLINKS=`find . \! -name $FILE -samefile $FILE`
for i in $HLINKS; do rm -f "$i"; done
+ else
+ # Empty string needed to clear values from prior iterations
+ HLINKS=""
fi
# Now take care of the file that has no hard-link
@@ -528,3 +537,6 @@
fi
done # for FILE
done # for DIR
+
+# Clean up timestamp-file
+rm $SCRIPTSTART
linktest.sh
Description: application/shellscript
-- http://linuxfromscratch.org/mailman/listinfo/blfs-dev FAQ: http://www.linuxfromscratch.org/blfs/faq.html Unsubscribe: See the above information page
