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
30 #include <sys/ioctl.h>
43 static bool ignorelink = false;
49 "vfiles version " << VERSION <<
51 "vfiles [ options ] reference-server vserver\n"
53 "--debug: Prints some debugging messages.\n"
54 "--ignorelink: Do not print symbolic links (they are never unified)\n"
60 static int vfiles_walk (
62 dev_t dev, // We stay on the same volume
67 if (debug > 0) printf ("Entering directory %s\n",logical_dir.c_str());
68 DIR *dir = opendir (absdir.c_str());
70 fprintf (stderr,"Can't open directory %s (%s)\n",absdir.c_str()
75 while (ret == 0 && (ent=readdir(dir))!=NULL){
76 if (strcmp(ent->d_name,".")==0 || strcmp(ent->d_name,"..")==0){
79 string file = absdir + "/" + ent->d_name;
81 if (vutil_lstat(file,st) == -1){
83 }else if (st.st_dev != dev){
84 if (debug > 0) printf ("Ignore sub-directory %s\n",file.c_str());
86 if (S_ISDIR(st.st_mode)){
87 ret |= vfiles_walk (file,dev
88 ,logical_dir + "/" + ent->d_name,files);
89 }else if (S_ISLNK(st.st_mode)){
90 if (!ignorelink) printf ("%s\n",file.c_str());
91 }else if (S_ISBLK(st.st_mode)
92 || S_ISCHR(st.st_mode)
93 || S_ISFIFO(st.st_mode)){
94 printf ("%s\n",file.c_str());
95 }else if (S_ISSOCK(st.st_mode)){
98 // Ok, this is a file. We either copy it or do a link
99 string logical_file = logical_dir + "/" + ent->d_name;
100 if (files.find (logical_file)==files.end()){
101 printf ("%s\n",file.c_str());
111 int main (int argc, char *argv[])
115 for (i=1; i<argc; i++){
116 const char *arg = argv[i];
117 //const char *opt = argv[i+1];
118 if (strcmp(arg,"--debug")==0){
120 }else if (strcmp(arg,"--ignorelink")==0){
129 string refserv = argv[i++];
130 string newserv = argv[i];
131 list<Package> packages;
132 // Load the files which are not configuration files from
134 vutil_loadallpkg (refserv,packages);
136 for (list<Package>::iterator it=packages.begin(); it!=packages.end(); it++){
137 (*it).loadfiles(refserv,files);
140 if (vutil_lstat(newserv,st)!=-1){
141 // Now, we do a recursive walk of newserv and prints
142 // all files not unifiable
143 ret = vfiles_walk (newserv,st.st_dev,"",files);