You are not logged in.

#1 2005-05-14 09:58:05

dtw
Forum Fellow
From: UK
Registered: 2004-08-03
Posts: 4,439
Website

compare the contents of two folders used as archives

to maintain my repo i use auto archiving of the source stored in the PKGBUILDS of my repo - i keep my patches and stuff there you see for users to dl themselves.

i have a problem with these archives getting out of hand tho - i have a force setting where it forces the dbase to be archived and updated - sometimes i do this 5 times in a row - anyway - that's not important


i tried to write a script to remove these archive folders, a new one is created with the date and time as the name, if they were identical to another archive - i.e. there were no changes - this is what i got, it doesn't really work:

clean_archive ()
{
    unset save_me
    archives=`find $archive_pkg_dir/* -type d | sed "s|$new_archive_pkg_dir||g"`
    for alpha in $archives ; do
        if [ -e $alpha ] ; then
            archives_temp=`echo $archives | sed "s|$alpha ||g"`
            if [ ! -z $(echo $save_me) ] ; then
                archives_temp=`echo $archives_temp | sed "s|$save_me||g"`
            fi
            for beta in $archive_temp ; do
                if [ -e $beta ] ; then

                    echo "change_cnt=0" >.change_cnt
                    echo "absent_cnt=0" >.absent_cnt
                    echo "file_cnt=0" >.file_cnt
                    
                    find $beta -type f | while read file ; do
                        echo "file_cnt=$(($file_cnt+1))" >.file_cnt
                    
                        if [ -e $alpha/$file ] ; then
                            if [[ ! -z $(diff -q $beta/$file $alpha/$file) ]] ; then
                                echo "One or more files in $alpha have been altered in $beta"
                                echo "$alpha should be kept"
                                break 1
                            else
                                source .change_cnt
                                echo "change_cnt=$(($change_cnt+1))" >.change_cnt
                            fi
                        else
                            source .absent_cnt
                            echo "absent_cnt=$(($absent_cnt+1))" >.absent_cnt
                                
                        fi
                    done
                fi
                
                source .absent_cnt
                source .change_cnt
                source .file_cnt
                if [ "$absent_cnt" != "0" ] ; then
                    echo "One or more files in $alpha do not exist in $beta"
                    echo "$alpha should probably be kept"
                elif [ "$change_cnt" != "0" ] ; then
                    dirname=${alpha##*/}
                    echo "$dirname contains $change_cnt of $file_cnt unchanged files and can be deleted"
                fi
                break 1
            done
            if [ -z "$save_me" ] ; then
                save_me=`echo "$alpha"`
            else
                save_me=`echo "$save_me $alpha"`
            fi
        fi
    done
}                            
                            
crap_clean_archive ()
{
    old_archives=`find $source_pkg_dir/.archive/* -mtime +14 -type d`
    recent_archives=`find $archive_pkg_dir/* -mmin -360 -type d | sed "s|$archive_pkg_dir/$time||g"`

    for dir in $recent_archives ; do

        echo "change_cnt=0" >.change_cnt
        echo "file_cnt=0" >.file_cnt

        find $dir -type f | while read file ; do
            source .file_cnt
            echo "file_cnt=$(($file_cnt+1))" >.file_cnt

            latest_file=$new_archive_pkg_dir/${file##*/}
            if [ -e $latest_file ] ; then
                if [[ ! -z $(diff -q $alpha/$file $beta/$file) ]] ; then
                    echo "$dir contains changed files and should be saved"
                    break 1                    
                else
                    source .change_cnt
                    echo "change_cnt=$(($change_cnt+1))" >.change_cnt
                    #rm -r $dir
                fi
            fi                
        done

        source .change_cnt
        source .file_cnt
        if [ "$change_cnt" != "0" ] ; then
            dirname=${dir##*/}
            echo "$dirname contains $change_cnt of $file_cnt unchanged files and can be deleted"
        fi
    done
    for dir in $old_archives ; do
        echo "$dir should be deleted"
    done
}

any ideas?

Offline

#2 2005-05-14 11:36:40

i3839
Member
Registered: 2004-02-04
Posts: 1,185

Re: compare the contents of two folders used as archives

Not sure what you want, but what's wrong with just using diff -rq? Or tar with the -u option?

Offline

#3 2005-05-15 03:19:52

dtw
Forum Fellow
From: UK
Registered: 2004-08-03
Posts: 4,439
Website

Re: compare the contents of two folders used as archives

um - i better take a look at those two options methinks

(/me was secretly hoping to prompt such a response)

Offline

#4 2005-05-15 05:32:20

Snowman
Developer/Forum Fellow
From: Montreal, Canada
Registered: 2004-08-20
Posts: 5,212

Re: compare the contents of two folders used as archives

You can also use a graphical diff. Usually, to compare directories, I use kdiff3 (it's in AUR).

Offline

Board footer

Powered by FluxBB