[Xapian-discuss] Atomic DB rebuilds

Sam Liddicott sam at liddicott.com
Tue Oct 5 10:43:24 BST 2004


James Aylett wrote:

>
>That wasn't what I meant - I've had ln -sf fail to unlink the previous
>symlink. And silently fail. This is one of the reasons why I don't
>like using symlinks :-/
> 
>  
>
>>We're getting away from the original issue here.  I doubt Sam is
>>accessing his databases over NFS, and I'd be stunned if he was accessing
>>them over NFS to a Windows server.
>>    
>>
>
>I meant more "I've had this problem (amongst others) with symlinks,
>which is why I'm wary of them", meaning that if you're right about
>rename() (and it would be weird if it didn't work), people should just
>use the things, and at some point I'll get over my phobia ...
>  
>

Here's my report and some sample bash:

export DBDIR=$HOME/xapian
export DBLINK=$HOME/xapian/data

readlink() {
  link="`stat -t -c '%N' \"$1\" 2>/dev/null`" || return
  link="`echo \"$link\" | grep -- '->' 2>/dev/null `" || return
  link="`echo \"$link\" | sed -e 's/^.*-> .\(.*\).$/\1/' 2>/dev/null`" 
|| return
  echo "$link"
}

serial=`date '+%s'`
newdb=$DBLINK.$serial
olddb="`readlink $DBLINK`" && echo fine $olddb || echo no $olddb

dbi2omega blah | \
scriptindex --overwrite $newdb cetoptics.si /dev/fd/0 && \
ln -s $newdb $newdb.lnk && perl -e "rename '$newdb.lnk', '$DBLINK';" && 
rm -fr "$olddb"

I had to use perl's rename because "mv" moved the new link inside the 
target directory of the old link (when it existed) instead of replacing 
the old link. The rename command also became confused.

To be honest so much hacky stuff is going on here with readlink and all 
I should probably do it all in perl

Sam




-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.tartarus.org/pipermail/xapian-discuss/attachments/20041005/417086d3/attachment.htm


More information about the Xapian-discuss mailing list