Saturday, 12 July 2014

sort -V : Thanks. That was not helpful

Was just looking at the code in CRiSP which checks whether a new
software update is available. It works by downloading an index
file with version information, and comparing the version
you are running against the master index. Very
simply mechanism.

The current latest release of CRiSP (for linux 32/64 bit systems), is
11.0.32. I am staring at the generated file, and it says "11.0.9". So,
anyone using the "Check for updates" menu in CRiSP will have no idea
that new versions are available.

But why?

Looking at the script to generate the updates - the last time I touched
this was in 2003. I know the script worked at some point in the last
few years. I rarely need to see if I am running the latest version of
CRiSP - so it would not show up as an issue.

The root of the issue lies in how the script gets an index
of all the indexed files:


get_latest ()
{
find . -name crisp-$1-b\*.* -print |
sed -e 's;^./;;' | sort -n | tail -1
}


The "find" command is getting a list of filenames - files are stored
in version directories (eg 11.0.31/). And because the build (b) number
is at the end of the filename, we want to sort all the available versions
of the files, but we want to sort numerically on the version numbers.
This means that something like:


10.0/crisp-linux-b1234.tar.gz
...
11.0/crisp-linux-b2345.tar.gz


would come out in a natural order. The "sort -n" does that in the
shell script above.

Turns out the "sort" people changed the behavior of a numeric sort
in the presence of text: they ignore the attempt to sort! So
instead of generating a list of the most recent versions of CRiSP,
we have a list of the oldest versions available instead. Not very
helpful. A quick scan of "sort"'s switches shows that I needed
to use "-V". I had never seen it before, but am glad it is there and
now generates the correct version information.

This illustrates a problem with all software, that by depending on
other tools and libraries, you will one day be silently broken
and may not realise it.

Post created by CRiSP v11.0.33a-b6754


No comments:

Post a Comment