Code: Select all
#! /usr/bin/env python
# distmaint.py -- Portage distfiles cleaning and management tool
# Version 0.1
# Copyright 2005 Sandy McGuffog.
# Distributed under the GNU Public License v2
# Comments/bugs to mcguffogl@bigfoot.com
import sys
import getopt
import os
import os.path
import string
import shutil
import glob
import portage
# ===========================================================================
# If Your Portage installation is non-standard, alter these.......
# Note this only aplies if we can't find location from the portage settings
# ===========================================================================
sPortage = '/usr/portage'
sOverlay = '/usr/local/portage'
sDirstFiles = '/usr/portage/distfiles'
sDigestDirectory = '/files'
# ===========================================================================
# End of area to alter.......
# ===========================================================================
# Ugly, nasty global variables.....
bVerbose = False
bPretend = False
def usage():
print 'distmaint V0.1'
print 'Usage: distmaint [OPTIONS] or python distmaint [OPTIONS]'
print 'Scan the portage database for source files required for any and'
print 'all ebuilds, then either (a) delete orphan (non-required files)'
print 'from portage/distfiles or (b) move ophan files to another directory'
print 'or (c) scan for and get required files from another location'
print
print 'Mandatory arguments to long options are mandatory for short options too.'
print ' -d, --delete delete orphan files in portage/distfiles'
print ' -h, --help display this help and exit'
print ' -v, --verbose explain what is being done. In (much) detail.'
print ' -p, --pretend instead of actually deleteing or moving files,'
print ' just display what would be done'
print ' -n, --number=N limit the number of files moved/deleted to N'
print ' -g, --get=DIRECTORY scan DIRECTORY for required files, and copy'
print ' to portage/distfiles if found'
print ' -m, --move=DIRECTORY move orphan files to DIRECTORY rather than'
print ' delete them'
print
print 'Examples:'
print ' distmaint'
print ' Scan all ebuild files, build a list of required source files for'
print ' all ebuilds, and compare that list to what is contained in distfiles'
print ' distmaint -d'
print ' Deletes all orphan files in portage/distfiles'
print ' distmaint -dpn 10'
print ' Outputs the names of the orphan files in portage/distfiles that would'
print ' be deleted, limiting the number to 10'
print ' distmaint -m /home/samba/public -n 10'
print ' Moves the first 10 orphan files in portage/distfiles to'
print ' the /home/samba/public directory'
print ' distmaint -g "/mnt/WinXP/Documents and Settings/All Users/Documents/Programs/Gentoo/distfiles"'
print ' Copy all files required by any ebuild that are available in the'
print ' /mnt/WinXP/..... directory to the portage distfiles directory'
print
def IOError(sMessage):
print '*** File I/O error occured '+sMessage+'; may be a permisioning problem'
sys.exit(2)
def addFileList(sDirectory, dList):
# We could us glob.glob('/usr/portage/*/*/files/digest-*') here, it would be
# quicker, but walk is more robust versus directory structure changes
for root, dirs, files in os.walk(sDirectory):
for individualFile in files:
if individualFile[0:7] == 'digest-':
try:
fInputFile = open(os.path.join(root, individualFile), 'r')
bDone = False
while not bDone:
sLine = fInputFile.readline()
if not sLine:
bDone = True
else:
tokens = string.split(sLine)
if len(tokens) == 4 and tokens[0] == 'MD5':
if bVerbose:
print 'Adding file', tokens[2], 'length', tokens[3], 'from', root[(len(sDirectory)+1):(len(root) - len(sDigestDirectory))], 'to wish list'
dList[tokens[2]] = root[(len(sPortage)+1):(len(root) - len(sDigestDirectory))]
except:
IOError('reading file '+os.path.join(root, individualFile))
def main():
#Need to declare these global here, else python just creates local variables instead of using the globals....
global bVerbose
global bPretend
bVerbose = False
bDelete = False
bMove = False
bPretend = False
bGet = False
bLimit = False
iLimit = 1000000000
iLimitStore = iLimit
sMoveDir = ''
try:
lOpts, lArgs = getopt.getopt(sys.argv[1:], "dhvpn:g:m:", ["help", "delete", "pretend", "number=", "get=", "move="])
except (getopt.GetoptError):
# print help information and exit:
usage()
sys.exit(2)
for sOption, sArgument in lOpts:
if sOption == "-v":
bVerbose = True
if sOption in ("-h", "--help"):
usage()
sys.exit()
if sOption in ("-d", "--delete"):
bDelete = True
if sOption in ("-p", "--pretend"):
bPretend = True
if sOption in ("-g", "--get"):
bGet = True
sGetDirectory = sArgument;
if not os.path.isdir(sGetDirectory):
print sGetDirectory, 'is not an existing directory'
usage()
sys.exit(2)
if sOption in ("-n", "--number"):
bLimit = True
iLimit = int(sArgument);
iLimitStore = iLimit
if sOption in ("-m", "--move"):
bMove = True
sMoveDir = sArgument;
if not os.path.isdir(sMoveDir):
print sMoveDir, 'is not an existing directory'
usage()
sys.exit(2)
if bLimit:
print '*** Limiting number of files moved, copied or deleted to', iLimit
if bDelete and bPretend:
print '*** Note, pretend overrides delete; no files will be deleted; to delete run without the -p'
if bMove and bPretend:
print '*** Note, pretend overrides move; no files will be moved; to move run without the -p'
cPortdir = portage.settings['PORTDIR']
cDistdir = portage.settings['DISTDIR']
cOverlaydir = portage.settings['PORTDIR_OVERLAY']
if len(cPortdir) > 2 and len(cDistdir) > 2:
#assume we got good data from portage
sPortage = cPortdir
sOverlay = cOverlaydir
sDirstFiles = cDistdir
else:
print '*** Warning - could not get file locations from Portage - using defaults:'
print 'PORTDIR =', sPortage
print 'DISTDIR =', sDirstFiles
print 'PORTDIR_OVERLAY =', sOverlay
#sPortage = '/usr/portage/dev-java'
dWishList = {}
print 'Searching Portage for files to add to the wish list; this may take several minutes.............'
addFileList(sPortage, dWishList)
if not sOverlay == '':
addFileList(sOverlay, dWishList)
print 'Total of', len(dWishList), 'files added to the wishlist'
print 'Searching distfiles for existing files.............'
lSortedDistFiles = glob.glob(os.path.join(sDirstFiles, '*'))
lSortedDistFiles.sort()
if bGet:
print 'Checking for files to get'
iTotalCopied = 0
iTotalFiles = 0
for root, dirs, files in os.walk(sGetDirectory):
for individualFile in files:
iTotalFiles = iTotalFiles + 1
try:
if (iLimit > 0 or not bLimit) and individualFile in dWishList and not (os.path.join(sDirstFiles, individualFile)) in lSortedDistFiles:
iLimit = iLimit - 1
if bPretend:
try:
if os.access(os.path.join(root, individualFile), os.R_OK):
(st_mode, st_ino, st_dev, st_nlink, st_uid, st_gid, st_size, st_atime , st_mtime, st_ctime) = os.stat(os.path.join(root, individualFile))
iTotalCopied = iTotalCopied + st_size
except:
IOError('attempting to access file '+sExistingFile)
print 'Would copy', os.path.join(root, individualFile), 'to', sDirstFiles, 'for package', dWishList[individualFile]
else:
#Copy2 preserves dates and times
shutil.copy2(os.path.join(root, individualFile), sDirstFiles)
print 'Copied', os.path.join(root, individualFile), 'to', sDirstFiles
except:
IOError('attempting to copy file '+os.path.join(root, individualFile)+' to '+sDirstFiles)
if bPretend:
print iTotalCopied/1024, 'KB in',iLimitStore - iLimit, 'files out of a total of', iTotalFiles,'files considered would be copied from', sGetDirectory
else:
# Here its either move or delete
print 'Matching the wish list to the existing files.............'
iFound = 0
iNotFound = 0
iTotalDeleted = 0
for sExistingFile in lSortedDistFiles:
(sHead, sTail) = os.path.split(sExistingFile)
if os.path.isdir(sExistingFile):
if bVerbose:
print sTail, 'is a directory - ignoring'
elif sTail in dWishList:
if bVerbose:
print 'Found', sTail, 'in wishlist'
iFound = iFound+1
else:
if bVerbose:
print 'Did not find', sTail, 'in wishlist'
if iLimit > 0 or not bLimit:
iLimit = iLimit - 1
if bPretend:
try:
if os.access(sExistingFile, os.R_OK):
(st_mode, st_ino, st_dev, st_nlink, st_uid, st_gid, st_size, st_atime , st_mtime, st_ctime) = os.stat(sExistingFile)
iTotalDeleted = iTotalDeleted + st_size
except:
IOError('attempting to access file '+sExistingFile)
if bDelete:
print 'Would delete', sExistingFile
elif bMove:
print 'Would move', sExistingFile, 'to', os.path.join(sMoveDir, sTail)
else:
if bDelete:
try:
os.remove(sExistingFile)
except:
IOError('attempting to delete file '+sExistingFile)
print 'Deleted', sExistingFile
elif bMove:
try:
shutil.move(sExistingFile, os.path.join(sMoveDir, sTail))
except:
IOError('attempting to move file '+sExistingFile+' to '+os.path.join(sMoveDir, sTail))
print 'Moved', sExistingFile, 'to', os.path.join(sMoveDir, sTail)
iNotFound = iNotFound+1
print 'Found',iFound, 'required files and', iNotFound, 'orphan files'
if bPretend:
print iTotalDeleted/1024, 'KB could be freed up from the', iLimitStore - iLimit, 'files considered for deletion or movement'
print
if __name__ == '__main__':
main()

