1 // $Id: vutil.h,v 1.3 2003/10/21 13:23:28 ensc Exp $
3 // Copyright (C) 2003 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
4 // based on vutil.h 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.
26 #include <sys/types.h>
40 // Patch to help compile this utility on unpatched kernel source
41 #ifndef EXT2_IMMUTABLE_FILE_FL
42 #define EXT2_IMMUTABLE_FILE_FL 0x00000010
43 /* Set both bits for backward compatibility */
44 #define EXT2_IMMUTABLE_LINK_FL 0x08008000
48 FILE *vutil_execdistcmd (const char *, Vserver const &, const char *);
49 extern const char K_DUMPFILES[];
50 extern const char K_UNIFILES[];
51 extern const char K_PKGVERSION[];
56 string version; // version + release
57 Package(string &_name, string &_version)
58 : name (_name), version(_version)
61 Package(const char *_name, const char *_version)
62 : name (_name), version(_version)
65 Package(const string &line)
69 Package & operator = (const string &_line)
72 string::iterator pos = find (line.begin(),line.end(),'=');
73 if (pos != line.end()){
74 name = string(line.begin(),pos);
75 version = string(pos + 1,line.end());
79 Package (const Package &pkg)
82 version = pkg.version;
84 bool operator == (const Package &v) const
86 return name == v.name && version == v.version;
88 bool operator < (const Package &v) const
93 }else if (name == v.name && version < v.version){
98 // Load the file member of the package, but exclude configuration file
99 void loadfiles(Vserver const &ref, set<string> &files)
101 if (debug > 2) cout << "Loading files for package " << name << endl;
102 string namever = name + '-' + version;
103 FILE *fin = vutil_execdistcmd (K_UNIFILES,ref,namever.c_str());
106 while (fgets(tmp,sizeof(tmp)-1,fin)!=NULL){
107 int last = strlen(tmp)-1;
108 if (last >= 0 && tmp[last] == '\n') tmp[last] = '\0';
112 if (debug > 2) cout << "Done\n";
115 bool locate(const string &path)
117 return find (files.begin(),files.end(),path) != files.end();
122 // Check if two package have the same name (but potentially different version)
126 same_name(const Package &_pkg) : pkg(_pkg) {}
127 bool operator()(const Package &p)
129 return pkg.name == p.name;