Hi,

Forget the explanation i gave in my previous mail, it was wrong. The
real problem lies in shell variables and function recursivity: in
clean_directory() $list is not declared as local, so when you have a
subdirectory and call clean_directory() on it, $list is modified.

The following patch fixes this for me but is probably specific to bash.

--- files.sh.orig^I2006-08-04 14:04:19.000000000 +0200
+++ files.sh.local^I2006-08-31 09:34:41.000000000 +0200
@@ -326,7 +326,7 @@
     fi
 
     # First list all the files to process
-    list=$(mktemp /tmp/bm-list.XXXXXX)
+    local list=$(mktemp /tmp/bm-list.XXXXXX)
     for file in $directory/*
     do
         if [ ! -e $file ]; then


On the other hand, is there a good reason to implement clean_directory()
as recursive instead of just using find ? backup-manager-purge seems to
accept full paths so something like this might be better (untested):

clean_directory()
{
    directory="$1"
    purge_date=$(date +%Y%m%d --date "$BM_ARCHIVE_TTL days ago")

#    __debug "Purging archives older than $purge_date"

    if [ ! -d $directory ]; then
        error "Directory given is not found."
    fi

    # First list all the files to process
    list=$(mktemp /tmp/bm-list.XXXXXX)
    find -H $directory -type f -print > $list

    # Then ask bakup-manager-purge what to remove
    for archive in `/usr/bin/backup-manager-purge --ttl=$BM_ARCHIVE_TTL < $list`
    do  
        info "Removing archive \"\$archive\"."
        rm -f $archive
    done
    rm -f $list
}

Or even:

clean_directory()
{
    directory="$1"
    purge_date=$(date +%Y%m%d --date "$BM_ARCHIVE_TTL days ago")

#    __debug "Purging archives older than $purge_date"

    if [ ! -d $directory ]; then
        error "Directory given is not found."
    fi

    # First list all the files to process
    # and ask bakup-manager-purge what to remove
    list=$(mktemp /tmp/bm-list.XXXXXX)
    find -H $directory -type f -print \
        | /usr/bin/backup-manager-purge --ttl=$BM_ARCHIVE_TTL > $list

    for archive in `cat $list`
    do  
        info "Removing archive \"\$archive\"."
        rm -f $archive
    done
    rm -f $list
}

Or even:

clean_directory()
{
    directory="$1"
    purge_date=$(date +%Y%m%d --date "$BM_ARCHIVE_TTL days ago")

#    __debug "Purging archives older than $purge_date"

    if [ ! -d $directory ]; then
        error "Directory given is not found."
    fi

    for archive in ` find -H $directory -type f -print \
        | /usr/bin/backup-manager-purge --ttl=$BM_ARCHIVE_TTL \
        | xargs rm -v -- `
    do
        info "\$archive"
    done
}


Of course all this might be perfectly wrong, because I didn't have my coffee
yet ;)

-- 
Thomas Parmelan


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to