Thanks, will try it outsandymc wrote:This is yet another tool for cleaning and maintaining the distfiles directory. Although there are others that are quicker and smaller in size, this does some things the various other versions on the forum don't do:
man you, drunk?gspir2004 wrote: <lots of text>
Code: Select all
#!/bin/bash
#distclean
case $1 in
-p | --pretend)
remove="no"
;;
-a | --ask)
remove="ask"
;;
"")
remove="yes"
;;
-h | --help | *)
echo -e "distclean : prune stale distfiles"
echo -e ""
echo -e "Usage:"
echo -e "distclean -p|--pretend\t: do not delete"
echo -e "distclean -a|--ask \t: ask for confirmation"
echo -e "distclean -h|--help \t: this help"
echo -e "distclean \t: clean all stale distfiles"
echo -e ""
echo -e ""
exit
;;
esac
#db and distfile settings
echo "Reading Portage environment..."
VDB_PATH=$(portageq vdb_path)
DISTDIR=$(portageq distdir)
#if Control-C pressed restore distfile perms
function restoreperm(){
echo -e "\n\nExiting due to signal.\n\n"
chmod -t $DISTDIR/*
exit 1
}
trap restoreperm SIGHUP SIGINT SIGQUIT SIGTERM SIGKILL
#mark all as stale
chmod +t $DISTDIR/*
#reverse perms for current package distfiles
echo "Reading package database..."
ENV=`find $VDB_PATH -type f -iname 'environment.bz2'`
for x in $ENV ; do
KEEP=`bzcat ${x} | sed -n '1s/A=//gp'`
for y in ${KEEP//\'/} ; do
[ -e "${DISTDIR}/${y}" ] && chmod -t ${DISTDIR}/${y}
done
done
#do the stuff
case $remove in
yes)
find $DISTDIR -perm +1000 -type f -maxdepth 1 \
-printf "\\033[32m<<\\033[00m %f \n" \
-exec rm -f \{\} \;
echo -e "\nDone.\n\n"
;;
ask)
find $DISTDIR -perm +1000 -type f -maxdepth 1 \
-printf "[ \\033[32m%6k kB\\033[00m ] " \
-ok rm -f \{\} \;
echo -e "\nDone.\n\n"
;;
no | *)
find $DISTDIR -perm +1000 -type f -maxdepth 1 \
-printf "[ \\033[32m%6k kB\\033[00m ] %f\n"
;;
esac
#restore remaining file perms
chmod -t $DISTDIR/*
you haven't tried with a 56k modem where speed rarely tops a whopping 10k and pay half hour of your salaray for one minute phone connection. have you? It is about efficiency.stalynx wrote:my own code
works pretty good.Code: Select all
#!/bin/sh cd /usr/portage/distfiles rm *
Code: Select all
You haven't tried with a 56k modem where speed rarely tops a whopping 10k and pay half hour of your salaray for one minute phone connection. have you? It is about efficiency.what does a modem and money have to do with running a remote script?alkan wrote:you haven't tried with a 56k modem where speed rarely tops a whopping 10k and pay half hour of your salaray for one minute phone connection. have you? It is about efficiency.stalynx wrote:my own code
works pretty good.Code: Select all
#!/bin/sh cd /usr/portage/distfiles rm *
Code: Select all
#!/bin/bash
# cleandu V2.0 - pur jus de chaussettes ;)
# compare les fichiers nécessaires à la compilation des packages installés
# à la liste de ceux qui ont été utilisés pour les compiler.
# sert aussi, en réseau, pour nettoyer les fichiers sources inutiles
# s'il y a un répertoire distifiles partagé.
echo -e "\n>>> Initialising necessary things..."
emerge info > /tmp/info.txt
DISTDIR=$(grep ^DISTDIR= /tmp/info.txt | cut -d'"' -f2)
PORTDIR=$(grep ^PORTDIR= /tmp/info.txt | cut -d'"' -f2)
PORTTMP=$(grep ^PORTAGE_TMPDIR= /tmp/info.txt | cut -d'"' -f2)
RPT=$DISTDIR/.cleandu/$HOSTNAME
TMP=$PORTTMP/cleandu.tmp
rm -rf /tmp/info.txt
[ ! -e $RPT ] && mkdir -p $RPT
[ ! -d $RPT ] && \
echo "error: !!! $RPT MUST be a dir !!!" \
&& exit 0
[ ! -e $TMP ] && mkdir -p $TMP
[ ! -d $TMP ] && \
echo "error: !!! $TMP MUST be a dir !!!" \
&& exit 0
rm -rf $RPT/* $TMP/*
# liste des ebuilds pour les packages installés.
echo -e "\n>>> Creating packages lists..."
ls /var/db/pkg/*/* -d --color=none | sed "s_/var/db/pkg/__" | sort > $TMP/qpkgv.txt
# liste des sources nécessaires à la compilation.
echo -e "\n>>> Building list of sources needed now to build packages installed..."
echo -n "emerge -pf " > $TMP/pfetch.sh
for fich in $(cat $TMP/qpkgv.txt)
do
echo -n "=$fich " >> $TMP/pfetch.sh
done
echo -n " > $TMP/files_tmp.txt 2>&1" >> $TMP/pfetch.sh
/bin/bash $TMP/pfetch.sh
cat $TMP/files_tmp.txt | cut -d' ' -f1 | gawk -F'/' '{ if (NF > 1) {print $NF} }' | sort -u > $RPT/files_needed.txt
# liste des sources utilisées.
echo -e "\n>>> Building list of sources used to build packages on this gentoo box..."
bzcat /var/db/pkg/*/*/environment.bz2 | grep ^A= | cut -d'=' -f2 | cut -d"'" -f2 | gawk -F' ' '{ for (n=1; n <=NF; n++ ) print $n }' | sort -u > $RPT/files_from_env.txt
echo -e "\n>>> Working on files...\n"
echo "Left files used - Right files needed"
diff $RPT/files_from_env.txt $RPT/files_needed.txt --side-by-side --suppress-common-lines
Code: Select all
#!/bin/bash
echo -e "\n>>> Initialisings necessary things..."
emerge info > /tmp/info.txt
DISTDIR=$(grep ^DISTDIR= /tmp/info.txt | cut -d '"' -f 2)
PORTDIR=$(grep ^PORTDIR= /tmp/info.txt | cut -d '"' -f 2)
PORTTMP=$(grep ^PORTAGE_TMPDIR= /tmp/info.txt | cut -d '"' -f 2)
RPT=$DISTDIR/.cleandu
TMP=$PORTTMP/cleandu.tmp
rm -rf /tmp/info.txt
[ ! -d $RPT ] && \
echo "error: !!! $RPT you MUST run cleandu before running del_oldfiles !!!" \
&& exit 0
rm -rf $RPT/dist.txt $RPT/needed.txt
for fich in $(ls $RPT)
do
[ -d $RPT/$fich ] && \
[ -e $RPT/$fich/files_from_env.txt ] && \
cat $RPT/$fich/files_from_env.txt >> $RPT/files_needed.txt
done
cat $RPT/files_needed.txt | sort -u >> $RPT/needed.txt
echo -e "\n>>> Building distfiles list..."
ls -I cvs-src $DISTDIR | sort > $RPT/dist.txt
rm -rf $RPT/files_*
for fich in $(cat $RPT/dist.txt)
do
grep $fich $RPT/needed.txt 2>&1 >/dev/null
if [[ $? != 0 && -e $RPT/../$fich ]]; then
echo -en "\n$fich not needed! Delete ? (y/n): \t"
read y
if [[ $y = "y" || $y = "Y" ]]; then
rm -rf $RPT/../$fich
echo "$fich removed..."
else
echo "$fich remain..."
fi;
fi;
done
Code: Select all
#!/bin/bash
l_sources=$1
[[ $l_sources == "" ]] && echo "usage: $0 \"file1 file2 ...\"" && exit 0
ls /var/db/pkg/*/* -d --color=none | sed "s_/var/db/pkg/__" | sort > /tmp/ebuilds_list_full.txt
echo ">> Finding ebuilds..."
for src in $l_sources
do
for pkg in $(cat /tmp/ebuilds_list_full.txt)
do
bzcat /var/db/pkg/$pkg/environment.bz2 | grep -q $src
[ $? == 0 ] && echo "$src in $pkg"
done
done
Code: Select all
#!/bin/bash
ls /var/db/pkg/*/* -d --color=none | sed "s_/var/db/pkg/__" | sort > /tmp/ebuilds_list_full.txt
cat /tmp/ebuilds_list_full.txt | sed "s/-[0-9].*//" > /tmp/liste_packages.txt
echo -n "emerge -up " > /tmp/ebuild_update.sh
for pkg in $(cat /tmp/liste_packages.txt)
do
echo -n "$pkg " >> /tmp/ebuild_update.sh
done
echo ">> Update pretend... ;)"
sh /tmp/ebuild_update.sh
Code: Select all
#!/bin/bash
PORTDIR=$(emerge info | grep ^PORTDIR= | cut -d'"' -f2)
PORTDIR_OVERLAY=$(emerge info | grep ^PORTDIR_OVERLAY= | cut -d'"' -f2)
MY_PATH="$PORTDIR $PORTDIR_OVERLAY"
#some cleaning ;)
[ -f /tmp/ebuilds_wrongs_list.txt ] && rm -f /tmp/ebuilds_wrongs_list.txt
ls /var/db/pkg/*/* -d --color=none | sed "s_/var/db/pkg/__" | sort > /tmp/ebuilds_list_full.txt
echo "Searching for wrongs ebuilds..."
for ligne in $(cat /tmp/ebuilds_list_full.txt)
do
status=1
for ac_dir in $MY_PATH
do
pkg=$(echo $ligne | sed "s/-[0-9].*//")
ebld=$(echo $ligne | cut -d'/' -f2)
[ -f $ac_dir/$pkg/$ebld.ebuild ] && status=0
done
[ $status != 0 ] && echo -n "$ligne " >> /tmp/ebuilds_wrongs_list.txt
done
#report result ;)
if [ -f /tmp/ebuilds_wrongs_list.txt ] ; then
echo "These ebuilds are not in portage tree: try to update them manualy or unmerge them..."
for ligne in $(cat /tmp/ebuilds_wrongs_list.txt)
do
echo $ligne
done
else
echo "All ebuilds are OK ;)"
fi
Code: Select all
#!/bin/bash
old=""
in_dupli=0
dupli=0
ls /var/db/pkg/*/* -d --color=none | sed "s_/var/db/pkg/__" | sort > /tmp/ebuilds_list_full.txt
cat /tmp/ebuilds_list_full.txt | sed "s/-[0-9].*//" | sort > /tmp/liste_packages.txt
for pkg in $(cat /tmp/liste_packages.txt)
do
if [[ $pkg == $old ]]; then
dupli=1
in_dupli=1
else
dupli=0
fi
if [[ $in_dupli == 1 ]] && [[ $dupli == 0 ]]; then
grep $old-[0-9] /tmp/ebuilds_list_full.txt
in_dupli=0
fi
old=$pkg
done
Code: Select all
yacleaner-0.3: please tell me what to do.
Usage:
yacleaner-0.3 [ options ] [ action ] < dist | binpkg | worktmp | log | all >
yacleaner-0.3 --help
Options: [ --ask | --nocolor | --pretend | --verbose ]
Actions: [ --delete ]
For more help try 'yacleaner-0.3 --help'
Code: Select all
#!/bin/sh
filesneeded=`find /usr/portage/ -name digest-\* -type f | xargs awk '{print $3}' | sort -u`
find /usr/portage/distfiles/ -type f -maxdepth 1 -printf "%f\n" | while read a
do
if [[ ! "${filesneeded}" =~ "${a}" ]]
then
echo /usr/portage/distfiles/${a}
fi
done | xargs rm -fCode: Select all
#!/bin/sh
f=/tmp/filesneeded.txt
e=/tmp/existingfiles.txt
find /usr/portage/ -name digest-\* -type f | xargs awk '{print $3}' | sort -u > ${f}
find /usr/portage/distfiles/ -type f -maxdepth 1 -printf "%f\n" | sort > ${e}
comm -2 -3 ${e} ${f} | sed 's%^%/usr/portage/distfiles/%' | xargs rm -f
rm -f ${e} ${f}
Code: Select all
FILES_PROBABLY_NEEDED=/var/tmp/probably_needed
FILES_NOT_NEEDED=/var/tmp/not_neededCode: Select all
/**
* syntax: ./vercompare <v1> <v2>
* Returns 1 if v1 is a newer version number than v2, 2 if v2 is a newer
* version than v1, 0 otherwise (both should be equivalant)
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <ctype.h>
/**
* Returns 1 if str is made only of digit, 0 otherwise
*/
static int isDigit(const char *str);
/**
* Returns 1 if str is made only of alpha characters, 0 otherwise
*/
static int isAlpha(const char *str);
/**
* Returns 1 if v1 > v2, 2 if v2 > v1, 0 otherwise. Comparison is not a simple
* numeric comparison, it's about version numbering
*/
static int vercmp(char *v1, char *v2);
static int isDigit(const char *str) {
size_t i = 0;
while(str[i] != '\0') {
if(!isdigit(str[i])) {
return 0;
}
i++;
}
return 1;
}
static int isAlpha(const char *str) {
size_t i = 0;
while(str[i] != '\0') {
if(!isalpha(str[i])) {
return 0;
}
i++;
}
return 1;
}
static int vercmp(char *v1, char *v2) {
char *b1, *b2; /* tmp buffers */
size_t maxlen, p1, p2;
long a1, a2;
#ifndef NDEBUG
printf("v1=%s v2=%s\n", v1, v2);
#endif
maxlen = strlen(v1) > strlen(v2) ? strlen(v1) : strlen(v2);
b1 = malloc(maxlen + 1); /* this way, we won't bother to realloc */
assert(b1 != NULL);
b2 = malloc(maxlen + 1);
assert(b2 != NULL);
while(v1[0] != '\0' && v2[0] != '\0') {
/* read some numbers from v1 and v2 */
p1 = strspn(v1, "0123456789");
p2 = strspn(v2, "0123456789");
/* if we didn't find anything number, let's just take one char */
if(p1 == 0)
p1 = 1;
if(p2 == 0)
p2 = 1;
strncpy(b1, v1, p1);
strncpy(b2, v2, p2);
/* make sure the tmp buffers are NULL terminated once we filled them */
b1[p1 + 1] = '\0';
b2[p2 + 1] = '\0';
#ifndef NDEBUG
printf("token v1=%s token v2=%s\n", b1, b2);
#endif
if(isDigit(b1) && isDigit(b2)) {
a1 = atol(b1);
a2 = atol(b2);
if(a1 > a2) {
#ifndef NDEBUG
puts(">>> v1 > v2 !");
#endif
free(b1);
free(b2);
return 1;
} else if(a1 < a2) {
#ifndef NDEBUG
puts(">>> (i) v1 < v2");
#endif
free(b1);
free(b2);
return 2;
} else {
#ifndef NDEBUG
puts("... (i) v1 =? v2");
#endif
}
} else if(isAlpha(b1) && isAlpha(b2)) {
a1 = strcmp(b1, b2);
if(a1 > 0) {
#ifndef NDEBUG
puts(">>> (s) v1 > v2");
#endif
free(b1);
free(b2);
return 1;
} else if(a1 < 0) {
#ifndef NDEBUG
puts(">>> (s) v1 < v2");
#endif
free(b1);
free(b2);
return 2;
}
} else {
#ifndef NDEBUG
puts("... (s) v1 =? v2");
#endif
}
v1 += p1;
v2 += p2;
} /* end of while */
free(b1);
free(b2);
/* if we got here it's because we reached the end of v1 or v2 */
if(v1[0] == '\0') {
if(v2[0] == '\0') {
return 0;
} else {
#ifndef NDEBUG
puts(">>> (l) v1 < v2");
#endif
return 2;
}
} else { /* ==> v2[0] == '\0' && v1[0] != '\0' */
#ifndef NDEBUG
puts(">>> (l) v1 > v2");
#endif
return 1;
}
}
int main(int argc, char *argv[]) {
int rv;
if(argc != 3)
return 0;
rv = vercmp(argv[1], argv[2]);
#ifndef NDEBUG
if(rv == 1) {
printf("%s > %s\n", argv[1], argv[2]);
} else if(rv == 2) {
printf("%s < %s\n", argv[1], argv[2]);
} else {
printf("%s ?= %s ??\n", argv[1], argv[2]);
}
#endif
return rv;
}Code: Select all
$ gcc -pedantic -ansi -W -Wall -Wfloat-equal -Waggregate-return -Wcast-align -Wcast-qual -Wnested-externs -Wpointer-arith -Wundef -Wshadow -Wbad-function-cast -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations -Wconversion -Winline -DNDEBUG -o vercompare vercompare.c
$ strip vercompareCode: Select all
--- cleandistfiles.pl 2005-07-28 23:04:46.000000000 +0200
+++ cleandistfiles.pl.old 2005-08-06 19:51:56.000000000 +0200
@@ -52,14 +39,9 @@
$version = $2;
next if ($maskedfiles{$name}); # Ignore "masked" files
if ($lastname && $name eq $lastname) {
- if ($version gt $lastversion) {
- push (@stalefiles, [$name, $version, $lastversion, $lastext]);
+ system './vercompare', $version, $lastversion;
+ if ($? >> 8 == 1) {
+ push (@stalefiles, [$name, $version, $lastversion, $lastext]);
+ } elsif($? >> 8 == 2) {
+ push (@stalefiles, [$name, $lastversion, $version, $lastext]);
}
}
$lastname = $name;
$lastversion = $version;
Code: Select all
#!/bin/bash
emerge -epf world &> /tmp/distfilesAX432z1
ACCEPT_KEYWORDS="~x86" emerge -epf world &> /tmp/distfilesAX432z2
cd /usr/portage/distfiles
for DISTFILE in *; do
GREPRESULT=`grep $DISTFILE /tmp/distfilesAX432z1 /tmp/distfilesAX432z2`
if ( [ -z "$GREPRESULT" ] )
then rm $DISTFILE
fi
done