3 // Copyright (C) 2003 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
4 // based on vfiles.cc by Jacques Gelinas
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2, or (at your option)
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 This utility is used to extract the list of non unified files in
26 #include <sys/ioctl.h>
39 static bool ignorelink = false;
45 "vfiles version " << VERSION <<
47 "vfiles [ options ] reference-server vserver\n"
49 "--debug: Prints some debugging messages.\n"
50 "--ignorelink: Do not print symbolic links (they are never unified)\n"
56 static int vfiles_walk (
58 dev_t dev, // We stay on the same volume
63 if (debug > 0) printf ("Entering directory %s\n",logical_dir.c_str());
64 DIR *dir = opendir (absdir.c_str());
66 fprintf (stderr,"Can't open directory %s (%s)\n",absdir.c_str()
71 while (ret == 0 && (ent=readdir(dir))!=NULL){
72 if (strcmp(ent->d_name,".")==0 || strcmp(ent->d_name,"..")==0){
75 string file = absdir + "/" + ent->d_name;
77 if (vutil_lstat(file,st) == -1){
79 }else if (st.st_dev != dev){
80 if (debug > 0) printf ("Ignore sub-directory %s\n",file.c_str());
82 if (S_ISDIR(st.st_mode)){
83 ret |= vfiles_walk (file,dev
84 ,logical_dir + "/" + ent->d_name,files);
85 }else if (S_ISLNK(st.st_mode)){
86 if (!ignorelink) printf ("%s\n",file.c_str());
87 }else if (S_ISBLK(st.st_mode)
88 || S_ISCHR(st.st_mode)
89 || S_ISFIFO(st.st_mode)){
90 printf ("%s\n",file.c_str());
91 }else if (S_ISSOCK(st.st_mode)){
94 // Ok, this is a file. We either copy it or do a link
95 string logical_file = logical_dir + "/" + ent->d_name;
96 if (files.find (logical_file)==files.end()){
97 printf ("%s\n",file.c_str());
107 int main (int argc, char *argv[])
111 for (i=1; i<argc; i++){
112 const char *arg = argv[i];
113 //const char *opt = argv[i+1];
114 if (strcmp(arg,"--debug")==0){
116 }else if (strcmp(arg,"--ignorelink")==0){
125 string refserv = argv[i++];
126 string newserv = argv[i];
127 list<PACKAGE> packages;
128 // Load the files which are not configuration files from
130 vutil_loadallpkg (refserv,packages);
132 for (list<PACKAGE>::iterator it=packages.begin(); it!=packages.end(); it++){
133 (*it).loadfiles(refserv,files);
136 if (vutil_lstat(newserv,st)!=-1){
137 // Now, we do a recursive walk of newserv and prints
138 // all files not unifiable
139 ret = vfiles_walk (newserv,st.st_dev,"",files);