desatan
千年狐狸
千年狐狸
  • UID5373
  • 注册日期2005-04-22
  • 最后登录2008-10-16
  • 发帖数1033
  • 经验10枚
  • 威望0点
  • 贡献值0点
  • 好评度0点
阅读:4879回复:8

[原创]写了个gentoo下的distfiles同步程序

楼主#
更多 发布于:2006-06-09 19:02
根据portage下载最新的软件包,删除distfiles下过期的和没用的软件包。

/*GPL-2,by Desatan(a newbie)*/
#include <stdio.h>
#include <dirent.h>
char s[200];
char fs[1000][200];
char df[500][200];
int i,cnt=0,cntdf=0;
int main(int argc,char *argv[]){
        int flag;
        FILE *src;
        DIR *dist;
        struct dirent *drnt;

        puts("Downloading new files.");
        if(argc==1){
                system("emerge -fe world>/tmp/distsync.tmp");
                src=fopen("/tmp/distsync.tmp","r");
                }
        else if(strcmp("skip",argv[1])){
                src=fopen(argv[1],"r");
                if(src==NULL){
                        printf("file %s not exists!",argv[1]);
                        exit(1);
                        }
                }
        else src=fopen("/tmp/distsync.tmp","r");

        puts("Generaing files needed.");
        do{
                fgets(s,150,src);
                if((strstr(s,"checking")!=NULL)&&(strstr(s,"checksums")==NULL)){
                        for(i=13;s!=' ';++i)fs[cnt][i-13]=s;
                        fs[cnt++][i-13]='\0';
                        }
                }while(!feof(src));
        if(!cnt){
                printf("There is no info about distfiles!");
                exit(2);
                }

        printf("Checking files useless or datepassed.\n");
        dist=opendir("/usr/portage/distfiles");
        while(drnt=readdir(dist)){
                if(drnt->d_name[0]=='.')continue;
                for(i=0;i<cnt;++i){
                        flag=0;
                        if(!strcmp(drnt->d_name,fs)){flag=1;break;}
                        }
                if(!flag){strcpy(df[cntdf++],drnt->d_name);puts(drnt->d_name);}
                }

        printf("Sure to delete these files.[y/n]");
        scanf("%c",&s[0]);
        if(s[0]=='y'){
                for(i=0;i<cntdf;++i){
                        sprintf(s,"/usr/portage/distfiles/%s",df);
                        if(!unlink(s))printf("%s deleted.\n",df);
                        else printf("error!sure u r root.\n");
                        }
                }

        return 0;
        }
desatan
千年狐狸
千年狐狸
  • UID5373
  • 注册日期2005-04-22
  • 最后登录2008-10-16
  • 发帖数1033
  • 经验10枚
  • 威望0点
  • 贡献值0点
  • 好评度0点
1楼#
发布于:2006-06-09 19:02
三翻领:收下了回到原帖

刚才那个有点小问题,用这个最新的吧
desatan
千年狐狸
千年狐狸
  • UID5373
  • 注册日期2005-04-22
  • 最后登录2008-10-16
  • 发帖数1033
  • 经验10枚
  • 威望0点
  • 贡献值0点
  • 好评度0点
2楼#
发布于:2006-06-09 19:02
搞了半天,原来用这个命令就可以了。
eclean-dist -d
游客

返回顶部