CARDS 2.4.87
Package manager for the NuTyX GNU/Linux distribution
libcards.h
1 /*
2  GNU GENERAL PUBLIC LICENSE
3  Version 2, June 1991
4 
5  Copyright (C) 1989, 1991 Free Software Foundation, Inc.
6  59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
7 
8  Everyone is permitted to copy and distribute verbatim copies
9  of this license document, but changing it is not allowed.
10 
11  Preamble
12 
13  The licenses for most software are designed to take away your
14 freedom to share and change it. By contrast, the GNU General Public
15 License is intended to guarantee your freedom to share and change free
16 software--to make sure the software is free for all its users. This
17 General Public License applies to most of the Free Software
18 Foundation's software and to any other program whose authors commit to
19 using it. (Some other Free Software Foundation software is covered by
20 the GNU Library General Public License instead.) You can apply it to
21 your programs, too.
22 
23  When we speak of free software, we are referring to freedom, not
24 price. Our General Public Licenses are designed to make sure that you
25 have the freedom to distribute copies of free software (and charge for
26 this service if you wish), that you receive source code or can get it
27 if you want it, that you can change the software or use pieces of it
28 in new free programs; and that you know you can do these things.
29 
30  To protect your rights, we need to make restrictions that forbid
31 anyone to deny you these rights or to ask you to surrender the rights.
32 These restrictions translate to certain responsibilities for you if you
33 distribute copies of the software, or if you modify it.
34 
35  For example, if you distribute copies of such a program, whether
36 gratis or for a fee, you must give the recipients all the rights that
37 you have. You must make sure that they, too, receive or can get the
38 source code. And you must show them these terms so they know their
39 rights.
40 
41  We protect your rights with two steps: (1) copyright the software, and
42 (2) offer you this license which gives you legal permission to copy,
43 distribute and/or modify the software.
44 
45  Also, for each author's protection and ours, we want to make certain
46 that everyone understands that there is no warranty for this free
47 software. If the software is modified by someone else and passed on, we
48 want its recipients to know that what they have is not the original, so
49 that any problems introduced by others will not reflect on the original
50 authors' reputations.
51 
52  Finally, any free program is threatened constantly by software
53 patents. We wish to avoid the danger that redistributors of a free
54 program will individually obtain patent licenses, in effect making the
55 program proprietary. To prevent this, we have made it clear that any
56 patent must be licensed for everyone's free use or not licensed at all.
57 
58  The precise terms and conditions for copying, distribution and
59 modification follow.
60 
61  GNU GENERAL PUBLIC LICENSE
62  TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
63 
64  0. This License applies to any program or other work which contains
65 a notice placed by the copyright holder saying it may be distributed
66 under the terms of this General Public License. The "Program", below,
67 refers to any such program or work, and a "work based on the Program"
68 means either the Program or any derivative work under copyright law:
69 that is to say, a work containing the Program or a portion of it,
70 either verbatim or with modifications and/or translated into another
71 language. (Hereinafter, translation is included without limitation in
72 the term "modification".) Each licensee is addressed as "you".
73 
74 Activities other than copying, distribution and modification are not
75 covered by this License; they are outside its scope. The act of
76 running the Program is not restricted, and the output from the Program
77 is covered only if its contents constitute a work based on the
78 Program (independent of having been made by running the Program).
79 Whether that is true depends on what the Program does.
80 
81  1. You may copy and distribute verbatim copies of the Program's
82 source code as you receive it, in any medium, provided that you
83 conspicuously and appropriately publish on each copy an appropriate
84 copyright notice and disclaimer of warranty; keep intact all the
85 notices that refer to this License and to the absence of any warranty;
86 and give any other recipients of the Program a copy of this License
87 along with the Program.
88 
89 You may charge a fee for the physical act of transferring a copy, and
90 you may at your option offer warranty protection in exchange for a fee.
91 
92  2. You may modify your copy or copies of the Program or any portion
93 of it, thus forming a work based on the Program, and copy and
94 distribute such modifications or work under the terms of Section 1
95 above, provided that you also meet all of these conditions:
96 
97  a) You must cause the modified files to carry prominent notices
98  stating that you changed the files and the date of any change.
99 
100  b) You must cause any work that you distribute or publish, that in
101  whole or in part contains or is derived from the Program or any
102  part thereof, to be licensed as a whole at no charge to all third
103  parties under the terms of this License.
104 
105  c) If the modified program normally reads commands interactively
106  when run, you must cause it, when started running for such
107  interactive use in the most ordinary way, to print or display an
108  announcement including an appropriate copyright notice and a
109  notice that there is no warranty (or else, saying that you provide
110  a warranty) and that users may redistribute the program under
111  these conditions, and telling the user how to view a copy of this
112  License. (Exception: if the Program itself is interactive but
113  does not normally print such an announcement, your work based on
114  the Program is not required to print an announcement.)
115 
116 These requirements apply to the modified work as a whole. If
117 identifiable sections of that work are not derived from the Program,
118 and can be reasonably considered independent and separate works in
119 themselves, then this License, and its terms, do not apply to those
120 sections when you distribute them as separate works. But when you
121 distribute the same sections as part of a whole which is a work based
122 on the Program, the distribution of the whole must be on the terms of
123 this License, whose permissions for other licensees extend to the
124 entire whole, and thus to each and every part regardless of who wrote it.
125 
126 Thus, it is not the intent of this section to claim rights or contest
127 your rights to work written entirely by you; rather, the intent is to
128 exercise the right to control the distribution of derivative or
129 collective works based on the Program.
130 
131 In addition, mere aggregation of another work not based on the Program
132 with the Program (or with a work based on the Program) on a volume of
133 a storage or distribution medium does not bring the other work under
134 the scope of this License.
135 
136  3. You may copy and distribute the Program (or a work based on it,
137 under Section 2) in object code or executable form under the terms of
138 Sections 1 and 2 above provided that you also do one of the following:
139 
140  a) Accompany it with the complete corresponding machine-readable
141  source code, which must be distributed under the terms of Sections
142  1 and 2 above on a medium customarily used for software interchange; or,
143 
144  b) Accompany it with a written offer, valid for at least three
145  years, to give any third party, for a charge no more than your
146  cost of physically performing source distribution, a complete
147  machine-readable copy of the corresponding source code, to be
148  distributed under the terms of Sections 1 and 2 above on a medium
149  customarily used for software interchange; or,
150 
151  c) Accompany it with the information you received as to the offer
152  to distribute corresponding source code. (This alternative is
153  allowed only for noncommercial distribution and only if you
154  received the program in object code or executable form with such
155  an offer, in accord with Subsection b above.)
156 
157 The source code for a work means the preferred form of the work for
158 making modifications to it. For an executable work, complete source
159 code means all the source code for all modules it contains, plus any
160 associated interface definition files, plus the scripts used to
161 control compilation and installation of the executable. However, as a
162 special exception, the source code distributed need not include
163 anything that is normally distributed (in either source or binary
164 form) with the major components (compiler, kernel, and so on) of the
165 operating system on which the executable runs, unless that component
166 itself accompanies the executable.
167 
168 If distribution of executable or object code is made by offering
169 access to copy from a designated place, then offering equivalent
170 access to copy the source code from the same place counts as
171 distribution of the source code, even though third parties are not
172 compelled to copy the source along with the object code.
173 
174  4. You may not copy, modify, sublicense, or distribute the Program
175 except as expressly provided under this License. Any attempt
176 otherwise to copy, modify, sublicense or distribute the Program is
177 void, and will automatically terminate your rights under this License.
178 However, parties who have received copies, or rights, from you under
179 this License will not have their licenses terminated so long as such
180 parties remain in full compliance.
181 
182  5. You are not required to accept this License, since you have not
183 signed it. However, nothing else grants you permission to modify or
184 distribute the Program or its derivative works. These actions are
185 prohibited by law if you do not accept this License. Therefore, by
186 modifying or distributing the Program (or any work based on the
187 Program), you indicate your acceptance of this License to do so, and
188 all its terms and conditions for copying, distributing or modifying
189 the Program or works based on it.
190 
191  6. Each time you redistribute the Program (or any work based on the
192 Program), the recipient automatically receives a license from the
193 original licensor to copy, distribute or modify the Program subject to
194 these terms and conditions. You may not impose any further
195 restrictions on the recipients' exercise of the rights granted herein.
196 You are not responsible for enforcing compliance by third parties to
197 this License.
198 
199  7. If, as a consequence of a court judgment or allegation of patent
200 infringement or for any other reason (not limited to patent issues),
201 conditions are imposed on you (whether by court order, agreement or
202 otherwise) that contradict the conditions of this License, they do not
203 excuse you from the conditions of this License. If you cannot
204 distribute so as to satisfy simultaneously your obligations under this
205 License and any other pertinent obligations, then as a consequence you
206 may not distribute the Program at all. For example, if a patent
207 license would not permit royalty-free redistribution of the Program by
208 all those who receive copies directly or indirectly through you, then
209 the only way you could satisfy both it and this License would be to
210 refrain entirely from distribution of the Program.
211 
212 If any portion of this section is held invalid or unenforceable under
213 any particular circumstance, the balance of the section is intended to
214 apply and the section as a whole is intended to apply in other
215 circumstances.
216 
217 It is not the purpose of this section to induce you to infringe any
218 patents or other property right claims or to contest validity of any
219 such claims; this section has the sole purpose of protecting the
220 integrity of the free software distribution system, which is
221 implemented by public license practices. Many people have made
222 generous contributions to the wide range of software distributed
223 through that system in reliance on consistent application of that
224 system; it is up to the author/donor to decide if he or she is willing
225 to distribute software through any other system and a licensee cannot
226 impose that choice.
227 
228 This section is intended to make thoroughly clear what is believed to
229 be a consequence of the rest of this License.
230 
231  8. If the distribution and/or use of the Program is restricted in
232 certain countries either by patents or by copyrighted interfaces, the
233 original copyright holder who places the Program under this License
234 may add an explicit geographical distribution limitation excluding
235 those countries, so that distribution is permitted only in or among
236 countries not thus excluded. In such case, this License incorporates
237 the limitation as if written in the body of this License.
238 
239  9. The Free Software Foundation may publish revised and/or new versions
240 of the General Public License from time to time. Such new versions will
241 be similar in spirit to the present version, but may differ in detail to
242 address new problems or concerns.
243 
244 Each version is given a distinguishing version number. If the Program
245 specifies a version number of this License which applies to it and "any
246 later version", you have the option of following the terms and conditions
247 either of that version or of any later version published by the Free
248 Software Foundation. If the Program does not specify a version number of
249 this License, you may choose any version ever published by the Free Software
250 Foundation.
251 
252  10. If you wish to incorporate parts of the Program into other free
253 programs whose distribution conditions are different, write to the author
254 to ask for permission. For software which is copyrighted by the Free
255 Software Foundation, write to the Free Software Foundation; we sometimes
256 make exceptions for this. Our decision will be guided by the two goals
257 of preserving the free status of all derivatives of our free software and
258 of promoting the sharing and reuse of software generally.
259 
260  NO WARRANTY
261 
262  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
263 FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
264 OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
265 PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
266 OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
267 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
268 TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
269 PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
270 REPAIR OR CORRECTION.
271 
272  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
273 WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
274 REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
275 INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
276 OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
277 TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
278 YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
279 PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
280 POSSIBILITY OF SUCH DAMAGES.
281 
282  END OF TERMS AND CONDITIONS
283 
284  Appendix: How to Apply These Terms to Your New Programs
285 
286  If you develop a new program, and you want it to be of the greatest
287 possible use to the public, the best way to achieve this is to make it
288 free software which everyone can redistribute and change under these terms.
289 
290  To do so, attach the following notices to the program. It is safest
291 to attach them to the start of each source file to most effectively
292 convey the exclusion of warranty; and each file should have at least
293 the "copyright" line and a pointer to where the full notice is found.
294 
295  <one line to give the program's name and a brief idea of what it does.>
296  Copyright (C) 19yy <name of author>
297 
298  This program is free software; you can redistribute it and/or modify
299  it under the terms of the GNU General Public License as published by
300  the Free Software Foundation; either version 2 of the License, or
301  (at your option) any later version.
302 
303  This program is distributed in the hope that it will be useful,
304  but WITHOUT ANY WARRANTY; without even the implied warranty of
305  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
306  GNU General Public License for more details.
307 
308  You should have received a copy of the GNU General Public License
309  along with this program; if not, write to the Free Software
310  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
311 
312 Also add information on how to contact you by electronic and paper mail.
313 
314 If the program is interactive, make it output a short notice like this
315 when it starts in an interactive mode:
316 
317  Gnomovision version 69, Copyright (C) 19yy name of author
318  Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
319  This is free software, and you are welcome to redistribute it
320  under certain conditions; type `show c' for details.
321 
322 The hypothetical commands `show w' and `show c' should show the appropriate
323 parts of the General Public License. Of course, the commands you use may
324 be called something other than `show w' and `show c'; they could even be
325 mouse-clicks or menu items--whatever suits your program.
326 
327 You should also get your employer (if you work as a programmer) or your
328 school, if any, to sign a "copyright disclaimer" for the program, if
329 necessary. Here is a sample; alter the names:
330 
331  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
332  `Gnomovision' (which makes passes at compilers) written by James Hacker.
333 
334  <signature of Ty Coon>, 1 April 1989
335  Ty Coon, President of Vice
336 
337 This General Public License does not permit incorporating your program into
338 proprietary programs. If your program is a subroutine library, you may
339 consider it more useful to permit linking proprietary applications with the
340 library. If this is what you want to do, use the GNU Library General
341 Public License instead of this License.
342 */
343 
344 
345 #ifndef LIB_CARDS_INCLUDED
346 #define LIB_CARDS_INCLUDED
347 
348 
349 #include <string>
350 #include <iterator>
351 #include <iostream>
352 
353 #include <syslog.h>
354 #include <stdio.h>
355 #include <sys/utsname.h>
356 #include <locale.h>
357 #include <libintl.h>
358 
359 #define _ gettext
360 
364 std::string getMachineType ();
365 
366 
367 
368 
369 #include <cstring>
370 
371 #define RED "\033[1;31m"
372 #define GREEN "\033[1;32m"
373 #define YELLOW "\033[1;33m"
374 #define BLUE "\033[1;34m"
375 #define MAGENTA "\033[1;35m"
376 #define CYAN "\033[1;36m"
377 #define WHITE "\033[1;37m"
378 #define NORMAL "\033[1;0m"
379 
380 #define ACTION _("\033[1;33maction:\033[1;0m")
381 #define USAGE _("\033[1;33musage: \033[1;0m")
382 #define OPTIONS _("\033[1;33moptions\033[1;0m")
383 #define REQUIRED _("\033[1;33mrequired\033[1;0m")
384 #define DESCRIPTION _("\033[1;33mdescription: \033[1;0m")
385 #define COMMAND _("\033[1;34mcommand\033[1;0m")
386 
387 
388 enum error
389 {
390 CANNOT_DOWNLOAD_FILE,
391 CANNOT_CREATE_FILE,
392 CANNOT_OPEN_FILE,
393 CANNOT_FIND_FILE,
394 CANNOT_READ_FILE,
395 CANNOT_COPY_FILE,
396 CANNOT_PARSE_FILE,
397 CANNOT_READ_DIRECTORY,
398 CANNOT_WRITE_FILE,
399 CANNOT_SYNCHRONIZE,
400 CANNOT_RENAME_FILE,
401 CANNOT_DETERMINE_NAME_BUILDNR,
402 WRONG_ARCHITECTURE,
403 EMPTY_PACKAGE,
404 CANNOT_FORK,
405 WAIT_PID_FAILED,
406 DATABASE_LOCKED,
407 CANNOT_LOCK_DIRECTORY,
408 CANNOT_REMOVE_FILE,
409 CANNOT_CREATE_DIRECTORY,
410 CANNOT_RENAME_DIRECTORY,
411 OPTION_ONE_ARGUMENT,
412 INVALID_OPTION,
413 OPTION_MISSING,
414 TOO_MANY_OPTIONS,
415 ONLY_ROOT_CAN_INSTALL_UPGRADE_REMOVE,
416 PACKAGE_NOT_FOUND,
417 PACKAGE_ALLREADY_INSTALL,
418 PACKAGE_NOT_INSTALL,
419 PACKAGE_NOT_PREVIOUSLY_INSTALL,
420 LISTED_FILES_ALLREADY_INSTALLED,
421 PKGADD_CONFIG_LINE_TOO_LONG,
422 PKGADD_CONFIG_WRONG_NUMBER_ARGUMENTS,
423 PKGADD_CONFIG_UNKNOWN_ACTION,
424 PKGADD_CONFIG_UNKNOWN_EVENT,
425 CANNOT_COMPILE_REGULAR_EXPRESSION,
426 CANNOT_GENERATE_LEVEL,
427 NOT_INSTALL_PACKAGE_NEITHER_PACKAGE_FILE
428 };
429 
430 class RunTimeErrorWithErrno : public std::runtime_error
431 {
432  public:
433  explicit RunTimeErrorWithErrno(const std::string& msg) throw();
434  explicit RunTimeErrorWithErrno(const std::string& msg, int e) throw();
435 };
436 
437 
438 #include <string.h>
439 
440 #define uint8 unsigned char
441 #define uint32 unsigned long int
442 
444 {
445  uint32 total[2];
446  uint32 state[4];
447  uint8 buffer[64];
448 };
449 
450 void md5_starts( struct md5_context *ctx );
451 void md5_update( struct md5_context *ctx, uint8 *input, uint32 length );
452 void md5_finish( struct md5_context *ctx, uint8 digest[16] );
453 
454 
455 
456 
457 #include <fstream>
458 #include <map>
459 #include <set>
460 #include <vector>
461 
462 #include <sys/stat.h>
463 
464 #define GIGA 1e9
465 #define MEGA 1e6
466 #define KILO 1e3
467 #define PACKAGE_LOCALE_DIR "/usr/share/locale"
468 #define GETTEXT_PACKAGE "cards"
469 
470 void *Malloc(size_t s);
471 
472 struct keyValue
473 {
474  std::string parameter;
475  std::string value;
476 };
477 
481 typedef struct
482 {
483  char **items;
484  unsigned int count;
485 } itemList;
486 
490 itemList *initItemList(void);
491 
495 void addItemToItemList(itemList *list, const char *item);
496 
501 void freeItemList(itemList *list);
502 
506 keyValue splitKeyValue
507 (std::string s, char delimiter);
508 
509 std::set<std::string> getKeysList
510 (std::string file, std::string delimiter);
511 
512 std::string getValueOfKey
513 (std::string file, std::string delimiter,std::string parameter);
514 
515 std::string getValue(const std::string& s, char delimiter);
516 std::string getValueBefore( const std::string& s, char del );
517 std::string itos(unsigned int value);
518 std::string ultos(unsigned long int value);
519 
520 std::string mtos(mode_t mode);
521 std::string trimFileName(const std::string& filename);
522 std::string sizeHumanRead(int value);
523 
524 /*param s the string to be searched, param delimiter the delimiter char
525 return the value after the first occurance of a delimiter */
526 std::string getFirstValueOfKeyAfterDelim(const std::string& s, char delimiter);
527 
528 /*param s the string to be searched param delimiter the delimiter char
529 return the value before the first occurance of a delimiter */
530 std::string getFirstValueOfKeyBeforeDelim(const std::string& s, char delimiter);
531 
532 /* strip whitespace in the beginning and end of string, return a stripped string */
533 std::string stripWhiteSpace(const std::string& s);
534 
535 /* populate a vector of string with delimited character */
536 std::vector<std::string> parseDelimitedList
537 (const std::string& s, const char delimiter);
538 
539 /* populate a set of string with delimited character */
540 std::set<std::string> parseDelimitedSetList
541 (const std::string& s, const char delimiter);
542 
543 /* make sure s1 starts with s2 */
544 bool startsWith(const std::string& s, const std::string& with);
545 
550 bool startsWithNoCase(const std::string& s1, const std::string& s2);
551 
552 std::string convertToLowerCase(const std::string& s);
553 std::string convertToUpperCase(const std::string& s);
554 
555 std::string replaceAll
556 ( std::string& in, const std::string& oldString, const std::string& newString );
557 
567 template <class T>
568 void split( const std::string& s, char del,
569  T& target,
570  int startPos, bool useEmpty )
571 {
572  std::string line = s;
573  std::string ss;
574  std::string::size_type pos;
575  int offset = startPos;
576  while ( ( pos = line.find( del, offset ) ) != std::string::npos ) {
577  offset = 0;
578  if ( line[pos-1] == '\\' ) {
579  line.erase(pos-1,1);
580  ss = ss + line.substr(0,pos);
581  line.erase(0,pos);
582  continue;
583  }
584  std::string val = line.substr( 0, pos );
585  if ( ( useEmpty || !stripWhiteSpace( val ).empty() ) ||
586  ( ss.length() > 0 ) ) {
587  target.push_back( ss + val );
588  }
589  line.erase( 0, pos+1 );
590  }
591 
592  if ( ( line.length() > 0 ) || ( ss.length() > 0 ) ) {
593  target.push_back( ss + line );
594  }
595 }
596 
597 
598 
599 
600 #include <utime.h>
601 #include <dirent.h>
602 #include <sys/param.h>
603 #include <sys/file.h>
604 #include <unistd.h>
605 #include <libgen.h>
606 #include <err.h>
607 
608 #define S_CARDS_MODE 0755
609 
610 #define WS_NONE 0
611 #define WS_RECURSIVE (1 << 0)
612 #define WS_DEFAULT WS_RECURSIVE
613 #define WS_FOLLOWLINK (1 << 1) /* follow symlinks */
614 #define WS_DOTFILES (1 << 2) /* per unix convention, .file is hidden */
615 #define WS_MATCHDIRS (1 << 3) /* if pattern is used on dir names too */
616 
617 enum {
618  WALK_OK = 0,
619  WALK_BADPATTERN,
620  WALK_NAMETOOLONG,
621  WALK_BADIO
622 };
623 
624 struct InfoFile
625 {
626  std::string url;
627  std::string filename;
628  std::string dirname;
629  std::string md5sum;
630  long int filetime;
631  utimbuf acmodtime;
632  FILE *stream;
633 };
634 
635 struct DirUrl {
636  std::string Dir;
637  std::string Url;
638 };
639 
640 struct Config {
641  Config() {}
642  std::string hostname;
643  std::string database;
644  std::string username;
645  std::string password;
646  std::string socket;
647  std::string collection;
648  std::string name;
649  std::string version;
650  std::string arch;
651  std::string logdir;
652  std::vector<std::string> locale;
653  std::vector<DirUrl> dirUrl;
654  std::vector<std::string> baseDir;
655  std::vector<std::string> archs;
656 };
657 
658 int getConfig(const char *fileName, Config& config);
659 void * getDatas ( void * var, FILE * file, long offset, size_t size, size_t nmemb);
660 std::string trimFileName(const std::string& filename);
661 time_t getEpochModifyTimeFile(const std::string& filename);
662 std::string getDateFromEpoch(const time_t& epoch);
663 std::string getModifyTimeFile(const std::string& filename);
664 bool checkFileExist(const std::string& filename);
665 bool checkFileEmpty(const std::string& filename);
666 bool checkRegularFile(const std::string& filename);
667 bool checkFileSignature(const std::string& filename, const std::string& signature);
668 bool checkFilesEqual(const std::string& file1, const std::string& file2);
669 bool checkPermissionsEqual(const std::string& file1, const std::string& file2);
670 bool createRecursiveDirs(const std::string& pathname);
671 void cleanupMetaFiles(const std::string& basedir);
672 void removeFile(const std::string& basedir, const std::string& filename);
673 int copyFile(const char * destFile, const char * origFile);
674 int findFile(std::set<std::string>& filesList, const std::string& basedir);
675 int findDir(itemList *filenameList, const char *path);
676 int findRecursiveFile(std::set<std::string>& filenameList, const char *filename, int spec);
677 int readFileStripSpace(itemList *fileContent, const char *fileName);
678 int readFile(itemList *fileContent, const char *fileName);
679 int parseFile(std::set<std::string>& fileContent, const char* fileName);
680 int parseFile(std::vector<std::string>& fileContent, const char* fileName);
681 bool findMD5sum(const std::string& fileName, unsigned char* result);
682 bool checkMD5sum(const char * fileName, const char * MD5Sum);
683 /* read a file
684  return it into a template container */
685 template <class T>
686 int parseFile( T& target, const char* fileName)
687 {
688  FILE *fp = fopen (fileName, "r");
689  if (!fp)
690  return -1;
691  const int length = BUFSIZ;
692  char input[length];
693  std::string line;
694  while (fgets(input, length, fp)) {
695  input[strlen(input)-1] = '\0';
696  line = input;
697  target.push_back(line);
698  }
699  fclose(fp);
700  return 0;
701 }
702 
703 
704 
705 
706 
707 #include <archive.h>
708 #include <archive_entry.h>
709 
710 
711 #if ARCHIVE_VERSION_NUMBER >= 3000000
712 #define INIT_ARCHIVE(ar) \
713  archive_read_support_filter_gzip((ar)); \
714  archive_read_support_filter_bzip2((ar)); \
715  archive_read_support_filter_xz((ar)); \
716  archive_read_support_format_tar((ar))
717 #define FREE_ARCHIVE(ar) \
718  archive_read_free((ar))
719 #else
720 #define INIT_ARCHIVE(ar) \
721  archive_read_support_compression_gzip((ar)); \
722  archive_read_support_compression_bzip2((ar)); \
723  archive_read_support_compression_xz((ar)); \
724  archive_read_support_format_tar((ar))
725 #define FREE_ARCHIVE(ar) \
726  archive_read_finish((ar))
727 #endif
728 
729 #define DEFAULT_BYTES_PER_BLOCK (20 * 512)
730 #define METAFILE ".META"
731 #define INFOFILE ".INFO"
732 #define MTREEFILE ".MTREE"
733 
734 enum archive_error
735 {
736 CANNOT_OPEN_ARCHIVE,
737 CANNOT_READ_ARCHIVE,
738 CANNOT_FIND_META_FILE,
739 CANNOT_FIND_MTREE_FILE,
740 CANNOT_FIND_NAME,
741 CANNOT_FIND_ARCH,
742 EMPTY_ARCHIVE
743 };
744 
745 
746 class ArchiveUtils
747 {
748  public:
749 
750 
751  ArchiveUtils(const std::string& fileName);
752  virtual ~ArchiveUtils();
753 
754  virtual void treatErrors(const std::string& s) const;
755 
756  void printDeps(); // Print Out the dependencies
757  void printMeta(); // Print Out the .META file
758  void printInfo(); // the .INFO file
759  void list(); // list the files to stdio
760 
761 
762  unsigned int long size(); // Numbers of files in the archive
763  std::set<std::string> setofFiles(); // return a order set of string
764  std::set<std::string> listofDependencies(); // return an order set of dependencies
765  std::set<std::string> listofAlias(); // return the alias list
766  std::set<std::pair<std::string,time_t> > listofDependenciesBuildDate(); // return an order set of dependencies,BuildDate
767  std::string arch(); // return the arch of the package
768  std::string version(); // return the version of the package
769  int release(); // return the release of the package
770  std::string description();// return the description of the package
771  std::string url(); // return the url of the package
772  std::string contributors(); // return the Contributor(s) of the package
773  std::string maintainer(); // return the Maintainer(s) of the package
774  std::string collection(); // return the collection of the package
775  std::string packager(); // return the Packager(s) of the package
776  std::string builddate(); // return the date like Mon Mar 24 10:16:00 2014
777  std::string name(); // return the name of the package
778  std::string namebuildn(); // return the name + epochvalue
779  std::string epochBuildDate(); // return the epochvalue in string format
780  time_t buildn(); // return the epoch value
781 
782  private:
783 
784  std::string getPackageName();
785  std::string getPackageArch();
786  std::vector<std::string> extractFileContent(const char * fileName);
787  void getRunTimeDependencies();
788  void getRunTimeDependenciesEpoch();
789  void getAliasList();
790 
791  unsigned int long m_size;
792 
793  std::vector<std::string> m_contentMtree;
794  std::vector<std::string> m_contentMeta;
795  std::vector<std::string> m_contentInfo;
796 
797  std::set<std::string> m_rtDependenciesList;
798  std::set<std::pair<std::string,time_t> > m_rtDependenciesEpochList;
799  std::string m_fileName;
800  std::string m_packageName;
801  std::string m_packageArch;
802  std::set<std::string> m_filesList;
803  std::set<std::string> m_aliasList;
804 
805  archive_error m_actualError;
806 };
807 
808 int openArchive(const char *fileName);
809 
810 /*
811  * pkg.h
812  *
813  * Copyright 2017 NuTyX <tnut@nutyx.org>
814  *
815  * This program is free software; you can redistribute it and/or modify
816  * it under the terms of the GNU General Public License as published by
817  * the Free Software Foundation; either version 2 of the License, or
818  * (at your option) any later version.
819  *
820  * This program is distributed in the hope that it will be useful,
821  * but WITHOUT ANY WARRANTY; without even the implied warranty of
822  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
823  * GNU General Public License for more details.
824  *
825  * You should have received a copy of the GNU General Public License
826  * along with this program; if not, write to the Free Software
827  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
828  * MA 02110-1301, USA.
829  *
830  *
831  */
832 
833 #define PKG_H
834 
835 #include <string>
836 
837 enum CPSTATUS
838 {
839  INSTALLED = 0x01,
840  TO_INSTALL = 0x02,
841  TO_REMOVE = 0x04,
842  TO_UPGRADE = 0x08
843 };
844 
845 class Pkg
846 {
847 public:
848  Pkg();
849  ~Pkg();
850  std::string getCollection();
851  std::string getName();
852  std::string getVersion();
853  std::string getPackager();
854  std::string getDescription();
855  void setName(std::string& name);
856  void setDescription(std::string& description);
857  void setVersion(std::string& version);
858  void setCollection(std::string& collection);
859  void setPackager(std::string& packager);
860  bool isInstalled();
861  bool isToBeInstalled();
862  bool isToBeRemoved();
863  void setStatus(CPSTATUS pstatus);
864  void unSetStatus(CPSTATUS pstatus);
865  CPSTATUS getStatus();
866 
867 protected:
868  std::string _collection;
869  std::string _name;
870  std::string _version;
871  std::string _packager;
872  std::string _description;
873  CPSTATUS _status;
874 };
875 
876 
877 
878 
880  std::string md5SUM;
881  std::string name;
882  std::string arch;
883 };
884 
891 /*
892  **************************************************
893  * 73193bfc1cb30fe02a880ed088ed7590#1414192958#aalib#1.4rc5##n.a#n.a#n.a#n.a#.cards.tar.xz
894  * 650ed499ce78791d45b91aaf7f91b445#1428615787#firefox#37.0.1#1#Standalone web browser from mozilla.org#http://www.mozilla.com/firefox/#n.a#pierre at nutyx dot org,tnut at nutyx dot org#.cards.tar.xz
895  *************************************************
896  */
898  std::string md5SUM;
899  std::string s_buildDate;
900  std::string basePackageName;
901  std::string extention;
902  std::string version;
903  int release;
904  std::string description;
905  std::string URL;
906  std::string contributors;
907  std::string maintainer;
908  std::string packager;
909  std::string fileDate;
910  std::string alias;
911  std::string group;
912  time_t buildDate;
913  std::vector<PortFilesList> portFilesList;
914 };
915 
917  std::string Dir;
918  std::string Url;
919  std::vector<BasePackageInfo> basePackageList;
920 };
924 struct RepoInfo {
925  std::string branch;
926  std::string arch;
927  std::string collection;
928  std::vector<BasePackageInfo> basePackageList;
929 };
930 class Pkgrepo {
931 public:
932 
933  Pkgrepo(const std::string& fileName);
934  virtual ~Pkgrepo() { clearPackagesList(); }
935  static int parseConfig(const char *fileName,
936  Config& config);
937 
948  std::set<std::string> getListOutOfDate();
949 
954  std::string getPortDir (const std::string& portName);
955 
956 
962  std::string getBasePortName (const std::string& portName);
967  std::string getBasePackageName(const std::string& packageName);
973  std::string getBasePackageVersion(const std::string& packageName);
977  std::string getPortVersion (const std::string& portName);
978 
983  int getBasePackageRelease (const std::string& packageName);
984 
988  int getPortRelease(const std::string& portName);
992  bool checkPortExist(const std::string& portName);
993 
997  std::set<std::string> getListOfPackagesFromCollection(const std::string& collectionName);
998 
1002  time_t getBinaryBuildTime (const std::string& portName);
1003 
1008  std::set<std::string> getBinaryPackageList();
1009 
1014  std::set<Pkg*> getListOfPackages();
1019  std::vector<RepoInfo> getRepoInfo();
1025  unsigned int getPortsList();
1026 
1027  bool getBinaryPackageInfo(const std::string& packageName);
1028  bool getPortInfo(const std::string& portName);
1029 
1030 protected:
1035  int parseConfig(const char *fileName);
1036 
1050 
1061  void parseCollectionDirectory();
1062 
1075 
1081  void parsePackagePkgfileFile();
1082 
1083 
1084  bool m_parsePkgRepoCollectionFile;
1085  bool m_parseCollectionDirectory;
1086  bool m_parsePackagePkgfileFile;
1087 
1088  std::vector<PortsDirectory>::iterator m_PortsDirectory_i;
1089  std::vector<BasePackageInfo>::iterator m_BasePackageInfo_i;
1090  std::vector<PortFilesList>::iterator m_PortFilesList_i;
1091 
1092  std::vector<PortFilesList> m_portFilesList;
1093 
1094  std::string m_packageFileName;
1095  std::string m_packageFileNameSignature;
1096  std::string m_configFileName;
1097  Config m_config;
1098 
1099  std::vector<PortsDirectory> m_portsDirectoryList;
1100 private:
1101  void clearPackagesList();
1102  std::set<Pkg*> m_packagesList;
1103 };
1104 #define REPODWL_H
1105 
1106 
1107 class Repodwl: public Pkgrepo {
1108 public:
1109  Repodwl(const char *fileName);
1120  void downloadPortsPkgRepo(const std::string& packageName);
1121 
1132  void downloadPackageFileName(const std::string& packageFileName);
1133  bool checkBinaryExist(const std::string& packageName);
1134  std::string getPackageFileName(const std::string& packageName);
1135  std::string getPackageFileNameSignature(const std::string& packageName);
1136 };
1137 
1144 #include <curl/curl.h>
1145 
1146 
1155 class FileDownloadState
1156 {
1157  public:
1158  double dlnow;
1159  double dltotal;
1160  double dlspeed;
1161  std::string filename;
1162 };
1163 
1164 class FileDownload;
1165 
1174 class FileDownloadEvent
1175 {
1176  friend FileDownload;
1177 public:
1179  ~FileDownloadEvent();
1180 
1181  protected:
1182 
1189 };
1190 
1199 class FileDownload
1200 {
1201  public:
1202 
1211  FileDownload(std::string url, std::string dirName, std::string fileName, bool progress);
1212 
1222  FileDownload(std::string url, std::string dirName, std::string fileName, std::string MD5Sum , bool progress);
1223 
1231  FileDownload(std::vector<InfoFile> destinationFiles,bool progress);
1232 
1237  {
1238  curl_slist_free_all(m_slist);
1239  curl_global_cleanup();
1240  curl_easy_cleanup(m_curl);
1241  }
1242 
1243  static void SuscribeToEvents(FileDownloadEvent* callback);
1244  static void UnSuscribeFromEvents(FileDownloadEvent* callback);
1245  private:
1246 
1250  bool checkMD5sum();
1251 
1255  void downloadFile();
1256 
1257  static int updateProgressHandle(void *p, double dltotal, double dlnow, double ultotal, double ulnow);
1258  static size_t writeToStreamHandle(void *buffer, size_t size, size_t nmemb, void *stream);
1259  int updateProgress(void *p, double dltotal, double dlnow, double ultotal, double ulnow);
1260  size_t writeToStream(void *buffer, size_t size, size_t nmemb, void *stream);
1261  void initFileToDownload(std::string _url, std::string _file);
1262 
1266  bool checkUpToDate();
1267  void SendProgressEvent(FileDownloadState event);
1268  struct dwlProgress
1269  {
1270  double lastruntime;
1271  CURL *curl;
1272  };
1273  struct curl_slist *m_slist;
1274 
1275  CURL* m_curl;
1276  CURLcode m_curlCode;
1277  dwlProgress m_downloadProgress;
1278  InfoFile m_destinationFile;
1279  std::string m_url;
1280  std::string m_downloadFileName;
1281  bool m_checkMD5;
1282  bool m_progress;
1283  std::string m_MD5Sum;
1284  static std::set<FileDownloadEvent*> m_arrCallBacks;
1285 };
1286 
1287 
1288 
1289 
1290 #include <list>
1291 #include <cassert>
1292 #include <cstddef>
1293 #include <cstdlib>
1294 #include <cstdio>
1295 
1296 #include <unistd.h>
1297 #include <fcntl.h>
1298 #include <sys/types.h>
1299 #include <sys/wait.h>
1300 
1301 
1310 class process
1311 {
1312 public:
1313  process();
1314  process( const std::string& app, const std::string& args, int fileDescriptorLog=0 );
1315 
1316  void execute(const std::string& app, const std::string& arguments, int fileDescriptorLog=0 );
1317 
1322  int execute();
1323 
1328  int executeShell();
1329 
1333  std::string name();
1334 
1338  std::string args();
1339 
1340 private:
1341 
1342  int exec(const int argc, char** argv);
1343  int execLog(const int argc, char** argv);
1344 
1345  int execShell(const char* shell);
1346  int execShellLog(const char* shell);
1347 
1348  std::string m_application;
1349  std::string m_arguments;
1350  int m_fileDescriptorLog;
1351 };
1352 
1353 
1354 
1355 
1356 #include <stdio.h>
1357 #include <stdlib.h>
1358 #include <string.h>
1359 #include <unistd.h>
1360 #include <sys/stat.h>
1361 
1362 
1363 int getRuntimeLibrariesList (std::set<std::string>& runtimeLibrariesList, const std::string& filename);
1364 
1365 
1372 #include <stdexcept>
1373 #include <csignal>
1374 #include <algorithm>
1375 
1376 #include <regex.h>
1377 #include <ext/stdio_filebuf.h>
1378 #include <pwd.h>
1379 #include <grp.h>
1380 
1381 
1382 
1383 #define LDCONFIG "sbin/ldconfig"
1384 #define LDCONFIG_CONF "etc/ld.so.conf"
1385 #define LDCONFIG_CONF_ARGS "-r "
1386 #define SHELL "bin/sh"
1387 
1388 #define INSTALL_INFO "usr/bin/install-info"
1389 #define INSTALL_INFO_ARGS "--info-dir=usr/share/info "
1390 
1391 #define UPDATE_ICON "usr/bin/gtk-update-icon-cache"
1392 #define UPDATE_ICON_ARGS "-f -t "
1393 
1394 #define COMPILE_SCHEMAS "usr/bin/glib-compile-schemas"
1395 #define COMPILE_SCHEMAS_ARGS ""
1396 
1397 #define UPDATE_DESKTOP_DB "usr/bin/update-desktop-database"
1398 #define UPDATE_DESKTOP_DB_ARGS "-q "
1399 
1400 #define UPDATE_MIME_DB "usr/bin/update-mime-database"
1401 #define UPDATE_MIME_DB_ARGS "-n "
1402 
1403 #define GDK_PIXBUF_QUERY_LOADER "usr/bin/gdk-pixbuf-query-loaders"
1404 #define GDK_PIXBUF_QUERY_LOADER_ARGS "--update-cache"
1405 
1406 #define GIO_QUERYMODULES "usr/bin/gio-querymodules"
1407 #define GIO_QUERYMODULES_ARGS "usr/lib/gio/modules"
1408 
1409 #define QUERY_IMMODULES_3 "usr/bin/gtk-query-immodules-3.0"
1410 #define QUERY_IMMODULES_3_ARGS "--update-cache"
1411 
1412 #define QUERY_IMMODULES_2 "usr/bin/gtk-query-immodules-2.0"
1413 #define QUERY_IMMODULES_2_ARGS "--update-cache"
1414 
1415 #define MKFONTDIR "usr/bin/mkfontdir"
1416 #define MKFONTDIR_ARGS ""
1417 
1418 #define MKFONTSCALE "usr/bin/mkfontscale"
1419 #define MKFONTSCALE_ARGS ""
1420 
1421 #define FC_CACHE "usr/bin/fc-cache"
1422 #define FC_CACHE_ARGS ""
1423 
1424 enum action
1425 {
1426 PKG_DOWNLOAD_START,
1427 PKG_DOWNLOAD_RUN,
1428 PKG_DOWNLOAD_END,
1429 DB_OPEN_START,
1430 DB_OPEN_RUN,
1431 DB_OPEN_END,
1432 PKG_PREINSTALL_START,
1433 PKG_PREINSTALL_END,
1434 PKG_INSTALL_START,
1435 PKG_INSTALL_END,
1436 PKG_INSTALL_RUN,
1437 PKG_POSTINSTALL_START,
1438 PKG_POSTINSTALL_END,
1439 PKG_MOVE_META_START,
1440 PKG_MOVE_META_END,
1441 DB_ADD_PKG_START,
1442 DB_ADD_PKG_END,
1443 LDCONFIG_START,
1444 LDCONFIG_END,
1445 RM_PKG_FILES_START,
1446 RM_PKG_FILES_RUN,
1447 RM_PKG_FILES_END
1448 };
1449 
1450 struct pkginfo_t {
1451  std::string base;
1452  std::string group;
1453  std::string collection;
1454  std::string description;
1455  std::string signature;
1456  time_t build; // date of build
1457  std::string version;
1458  int release;
1459  std::string url;
1460  std::string contributors;
1461  std::string packager;
1462  std::string maintainer;
1463  time_t install; // date of last installation
1464  std::string arch;
1465  int size;
1466  std::set< std::pair<std::string,time_t> > dependencies;
1467  std::set<std::string> alias;
1468  std::set<std::string> files;
1469 };
1470 typedef std::map<std::string, pkginfo_t> packages_t;
1471 typedef std::map<std::string, std::string> alias_t;
1472 
1473 enum rule_event_t {
1474  LDCONF,
1475  UPGRADE,
1476  INSTALL,
1477  INFO,
1478  ICONS,
1479  FONTS,
1480  SCHEMAS,
1481  DESKTOP_DB,
1482  MIME_DB,
1483  QUERY_PIXBUF,
1484  GIO_QUERY,
1485  QUERY_IMOD3,
1486  QUERY_IMOD2
1487 };
1488 
1489 struct rule_t {
1490  rule_event_t event;
1491  std::string pattern;
1492  bool action;
1493 };
1494 
1495 class Pkgdbh {
1496 public:
1497 
1498  explicit Pkgdbh(const std::string& name);
1499  virtual ~Pkgdbh();
1500 
1501  /* Following methods can be redefined in derivated class */
1502  virtual void parseArguments(int argc, char** argv);
1503  virtual void run(int argc, char** argv) {};
1504  virtual void run() {};
1505 
1506  virtual void printHelp() const {};
1507 
1508  virtual void progressInfo();
1509  virtual void treatErrors(const std::string& s) const;
1510 
1511 
1512  void print_version() const;
1513  int getNumberOfPackages();
1514  std::set<std::string> getListOfPackageName();
1515  bool checkPackageNameExist(const std::string& name) const;
1516  unsigned int getFilesNumber();
1517  unsigned int getInstalledFilesNumber();
1518  std::set<std::string> getFilesList();
1519 
1520 protected:
1521  // Database
1522 
1523  std::set<std::string> getFilesOfPackage(const std::string& packageName);
1524  int getListOfPackageNames(const std::string& path);
1525  std::pair<std::string, pkginfo_t> getInfosPackage(const std::string& packageName);
1526  void buildSimpleDatabase();
1527  void buildCompleteDatabase(const bool& silent);
1528  void buildDatabase(const bool& progress,
1529  const bool& simple,
1530  const bool& all,
1531  const bool& files,
1532  const std::string& packageName);
1533 
1534 
1535  void addPackageFilesRefsToDB(const std::string& name,
1536  const pkginfo_t& info);
1537 
1538  bool checkPackageNameUptodate(const std::pair<std::string,
1539  pkginfo_t>& archiveName);
1540  bool checkPackageNameBuildDateSame(const std::pair<std::string,
1541  time_t>& dependencieNameBuild);
1542 
1543  /*
1544  * Remove the physical files after followings some rules
1545  */
1546  void removePackageFiles(const std::string& name);
1547  void removePackageFiles(const std::string& name,
1548  const std::set<std::string>& keep_list);
1549 
1550  /*
1551  * Remove meta data about the removed package
1552  */
1553  void removePackageFilesRefsFromDB(const std::string& name);
1554  void removePackageFilesRefsFromDB(std::set<std::string> files,
1555  const std::set<std::string>& keep_list);
1556  std::set<std::string> getConflictsFilesList(const std::string& name,
1557  const pkginfo_t& info);
1558 
1559  // Tar.gz
1560  std::pair<std::string, pkginfo_t> openArchivePackage(const std::string& filename);
1561  std::set< std::pair<std::string, time_t> > getPackageDependencies(const std::string& filename);
1562  void extractAndRunPREfromPackage(const std::string& filename);
1563  void installArchivePackage(const std::string& filename,
1564  const std::set<std::string>& keep_list,
1565  const std::set<std::string>& non_install_files);
1566 
1567  /*
1568  * The folder holding the meta datas is going to be create here
1569  */
1570  void moveMetaFilesPackage(const std::string& name, pkginfo_t& info);
1571 
1572 
1573  void readRulesFile();
1574  void getInstallRulesList(const std::vector<rule_t>& rules,
1575  rule_event_t event, std::vector<rule_t>& found) const;
1576  bool checkRuleAppliesToFile(const rule_t& rule,
1577  const std::string& file);
1578 
1579  void getFootprintPackage(std::string& filename);
1580 
1581  std::string m_packageArchiveName;
1582  std::string m_packageName;
1583  std::string m_packageArchiveVersion;
1584  std::string m_packageArchiveRelease;
1585  std::string m_packageArchiveCollection;
1586  std::string m_packageVersion;
1587  std::string m_packageRelease;
1588  std::string m_packageCollection;
1589  std::string m_utilName;
1590  std::string m_root;
1591  std::string m_build;
1592  std::vector<rule_t> m_actionRules;
1593  std::set< std::pair<std::string, int> > m_postInstallList;
1594  alias_t m_listOfAlias;
1595 
1596  packages_t m_listOfInstPackages;
1597  packages_t m_listOfDepotPackages;
1598 
1599  action m_actualAction;
1600  error m_actualError;
1601 
1602 private:
1603 
1604  void runLastPostInstall();
1605 
1606  std::set<std::string> m_runtimeLibrariesList;
1607  std::set<std::string> m_filesList;
1608  std::set<std::string> m_packageNamesList;
1609  unsigned int m_filesNumber;
1610  unsigned int m_installedFilesNumber;
1611 
1612 
1613  bool m_DB_Empty;
1614  bool m_miniDB_Empty;
1615 };
1616 
1617 class Db_lock {
1618 public:
1619  Db_lock(const std::string& m_root, bool exclusive);
1620  ~Db_lock();
1621 
1622 private:
1623  DIR* m_dir;
1624  struct sigaction m_sa;
1625 };
1626 
1627 void assertArgument(char** argv, int argc, int index);
1628 void rotatingCursor();
1629 
1643 class Pkgadd : public Pkgdbh {
1644 public:
1648  Pkgadd();
1654  Pkgadd(const std::string& commandName);
1655  void parseArguments(int argc, char** argv);
1656  void preRun();
1657  void postRun();
1658  virtual void run();
1659  virtual void run(int argc, char** argv);
1660  virtual void printHelp() const;
1661 
1662 protected:
1663  bool m_runPrePost;
1664  bool m_upgrade;
1665  bool m_force;
1666 private:
1667  std::set<std::string> getKeepFileList(const std::set<std::string>& files,
1668  const std::vector<rule_t>& rules);
1669  std::set<std::string> applyInstallRules(const std::string& name,
1670  pkginfo_t& info,
1671  const std::vector<rule_t>& rules);
1672  void applyPostInstallRules(const std::string& name,
1673  pkginfo_t& info,
1674  const std::vector<rule_t>& rules);
1675  void getInstallRulesList(const std::vector<rule_t>& rules,
1676  rule_event_t event,
1677  std::vector<rule_t>& found) const;
1678  void getPostInstallRulesList(const std::vector<rule_t>& rules,
1679  std::vector<rule_t>& found) const;
1680 };
1681 
1688 class Pkgrm : public Pkgdbh {
1689 public:
1690  Pkgrm(const std::string& commandName) : Pkgdbh(commandName) {}
1691  Pkgrm();
1692  void run();
1693  void run(int argc, char** argv);
1694  void printHelp() const;
1695 };
1696 
1697 
1704 #include <sstream>
1705 #include <iomanip>
1706 
1707 
1708 class Pkginfo : public Pkgdbh {
1709 public:
1710  Pkginfo(const std::string& commandName);
1711  Pkginfo();
1712  virtual void run(int argc, char** argv);
1713  virtual void parseArguments(int argc, char** argv);
1714  virtual void run();
1715  virtual void finish();
1716  virtual void printHelp() const;
1717 
1718 protected:
1719  std::string m_arg;
1720  int m_runtimedependencies_mode;
1721  int m_footprint_mode;
1722  int m_archiveinfo;
1723  int m_installed_mode;
1724  int m_list_mode;
1725  int m_owner_mode;
1726  int m_details_mode;
1727  int m_libraries_mode;
1728  int m_runtime_mode;
1729  int m_epoc;
1730 
1731 };
1732 
1733 
1734 
1735 
1736 
1737 class Pkginst : public Pkgadd, public Repodwl {
1738 public:
1739  Pkginst(const std::string& commandName, const char *configFileName);
1740  void generateDependencies(const std::pair<std::string,time_t>& packageName);
1741  void generateDependencies();
1742 
1743 protected:
1744  std::vector<std::string> m_dependenciesList;
1745 };
1746 
1747 
1748 #include <cstring>
1749 #include <cstdlib>
1750 #include <iostream>
1751 
1752 
1753 #include <curl/curl.h>
1754 #include <sys/types.h>
1755 #include <sys/stat.h>
1756 #include <unistd.h>
1757 #include <libgen.h>
1758 #include <dirent.h>
1759 
1760 class Pkgsync
1761 {
1762 public:
1767  Pkgsync();
1768  Pkgsync(const std::string& url,
1769  const std::string& directory,
1770  const std::string& repoFile);
1771 
1772  virtual void treatErrors(const std::string& s) const;
1773 
1774  virtual void run();
1775  virtual void purge();
1776  static const std::string DEFAULT_REPOFILE;
1777 
1778  void setRootPath(const std::string& path);
1779  void setConfigFile(const std::string& file);
1780 
1781 private:
1782 
1783  unsigned int getLocalPackages(const std::string& path);
1784  unsigned int getRemotePackages(const std::string& pkgrepoFile);
1785 
1786  void deleteFolder(const std::string& folderName);
1787 
1788  std::set<std::string> m_localPackagesList;
1789  std::set<std::string> m_remotePackagesList;
1790  const std::string m_baseDirectory;
1791  const std::string m_remoteUrl;
1792  std::string m_repoFile;
1793  std::string m_root;
1794  std::string m_configFile;
1795  error m_actualError;
1796 
1797 
1798 };
1799 
1800 #endif
1801 // vim:set ts=2 :
std::string args()
Definition: process.cxx:55
int execute()
Definition: process.cxx:59
Pkgsync()
Definition: pkgsync.cxx:26
Definition: libcards.h:845
std::set< Pkg * > getListOfPackages()
Definition: pkgrepo.cxx:401
Definition: libcards.h:1450
Definition: libcards.h:481
Definition: libcards.h:930
Definition: libcards.h:879
Definition: libcards.h:1489
int executeShell()
Definition: process.cxx:175
Definition: libcards.h:1708
std::vector< RepoInfo > getRepoInfo()
Definition: pkgrepo.cxx:432
Definition: error_treat.h:88
std::string getCollection()
Return.
Definition: pkg.cxx:61
void parseCollectionDirectory()
Definition: pkgrepo.cxx:164
void buildSimpleDatabase()
Definition: pkgdbh.cxx:479
std::string getBasePackageVersion(const std::string &packageName)
Definition: archive_utils.h:67
File Download Event class.
Definition: file_download.h:62
time_t getBinaryBuildTime(const std::string &portName)
Definition: libcards.h:924
Definition: file_utils.h:64
void buildCompleteDatabase(const bool &silent)
Definition: pkgdbh.cxx:538
void parsePackagePkgfileFile()
Definition: pkgrepo.cxx:277
Definition: libcards.h:916
std::set< std::string > getBinaryPackageList()
Definition: pkgrepo.cxx:365
void downloadPortsPkgRepo(const std::string &packageName)
Pkgadd()
Definition: pkgadd.cxx:28
File Download State class.
Definition: file_download.h:43
Definition: libcards.h:897
FileDownload(std::string url, std::string dirName, std::string fileName, bool progress)
Definition: file_download.cxx:67
virtual void OnFileDownloadProgressInfo(FileDownloadState state)
Definition: libcards.h:1188
void parseCurrentPackagePkgRepoFile()
Definition: pkgrepo.cxx:192
Definition: libcards.h:472
void buildDatabase(const bool &progress, const bool &simple, const bool &all, const bool &files, const std::string &packageName)
Definition: pkgdbh.cxx:363
std::set< std::string > getListOutOfDate()
Definition: pkgrepo.cxx:260
Definition: libcards.h:1688
Pkg()
Constructor.
Definition: pkg.cxx:29
Definition: libcards.h:1760
Pkgadd class.
Definition: libcards.h:1643
Definition: libcards.h:443
unsigned int getPortsList()
Definition: pkgrepo.cxx:462
int getBasePackageRelease(const std::string &packageName)
Definition: file_utils.h:69
bool checkPortExist(const std::string &portName)
File Download class.
Definition: file_download.h:87
Definition: libcards.h:1617
std::string getBasePackageName(const std::string &packageName)
std::string getPortDir(const std::string &portName)
Definition: pkgrepo.cxx:569
Definition: libcards.h:1310
Definition: file_utils.h:53
std::string getPortVersion(const std::string &portName)
Definition: libcards.h:1107
~Pkg()
Destructor.
Definition: pkg.cxx:35
Definition: libcards.h:1495
~FileDownload()
Definition: libcards.h:1236
std::string name()
Definition: process.cxx:51
void downloadPackageFileName(const std::string &packageFileName)
int getPortRelease(const std::string &portName)
Definition: libcards.h:1737
std::string getBasePortName(const std::string &portName)
std::set< std::string > getListOfPackagesFromCollection(const std::string &collectionName)
void parsePkgRepoCollectionFile()
Definition: pkgrepo.cxx:44