CARDS 2.4.140
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
14freedom to share and change it. By contrast, the GNU General Public
15License is intended to guarantee your freedom to share and change free
16software--to make sure the software is free for all its users. This
17General Public License applies to most of the Free Software
18Foundation's software and to any other program whose authors commit to
19using it. (Some other Free Software Foundation software is covered by
20the GNU Library General Public License instead.) You can apply it to
21your programs, too.
22
23 When we speak of free software, we are referring to freedom, not
24price. Our General Public Licenses are designed to make sure that you
25have the freedom to distribute copies of free software (and charge for
26this service if you wish), that you receive source code or can get it
27if you want it, that you can change the software or use pieces of it
28in 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
31anyone to deny you these rights or to ask you to surrender the rights.
32These restrictions translate to certain responsibilities for you if you
33distribute copies of the software, or if you modify it.
34
35 For example, if you distribute copies of such a program, whether
36gratis or for a fee, you must give the recipients all the rights that
37you have. You must make sure that they, too, receive or can get the
38source code. And you must show them these terms so they know their
39rights.
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,
43distribute and/or modify the software.
44
45 Also, for each author's protection and ours, we want to make certain
46that everyone understands that there is no warranty for this free
47software. If the software is modified by someone else and passed on, we
48want its recipients to know that what they have is not the original, so
49that any problems introduced by others will not reflect on the original
50authors' reputations.
51
52 Finally, any free program is threatened constantly by software
53patents. We wish to avoid the danger that redistributors of a free
54program will individually obtain patent licenses, in effect making the
55program proprietary. To prevent this, we have made it clear that any
56patent must be licensed for everyone's free use or not licensed at all.
57
58 The precise terms and conditions for copying, distribution and
59modification 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
65a notice placed by the copyright holder saying it may be distributed
66under the terms of this General Public License. The "Program", below,
67refers to any such program or work, and a "work based on the Program"
68means either the Program or any derivative work under copyright law:
69that is to say, a work containing the Program or a portion of it,
70either verbatim or with modifications and/or translated into another
71language. (Hereinafter, translation is included without limitation in
72the term "modification".) Each licensee is addressed as "you".
73
74Activities other than copying, distribution and modification are not
75covered by this License; they are outside its scope. The act of
76running the Program is not restricted, and the output from the Program
77is covered only if its contents constitute a work based on the
78Program (independent of having been made by running the Program).
79Whether that is true depends on what the Program does.
80
81 1. You may copy and distribute verbatim copies of the Program's
82source code as you receive it, in any medium, provided that you
83conspicuously and appropriately publish on each copy an appropriate
84copyright notice and disclaimer of warranty; keep intact all the
85notices that refer to this License and to the absence of any warranty;
86and give any other recipients of the Program a copy of this License
87along with the Program.
88
89You may charge a fee for the physical act of transferring a copy, and
90you 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
93of it, thus forming a work based on the Program, and copy and
94distribute such modifications or work under the terms of Section 1
95above, 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
116These requirements apply to the modified work as a whole. If
117identifiable sections of that work are not derived from the Program,
118and can be reasonably considered independent and separate works in
119themselves, then this License, and its terms, do not apply to those
120sections when you distribute them as separate works. But when you
121distribute the same sections as part of a whole which is a work based
122on the Program, the distribution of the whole must be on the terms of
123this License, whose permissions for other licensees extend to the
124entire whole, and thus to each and every part regardless of who wrote it.
125
126Thus, it is not the intent of this section to claim rights or contest
127your rights to work written entirely by you; rather, the intent is to
128exercise the right to control the distribution of derivative or
129collective works based on the Program.
130
131In addition, mere aggregation of another work not based on the Program
132with the Program (or with a work based on the Program) on a volume of
133a storage or distribution medium does not bring the other work under
134the scope of this License.
135
136 3. You may copy and distribute the Program (or a work based on it,
137under Section 2) in object code or executable form under the terms of
138Sections 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
157The source code for a work means the preferred form of the work for
158making modifications to it. For an executable work, complete source
159code means all the source code for all modules it contains, plus any
160associated interface definition files, plus the scripts used to
161control compilation and installation of the executable. However, as a
162special exception, the source code distributed need not include
163anything that is normally distributed (in either source or binary
164form) with the major components (compiler, kernel, and so on) of the
165operating system on which the executable runs, unless that component
166itself accompanies the executable.
167
168If distribution of executable or object code is made by offering
169access to copy from a designated place, then offering equivalent
170access to copy the source code from the same place counts as
171distribution of the source code, even though third parties are not
172compelled to copy the source along with the object code.
173
174 4. You may not copy, modify, sublicense, or distribute the Program
175except as expressly provided under this License. Any attempt
176otherwise to copy, modify, sublicense or distribute the Program is
177void, and will automatically terminate your rights under this License.
178However, parties who have received copies, or rights, from you under
179this License will not have their licenses terminated so long as such
180parties remain in full compliance.
181
182 5. You are not required to accept this License, since you have not
183signed it. However, nothing else grants you permission to modify or
184distribute the Program or its derivative works. These actions are
185prohibited by law if you do not accept this License. Therefore, by
186modifying or distributing the Program (or any work based on the
187Program), you indicate your acceptance of this License to do so, and
188all its terms and conditions for copying, distributing or modifying
189the Program or works based on it.
190
191 6. Each time you redistribute the Program (or any work based on the
192Program), the recipient automatically receives a license from the
193original licensor to copy, distribute or modify the Program subject to
194these terms and conditions. You may not impose any further
195restrictions on the recipients' exercise of the rights granted herein.
196You are not responsible for enforcing compliance by third parties to
197this License.
198
199 7. If, as a consequence of a court judgment or allegation of patent
200infringement or for any other reason (not limited to patent issues),
201conditions are imposed on you (whether by court order, agreement or
202otherwise) that contradict the conditions of this License, they do not
203excuse you from the conditions of this License. If you cannot
204distribute so as to satisfy simultaneously your obligations under this
205License and any other pertinent obligations, then as a consequence you
206may not distribute the Program at all. For example, if a patent
207license would not permit royalty-free redistribution of the Program by
208all those who receive copies directly or indirectly through you, then
209the only way you could satisfy both it and this License would be to
210refrain entirely from distribution of the Program.
211
212If any portion of this section is held invalid or unenforceable under
213any particular circumstance, the balance of the section is intended to
214apply and the section as a whole is intended to apply in other
215circumstances.
216
217It is not the purpose of this section to induce you to infringe any
218patents or other property right claims or to contest validity of any
219such claims; this section has the sole purpose of protecting the
220integrity of the free software distribution system, which is
221implemented by public license practices. Many people have made
222generous contributions to the wide range of software distributed
223through that system in reliance on consistent application of that
224system; it is up to the author/donor to decide if he or she is willing
225to distribute software through any other system and a licensee cannot
226impose that choice.
227
228This section is intended to make thoroughly clear what is believed to
229be a consequence of the rest of this License.
230
231 8. If the distribution and/or use of the Program is restricted in
232certain countries either by patents or by copyrighted interfaces, the
233original copyright holder who places the Program under this License
234may add an explicit geographical distribution limitation excluding
235those countries, so that distribution is permitted only in or among
236countries not thus excluded. In such case, this License incorporates
237the limitation as if written in the body of this License.
238
239 9. The Free Software Foundation may publish revised and/or new versions
240of the General Public License from time to time. Such new versions will
241be similar in spirit to the present version, but may differ in detail to
242address new problems or concerns.
243
244Each version is given a distinguishing version number. If the Program
245specifies a version number of this License which applies to it and "any
246later version", you have the option of following the terms and conditions
247either of that version or of any later version published by the Free
248Software Foundation. If the Program does not specify a version number of
249this License, you may choose any version ever published by the Free Software
250Foundation.
251
252 10. If you wish to incorporate parts of the Program into other free
253programs whose distribution conditions are different, write to the author
254to ask for permission. For software which is copyrighted by the Free
255Software Foundation, write to the Free Software Foundation; we sometimes
256make exceptions for this. Our decision will be guided by the two goals
257of preserving the free status of all derivatives of our free software and
258of 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
263FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
264OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
265PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
266OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
267MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
268TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
269PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
270REPAIR OR CORRECTION.
271
272 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
273WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
274REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
275INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
276OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
277TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
278YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
279PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
280POSSIBILITY 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
287possible use to the public, the best way to achieve this is to make it
288free 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
291to attach them to the start of each source file to most effectively
292convey the exclusion of warranty; and each file should have at least
293the "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
312Also add information on how to contact you by electronic and paper mail.
313
314If the program is interactive, make it output a short notice like this
315when 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
322The hypothetical commands `show w' and `show c' should show the appropriate
323parts of the General Public License. Of course, the commands you use may
324be called something other than `show w' and `show c'; they could even be
325mouse-clicks or menu items--whatever suits your program.
326
327You should also get your employer (if you work as a programmer) or your
328school, if any, to sign a "copyright disclaimer" for the program, if
329necessary. 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
337This General Public License does not permit incorporating your program into
338proprietary programs. If your program is a subroutine library, you may
339consider it more useful to permit linking proprietary applications with the
340library. If this is what you want to do, use the GNU Library General
341Public 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
364std::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
388enum error
389{
390CANNOT_FIND_DEPOT,
391CANNOT_DOWNLOAD_FILE,
392CANNOT_CREATE_FILE,
393CANNOT_OPEN_FILE,
394CANNOT_FIND_FILE,
395CANNOT_READ_FILE,
396CANNOT_COPY_FILE,
397CANNOT_PARSE_FILE,
398CANNOT_READ_DIRECTORY,
399CANNOT_WRITE_FILE,
400CANNOT_SYNCHRONIZE,
401CANNOT_RENAME_FILE,
402CANNOT_DETERMINE_NAME_BUILDNR,
403WRONG_ARCHITECTURE,
404EMPTY_PACKAGE,
405CANNOT_FORK,
406WAIT_PID_FAILED,
407DATABASE_LOCKED,
408CANNOT_LOCK_DIRECTORY,
409CANNOT_REMOVE_FILE,
410CANNOT_CREATE_DIRECTORY,
411CANNOT_RENAME_DIRECTORY,
412OPTION_ONE_ARGUMENT,
413INVALID_OPTION,
414OPTION_MISSING,
415TOO_MANY_OPTIONS,
416ONLY_ROOT_CAN_INSTALL_UPGRADE_REMOVE,
417PACKAGE_NOT_EXIST,
418PACKAGE_NOT_FOUND,
419PACKAGE_ALLREADY_INSTALL,
420PACKAGE_NOT_INSTALL,
421PACKAGE_NOT_PREVIOUSLY_INSTALL,
422LISTED_FILES_ALLREADY_INSTALLED,
423PKGADD_CONFIG_LINE_TOO_LONG,
424PKGADD_CONFIG_WRONG_NUMBER_ARGUMENTS,
425PKGADD_CONFIG_UNKNOWN_ACTION,
426PKGADD_CONFIG_UNKNOWN_EVENT,
427CANNOT_COMPILE_REGULAR_EXPRESSION,
428CANNOT_GENERATE_LEVEL,
429NOT_INSTALL_PACKAGE_NEITHER_PACKAGE_FILE
430};
431
432class RunTimeErrorWithErrno : public std::runtime_error
433{
434 public:
435 explicit RunTimeErrorWithErrno(const std::string& msg) throw();
436 explicit RunTimeErrorWithErrno(const std::string& msg, int e) throw();
437};
438
439
440#include <string.h>
441
442#define uint8 unsigned char
443#define uint32 unsigned long int
444
446{
447 uint32 total[2];
448 uint32 state[4];
449 uint8 buffer[64];
450};
451
452void md5_starts( struct md5_context *ctx );
453void md5_update( struct md5_context *ctx, uint8 *input, uint32 length );
454void md5_finish( struct md5_context *ctx, uint8 digest[16] );
455
456
457
458
459#include <fstream>
460#include <map>
461#include <set>
462#include <vector>
463
464#include <sys/stat.h>
465
466#define GIGA 1e9
467#define MEGA 1e6
468#define KILO 1e3
469#define PACKAGE_LOCALE_DIR "/usr/share/locale"
470#define GETTEXT_PACKAGE "cards"
471
472void *Malloc(size_t s);
473
474struct keyValue
475{
476 std::string parameter;
477 std::string value;
478};
479
483typedef struct
484{
485 char **items;
486 unsigned int count;
487} itemList;
488
492itemList *initItemList(void);
493
497void addItemToItemList(itemList *list, const char *item);
498
503void freeItemList(itemList *list);
504
508keyValue splitKeyValue
509(std::string s, char delimiter);
510
511std::set<std::string> getKeysList
512(std::string file, std::string delimiter);
513
514std::string getValueOfKey
515(std::string file, std::string delimiter,std::string parameter);
516
517std::string getValue(const std::string& s, char delimiter);
518std::string getValueBefore( const std::string& s, char del );
519std::string getValueBeforeLast( const std::string& s, char del );
520
521std::string itos(unsigned int value);
522std::string ultos(unsigned long int value);
523
524std::string mtos(mode_t mode);
525std::string trimFileName(const std::string& filename);
526std::string sizeHumanRead(int value);
527
528/*param s the string to be searched, param delimiter the delimiter char
529return the value after the first occurance of a delimiter */
530std::string getFirstValueOfKeyAfterDelim(const std::string& s, char delimiter);
531
532/* strip whitespace in the beginning and end of string, return a stripped string */
533std::string stripWhiteSpace(const std::string& s);
534
535/* populate a vector of string with delimited characters */
536std::vector<std::string> parseDelimitedVectorList
537(const std::string& s, const char *delimiter);
538
539/* populate a set of string with delimited characters */
540std::set<std::string> parseDelimitedSetList
541(const std::string& s, const char *delimiter);
542
543/* make sure s1 starts with s2 */
544bool startsWith(const std::string& s, const std::string& with);
545
550bool startsWithNoCase(const std::string& s1, const std::string& s2);
551
552std::string convertToLowerCase(const std::string& s);
553std::string convertToUpperCase(const std::string& s);
554
555std::string replaceAll
556( std::string& in, const std::string& oldString, const std::string& newString );
557
567template <class T>
568void 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
617enum {
618 WALK_OK = 0,
619 WALK_BADPATTERN,
620 WALK_NAMETOOLONG,
621 WALK_BADIO
622};
623
624struct 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
635struct DirUrl {
636 std::string Dir;
637 std::string Url;
638};
639
640struct 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 url;
652 std::string logdir;
653 std::vector<std::string> group;
654 std::vector<DirUrl> dirUrl;
655 std::vector<std::string> baseDir;
656 std::vector<std::string> archs;
657};
658
659int getConfig(const char *fileName, Config& config);
660void * getDatas ( void * var, FILE * file, long offset, size_t size, size_t nmemb);
661std::string trimFileName(const std::string& filename);
662time_t getEpochModifyTimeFile(const std::string& filename);
663std::string getDateFromEpoch(const time_t& epoch);
664std::string getModifyTimeFile(const std::string& filename);
665bool checkFileExist(const std::string& filename);
666bool checkFileEmpty(const std::string& filename);
667bool checkRegularFile(const std::string& filename);
668bool checkFileSignature(const std::string& filename, const std::string& signature);
669bool checkFilesEqual(const std::string& file1, const std::string& file2);
670bool checkPermissionsEqual(const std::string& file1, const std::string& file2);
671bool createRecursiveDirs(const std::string& pathname);
672void cleanupMetaFiles(const std::string& basedir);
673void removeFile(const std::string& basedir, const std::string& filename);
674int copyFile(const char * destFile, const char * origFile);
675int findFile(std::set<std::string>& filesList, const std::string& basedir);
676int findDir(itemList *filenameList, const char *path);
677int findRecursiveFile(std::set<std::string>& filenameList, const char *filename, int spec);
678int readFileStripSpace(itemList *fileContent, const char *fileName);
679int readFile(itemList *fileContent, const char *fileName);
680int parseFile(std::set<std::string>& fileContent, const char* fileName);
681int parseFile(std::vector<std::string>& fileContent, const char* fileName);
682int parseFile(std::string& Depends, const char* key, const char* fileName);
683bool findMD5sum(const std::string& fileName, unsigned char* result);
684bool checkMD5sum(const char * fileName, const char * MD5Sum);
685/* read a file
686 return it into a template container */
687template <class T>
688int parseFile( T& target, const char* fileName)
689{
690 FILE *fp = fopen (fileName, "r");
691 if (!fp)
692 return -1;
693 const int length = BUFSIZ;
694 char input[length];
695 std::string line;
696 while (fgets(input, length, fp)) {
697 input[strlen(input)-1] = '\0';
698 line = input;
699 target.push_back(line);
700 }
701 fclose(fp);
702 return 0;
703}
704
705
706
707
708
709#include <archive.h>
710#include <archive_entry.h>
711
712
713#if ARCHIVE_VERSION_NUMBER >= 3000000
714#define INIT_ARCHIVE(ar) \
715 archive_read_support_filter_gzip((ar)); \
716 archive_read_support_filter_bzip2((ar)); \
717 archive_read_support_filter_xz((ar)); \
718 archive_read_support_filter_zstd((ar)); \
719 archive_read_support_format_tar((ar))
720#define FREE_ARCHIVE(ar) \
721 archive_read_free((ar))
722#else
723#define INIT_ARCHIVE(ar) \
724 archive_read_support_compression_gzip((ar)); \
725 archive_read_support_compression_bzip2((ar)); \
726 archive_read_support_compression_xz((ar)); \
727 archive_read_support_format_tar((ar))
728#define FREE_ARCHIVE(ar) \
729 archive_read_finish((ar))
730#endif
731
732#define DEFAULT_BYTES_PER_BLOCK (20 * 512)
733#define METAFILE ".META"
734#define INFOFILE ".INFO"
735#define MTREEFILE ".MTREE"
736
737enum archive_error
738{
739CANNOT_OPEN_ARCHIVE,
740CANNOT_READ_ARCHIVE,
741CANNOT_FIND_META_FILE,
742CANNOT_FIND_MTREE_FILE,
743CANNOT_FIND_NAME,
744CANNOT_FIND_ARCH,
745EMPTY_ARCHIVE
746};
747
748
749class ArchiveUtils
750{
751 public:
752
753
754 ArchiveUtils(const std::string& fileName);
755 virtual ~ArchiveUtils();
756
757 virtual void treatErrors(const std::string& s) const;
758
759 void printDeps(); // Print Out the dependencies
760 void printMeta(); // Print Out the .META file
761 void printInfo(); // the .INFO file
762 void list(); // list the files to stdio
763
764
765 unsigned int long size(); // Numbers of files in the archive
766 std::set<std::string> setofFiles(); // return a order set of string
767 std::set<std::string> listofDependencies(); // return an order set of dependencies
768 std::set<std::string> listofAlias(); // return the alias list
769 std::set<std::pair<std::string,time_t> > listofDependenciesBuildDate(); // return an order set of dependencies,BuildDate
770 std::string arch(); // return the arch of the package
771 std::string version(); // return the version of the package
772 int release(); // return the release of the package
773 std::string description();// return the description of the package
774 std::string url(); // return the url of the package
775 std::string contributors(); // return the Contributor(s) of the package
776 std::string maintainer(); // return the Maintainer(s) of the package
777 std::string collection(); // return the collection of the package
778 std::string packager(); // return the Packager(s) of the package
779 std::string builddate(); // return the date like Mon Mar 24 10:16:00 2014
780 std::string name(); // return the name of the package
781 std::string group(); // return the group of the package
782 std::string namebuildn(); // return the name + epochvalue
783 std::string epochBuildDate(); // return the epochvalue in string format
784 time_t buildn(); // return the epoch value
785
786 private:
787
788 std::string getPackageName();
789 std::string getPackageArch();
790 std::vector<std::string> extractFileContent(const char * fileName);
791 void getRunTimeDependencies();
792 void getRunTimeDependenciesEpoch();
793 void getAliasList();
794
795 unsigned int long m_size;
796
797 std::vector<std::string> m_contentMtree;
798 std::vector<std::string> m_contentMeta;
799 std::vector<std::string> m_contentInfo;
800
801 std::set<std::string> m_rtDependenciesList;
802 std::set<std::pair<std::string,time_t> > m_rtDependenciesEpochList;
803 std::string m_fileName;
804 std::string m_packageName;
805 std::string m_packageArch;
806 std::set<std::string> m_filesList;
807 std::set<std::string> m_aliasList;
808
809 archive_error m_actualError;
810};
811
812int openArchive(const char *fileName);
813
814/*
815 * pkg.h
816 *
817 * Copyright 2017 - 2021 NuTyX <tnut@nutyx.org>
818 *
819 * This program is free software; you can redistribute it and/or modify
820 * it under the terms of the GNU General Public License as published by
821 * the Free Software Foundation; either version 2 of the License, or
822 * (at your option) any later version.
823 *
824 * This program is distributed in the hope that it will be useful,
825 * but WITHOUT ANY WARRANTY; without even the implied warranty of
826 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
827 * GNU General Public License for more details.
828 *
829 * You should have received a copy of the GNU General Public License
830 * along with this program; if not, write to the Free Software
831 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
832 * MA 02110-1301, USA.
833 *
834 *
835 */
836
837#define PKG_H
838
839
840#include <string>
841
842enum CPSTATUS
843{
844 INSTALLED = 0x01,
845 TO_INSTALL = 0x02,
846 TO_REMOVE = 0x04,
847 TO_UPGRADE = 0x08
848};
849
850class Pkg
851{
852public:
853 Pkg();
854 ~Pkg();
855 std::string getName();
856 std::string getVersion();
857 std::string getPackager();
858 std::string getDescription();
859 std::string getCollection();
860 std::vector<std::string> getSet();
861 std::string getPrimarySet();
862 void setName(std::string& name);
863 void setDescription(std::string& description);
864 void setVersion(std::string& version);
865 void setCollection(std::string& collection);
866 void setSet(std::string& set);
867 void setPackager(std::string& packager);
868 bool isInstalled();
869 bool isToBeInstalled();
870 bool isToBeRemoved();
871 void setStatus(CPSTATUS pstatus);
872 void unSetStatus(CPSTATUS pstatus);
873 CPSTATUS getStatus();
874
875private:
876 std::string m_collection;
877 std::string m_set;
878 std::vector<std::string> m_setList;
879 std::string m_name;
880 std::string m_version;
881 std::string m_packager;
882 std::string m_description;
883 CPSTATUS m_status;
884};
885
886
887
888
890 std::string md5SUM;
891 std::string name;
892 std::string arch;
893};
894
901/*
902 **************************************************
903 * 73193bfc1cb30fe02a880ed088ed7590#1414192958#aalib#1.4rc5##n.a#n.a#n.a#n.a#.cards.tar.xz
904 * 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
905 *************************************************
906 */
908 std::string md5SUM;
909 std::string s_buildDate;
910 std::string basePackageName;
911 std::string extention;
912 std::string version;
913 int release;
914 std::string description;
915 std::string categories;
916 std::string URL;
917 std::string contributors;
918 std::string maintainer;
919 std::string packager;
920 std::string fileDate;
921 std::string alias;
922 std::string set;
923 std::string group;
924 time_t buildDate;
925 std::vector<PortFilesList> portFilesList;
926};
927
929 std::string Dir;
930 std::string Url;
931 std::vector<BasePackageInfo> basePackageList;
932};
936struct RepoInfo {
937 std::string branch;
938 std::string arch;
939 std::string collection;
940 std::vector<BasePackageInfo> basePackageList;
941};
942
944{
945public:
946
947 Pkgrepo(const std::string& fileName);
948 virtual ~Pkgrepo() { clearPackagesList(); }
949
950 static int parseConfig(const char *fileName,
951 Config& config);
952
953 void throwError(const std::string& s) const;
954
965 std::set<std::string> getListOutOfDate();
966
971 std::string getPortDir (const std::string& portName);
972
973
979 std::string getBasePortName (const std::string& portName);
984 std::string getBasePackageName(const std::string& packageName);
990 std::string getBasePackageVersion(const std::string& packageName);
994 std::string getPortVersion (const std::string& portName);
995
1000 int getBasePackageRelease (const std::string& packageName);
1001
1005 int getPortRelease(const std::string& portName);
1009 bool checkPortExist(const std::string& portName);
1010
1014 std::set<std::string> getListOfPackagesFromCollection(const std::string& collectionName);
1015
1019 std::set<std::string> getListOfPackagesFromSet(const std::string& collectionName);
1020
1024 time_t getBinaryBuildTime (const std::string& portName);
1025
1030 std::set<std::string> getBinaryPackageList();
1031
1036 std::set<Pkg*> getBinaryPackageSet();
1041 std::vector<RepoInfo> getRepoInfo();
1047 unsigned int getPortsList();
1048
1049 bool getBinaryPackageInfo(const std::string& packageName);
1050 bool getPortInfo(const std::string& portName);
1051
1052protected:
1057 int parseConfig(const char *fileName);
1058
1072
1084
1097
1104
1105
1106 bool m_parsePkgRepoCollectionFile;
1107 bool m_parseCollectionDirectory;
1108 bool m_parsePackagePkgfileFile;
1109
1110 std::vector<PortsDirectory>::iterator m_PortsDirectory_i;
1111 std::vector<BasePackageInfo>::iterator m_BasePackageInfo_i;
1112 std::vector<PortFilesList>::iterator m_PortFilesList_i;
1113
1114 std::vector<PortFilesList> m_portFilesList;
1115
1116 std::string m_configFileName;
1117 Config m_config;
1118
1119 std::vector<PortsDirectory> m_portsDirectoryList;
1120private:
1121 error m_ErrorCond;
1122 void clearPackagesList();
1123 std::set<Pkg*> m_packagesList;
1124};
1125#define REPODWL_H
1126
1127
1128class Repodwl: public Pkgrepo {
1129public:
1130 Repodwl(const char *fileName);
1141 void downloadPortsPkgRepo(const std::string& packageName);
1142
1153 void downloadPackageFileName(const std::string& packageName);
1154 bool checkBinaryExist(const std::string& packageName);
1155 std::string getPackageFileName(const std::string& packageName);
1156 std::string getPackageFileNameSignature(const std::string& packageName);
1157
1158 void setPackageFileName(const std::string& packageFileName);
1159
1160private:
1161 std::string m_packageFileName;
1162 std::string m_packageFileNameSignature;
1163};
1164
1171#include <curl/curl.h>
1172
1173
1174
1184{
1185 public:
1186 double dlnow;
1187 double dltotal;
1188 double dlspeed;
1189 std::string filename;
1190};
1191
1192class FileDownload;
1193
1203{
1204 friend FileDownload;
1205public:
1208
1209 protected:
1210
1217};
1218
1227class FileDownload
1228{
1229 public:
1230
1239 FileDownload(std::string url, std::string dirName, std::string fileName, bool progress);
1240
1251 FileDownload(std::string fileInfo, std::string url, std::string dirName, std::string fileName, std::string MD5Sum , bool progress);
1252
1260 FileDownload(std::vector<InfoFile> destinationFiles,bool progress);
1261
1266 {
1267 curl_slist_free_all(m_slist);
1268 curl_global_cleanup();
1269 curl_easy_cleanup(m_curl);
1270 }
1271
1272 static void SuscribeToEvents(FileDownloadEvent* callback);
1273 static void UnSuscribeFromEvents(FileDownloadEvent* callback);
1274
1275
1276 private:
1277
1281 bool checkMD5sum();
1282
1286 void downloadFile();
1287
1288 static int updateProgressHandle(void *p, double dltotal, double dlnow, double ultotal, double ulnow);
1289 static size_t writeToStreamHandle(void *buffer, size_t size, size_t nmemb, void *stream);
1290 int updateProgress(void *p, double dltotal, double dlnow, double ultotal, double ulnow);
1291 size_t writeToStream(void *buffer, size_t size, size_t nmemb, void *stream);
1292 void initFileToDownload(std::string _url, std::string _file);
1293
1297 bool checkUpToDate();
1298 void SendProgressEvent(FileDownloadState event);
1299 struct dwlProgress
1300 {
1301 std::string name;
1302 double lastruntime;
1303 CURL *curl;
1304 };
1305 struct curl_slist *m_slist;
1306
1307 CURL* m_curl;
1308 CURLcode m_curlCode;
1309 dwlProgress m_downloadProgress;
1310 InfoFile m_destinationFile;
1311 std::string m_url;
1312 std::string m_downloadFileName;
1313 std::string m_fileInfo;
1314 bool m_checkMD5;
1315 bool m_progress;
1316 std::string m_MD5Sum;
1317 static std::set<FileDownloadEvent*> m_arrCallBacks;
1318};
1319
1320
1321
1322
1323#include <list>
1324#include <cassert>
1325#include <cstddef>
1326#include <cstdlib>
1327#include <cstdio>
1328
1329#include <unistd.h>
1330#include <fcntl.h>
1331#include <sys/types.h>
1332#include <sys/wait.h>
1333
1334
1344{
1345public:
1346 process();
1347 process( const std::string& app, const std::string& args, int fileDescriptorLog=0 );
1348
1349 void execute(const std::string& app, const std::string& arguments, int fileDescriptorLog=0 );
1350
1355 int execute();
1356
1361 int executeShell();
1362
1366 std::string name();
1367
1371 std::string args();
1372
1373private:
1374
1375 int exec(const int argc, char** argv);
1376 int execLog(const int argc, char** argv);
1377
1378 int execShell(const char* shell);
1379 int execShellLog(const char* shell);
1380
1381 std::string m_application;
1382 std::string m_arguments;
1383 int m_fileDescriptorLog;
1384};
1385
1386
1387
1388
1389#include <stdio.h>
1390#include <stdlib.h>
1391#include <string.h>
1392#include <unistd.h>
1393#include <sys/stat.h>
1394
1395
1396int getRuntimeLibrariesList (std::set<std::string>& runtimeLibrariesList, const std::string& filename);
1397
1398
1405#include <stdexcept>
1406#include <csignal>
1407#include <algorithm>
1408
1409#include <regex.h>
1410#include <ext/stdio_filebuf.h>
1411#include <pwd.h>
1412#include <grp.h>
1413
1414
1415
1416#define LDCONFIG "sbin/ldconfig"
1417#define LDCONFIG_CONF "etc/ld.so.conf"
1418#define LDCONFIG_CONF_ARGS "-r "
1419#define SHELL "bin/sh"
1420
1421#define INSTALL_INFO "usr/bin/install-info"
1422#define INSTALL_INFO_ARGS "--info-dir=usr/share/info "
1423
1424#define UPDATE_ICON "usr/bin/gtk-update-icon-cache"
1425#define UPDATE_ICON_ARGS "-f -t "
1426
1427#define COMPILE_SCHEMAS "usr/bin/glib-compile-schemas"
1428#define COMPILE_SCHEMAS_ARGS ""
1429
1430#define UPDATE_DESKTOP_DB "usr/bin/update-desktop-database"
1431#define UPDATE_DESKTOP_DB_ARGS "-q "
1432
1433#define UPDATE_MIME_DB "usr/bin/update-mime-database"
1434#define UPDATE_MIME_DB_ARGS "-n "
1435
1436#define GDK_PIXBUF_QUERY_LOADER "usr/bin/gdk-pixbuf-query-loaders"
1437#define GDK_PIXBUF_QUERY_LOADER_ARGS "--update-cache"
1438
1439#define GIO_QUERYMODULES "usr/bin/gio-querymodules"
1440#define GIO_QUERYMODULES_ARGS "usr/lib/gio/modules"
1441
1442#define QUERY_IMMODULES_3 "usr/bin/gtk-query-immodules-3.0"
1443#define QUERY_IMMODULES_3_ARGS "--update-cache"
1444
1445#define QUERY_IMMODULES_2 "usr/bin/gtk-query-immodules-2.0"
1446#define QUERY_IMMODULES_2_ARGS "--update-cache"
1447
1448#define MKFONTDIR "usr/bin/mkfontdir"
1449#define MKFONTDIR_ARGS ""
1450
1451#define MKFONTSCALE "usr/bin/mkfontscale"
1452#define MKFONTSCALE_ARGS ""
1453
1454#define FC_CACHE "usr/bin/fc-cache"
1455#define FC_CACHE_ARGS ""
1456
1457enum action
1458{
1459PKG_DOWNLOAD_START,
1460PKG_DOWNLOAD_RUN,
1461PKG_DOWNLOAD_END,
1462DB_OPEN_START,
1463DB_OPEN_RUN,
1464DB_OPEN_END,
1465PKG_PREINSTALL_START,
1466PKG_PREINSTALL_END,
1467PKG_INSTALL_START,
1468PKG_INSTALL_END,
1469PKG_INSTALL_RUN,
1470PKG_POSTINSTALL_START,
1471PKG_POSTINSTALL_END,
1472PKG_MOVE_META_START,
1473PKG_MOVE_META_END,
1474DB_ADD_PKG_START,
1475DB_ADD_PKG_END,
1476LDCONFIG_START,
1477LDCONFIG_END,
1478RM_PKG_FILES_START,
1479RM_PKG_FILES_RUN,
1480RM_PKG_FILES_END
1481};
1482
1484 std::string group;
1485 std::string collection;
1486 std::string description;
1487 std::string signature;
1488 time_t build; // date of build
1489 std::string version;
1490 int release;
1491 std::string url;
1492 std::string contributors;
1493 std::string packager;
1494 std::string maintainer;
1495 time_t install; // date of last installation
1496 std::string arch;
1497 int size;
1498 bool dependency; // true it's a dependency: automaticaly install
1499 std::set< std::pair<std::string,time_t> > dependencies;
1500 std::set<std::string> alias;
1501 std::set<std::string> set;
1502 std::set<std::string> categories;
1503 std::set<std::string> files;
1504};
1505typedef std::map<std::string, pkginfo_t> packages_t;
1506typedef std::map<std::string, std::string> alias_t;
1507
1508enum rule_event_t {
1509 LDCONF,
1510 UPGRADE,
1511 INSTALL,
1512 INFO,
1513 ICONS,
1514 FONTS,
1515 SCHEMAS,
1516 DESKTOP_DB,
1517 MIME_DB,
1518 QUERY_PIXBUF,
1519 GIO_QUERY,
1520 QUERY_IMOD3,
1521 QUERY_IMOD2
1522};
1523
1524struct rule_t {
1525 rule_event_t event;
1526 std::string pattern;
1527 bool action;
1528};
1529
1530class Pkgdbh {
1531public:
1532
1533 explicit Pkgdbh(const std::string& name);
1534 virtual ~Pkgdbh();
1535
1536 /* Following methods can be redefined in derivated class */
1537 virtual void parseArguments(int argc, char** argv);
1538 virtual void run(int argc, char** argv) {};
1539 virtual void run() {};
1540
1541 virtual void printHelp() const {};
1542
1543 virtual void progressInfo();
1544 virtual void treatErrors(const std::string& s) const;
1545
1546
1547 void print_version() const;
1548 int getNumberOfPackages();
1549 std::set<std::string> getListOfPackageName();
1550
1551 bool checkPackageNameExist(const std::string& name) const;
1552 bool checkDependency(const std::string& name);
1553 void setDependency();
1554 void resetDependency();
1555
1556 unsigned int getFilesNumber();
1557 unsigned int getInstalledFilesNumber();
1558 std::set<std::string> getFilesList();
1559
1560protected:
1561 // Database
1562
1563 std::set<std::string> getFilesOfPackage(const std::string& packageName);
1564 int getListOfPackageNames(const std::string& path);
1565 std::pair<std::string, pkginfo_t> getInfosPackage(const std::string& packageName);
1566 void buildSimpleDatabase();
1568
1569 void buildCompleteDatabase(const bool& silent);
1570 void buildDatabase(const bool& progress,
1571 const bool& simple,
1572 const bool& all,
1573 const bool& files,
1574 const std::string& packageName);
1575
1576
1577 void addPackageFilesRefsToDB(const std::string& name,
1578 const pkginfo_t& info);
1579
1580 bool checkPackageNameUptodate(const std::pair<std::string,
1581 pkginfo_t>& archiveName);
1582 bool checkPackageNameBuildDateSame(const std::pair<std::string,
1583 time_t>& dependencieNameBuild);
1584
1585 /*
1586 * Remove the physical files after followings some rules
1587 */
1588 void removePackageFiles(const std::string& name);
1589 void removePackageFiles(const std::string& name,
1590 const std::set<std::string>& keep_list);
1591
1592 /*
1593 * Remove meta data about the removed package
1594 */
1595 void removePackageFilesRefsFromDB(const std::string& name);
1596 void removePackageFilesRefsFromDB(std::set<std::string> files,
1597 const std::set<std::string>& keep_list);
1598 std::set<std::string> getConflictsFilesList(const std::string& name,
1599 const pkginfo_t& info);
1600
1601 // Tar.gz
1602 std::pair<std::string, pkginfo_t> openArchivePackage(const std::string& filename);
1603 std::set< std::pair<std::string, time_t> > getPackageDependencies(const std::string& filename);
1604 void extractAndRunPREfromPackage(const std::string& filename);
1605 void installArchivePackage(const std::string& filename,
1606 const std::set<std::string>& keep_list,
1607 const std::set<std::string>& non_install_files);
1608
1609 /*
1610 * The folder holding the meta datas is going to be create here
1611 */
1612 void moveMetaFilesPackage(const std::string& name, pkginfo_t& info);
1613
1614
1615 void readRulesFile();
1616 void getInstallRulesList(const std::vector<rule_t>& rules,
1617 rule_event_t event, std::vector<rule_t>& found) const;
1618 bool checkRuleAppliesToFile(const rule_t& rule,
1619 const std::string& file);
1620
1621 void getFootprintPackage(std::string& filename);
1622
1623 std::string m_packageArchiveName;
1624 std::string m_packageName;
1625 std::string m_packageArchiveVersion;
1626 std::string m_packageArchiveRelease;
1627 std::string m_packageArchiveCollection;
1628 std::string m_packageVersion;
1629 std::string m_packageRelease;
1630 std::string m_packageCollection;
1631 std::string m_utilName;
1632 std::string m_root;
1633 std::string m_build;
1634 std::vector<rule_t> m_actionRules;
1635 std::set< std::pair<std::string, int> > m_postInstallList;
1636 alias_t m_listOfAlias;
1637
1638 packages_t m_listOfInstPackages;
1639 packages_t m_listOfDepotPackages;
1640
1641 std::set<std::pair<std::string,std::set<std::string> > > m_listOfInstalledPackagesWithDeps;
1642
1643 action m_actualAction;
1644 error m_actualError;
1645
1646private:
1647
1648 void runLastPostInstall();
1649
1650 std::set<std::string> m_runtimeLibrariesList;
1651 std::set<std::string> m_filesList;
1652 std::set<std::string> m_packageNamesList;
1653 unsigned int m_filesNumber;
1654 unsigned int m_installedFilesNumber;
1655
1656 bool m_dependency;
1657
1658 bool m_DB_Empty;
1659 bool m_miniDB_Empty;
1660};
1661
1662class Db_lock {
1663public:
1664 Db_lock(const std::string& m_root, bool exclusive);
1665 ~Db_lock();
1666
1667private:
1668 DIR* m_dir;
1669 struct sigaction m_sa;
1670};
1671
1672void assertArgument(char** argv, int argc, int index);
1673void rotatingCursor();
1674
1688class Pkgadd : public Pkgdbh {
1689public:
1693 Pkgadd();
1699 Pkgadd(const std::string& commandName);
1700 void parseArguments(int argc, char** argv);
1701 void preRun();
1702 void postRun();
1703 virtual void run();
1704 virtual void run(int argc, char** argv);
1705 virtual void printHelp() const;
1706
1707protected:
1708 bool m_runPrePost;
1709 bool m_upgrade;
1710 bool m_force;
1711private:
1712 std::set<std::string> getKeepFileList(const std::set<std::string>& files,
1713 const std::vector<rule_t>& rules);
1714 std::set<std::string> applyInstallRules(const std::string& name,
1715 pkginfo_t& info,
1716 const std::vector<rule_t>& rules);
1717 void applyPostInstallRules(const std::string& name,
1718 pkginfo_t& info,
1719 const std::vector<rule_t>& rules);
1720 void getInstallRulesList(const std::vector<rule_t>& rules,
1721 rule_event_t event,
1722 std::vector<rule_t>& found) const;
1723 void getPostInstallRulesList(const std::vector<rule_t>& rules,
1724 std::vector<rule_t>& found) const;
1725};
1726
1733class Pkgrm : public Pkgdbh {
1734public:
1735 Pkgrm(const std::string& commandName) : Pkgdbh(commandName) {}
1736 Pkgrm();
1737 void run();
1738 void run(int argc, char** argv);
1739 void printHelp() const;
1740
1741protected:
1742 void getListOfManInstalledPackages ();
1743 std::set<std::string> m_listOfManInstalledPackages;
1744 std::set<std::string> m_listofDependencies;
1745private:
1746 void getDirectDependencies(std::string& name);
1747
1748};
1749
1750
1757#include <sstream>
1758#include <iomanip>
1759
1760
1761class Pkginfo : public Pkgdbh {
1762public:
1763 Pkginfo(const std::string& commandName);
1764 Pkginfo();
1765 virtual void run(int argc, char** argv);
1766 virtual void parseArguments(int argc, char** argv);
1767 virtual void run();
1768 virtual void finish();
1769 virtual void printHelp() const;
1770
1771protected:
1772 std::string m_arg;
1773 int m_runtimedependencies_mode;
1774 int m_footprint_mode;
1775 int m_archiveinfo;
1776 int m_installed_mode;
1777 int m_list_mode;
1778 int m_owner_mode;
1779 int m_details_mode;
1780 int m_libraries_mode;
1781 int m_runtime_mode;
1782 int m_epoc;
1783 bool m_fulllist_mode;
1784
1785};
1786
1787
1788
1789
1790
1791class Pkginst : public Pkgadd, public Repodwl {
1792public:
1793 Pkginst(const std::string& commandName, const char *configFileName);
1794 void generateDependencies(const std::pair<std::string,time_t>& packageName);
1795 void generateDependencies();
1796
1797protected:
1798 std::vector< std::pair<std::string,time_t> > m_dependenciesList;
1799};
1800
1801
1802#include <cstring>
1803#include <cstdlib>
1804#include <iostream>
1805
1806
1807#include <curl/curl.h>
1808#include <sys/types.h>
1809#include <sys/stat.h>
1810#include <unistd.h>
1811#include <libgen.h>
1812#include <dirent.h>
1813
1815{
1816public:
1821 Pkgsync();
1822 Pkgsync(const std::string& url,
1823 const std::string& directory,
1824 const std::string& repoFile);
1825
1826 virtual void treatErrors(const std::string& s) const;
1827
1828 virtual void run();
1829 virtual void purge();
1830 static const std::string DEFAULT_REPOFILE;
1831
1832 void setRootPath(const std::string& path);
1833 void setConfigFile(const std::string& file);
1834
1835private:
1836
1837 unsigned int getLocalPackages(const std::string& path);
1838 unsigned int getRemotePackages(const std::string& pkgrepoFile);
1839
1840 void deleteFolder(const std::string& folderName);
1841
1842 std::set<std::string> m_localPackagesList;
1843 std::set<std::string> m_remotePackagesList;
1844 const std::string m_baseDirectory;
1845 const std::string m_remoteUrl;
1846 std::string m_repoFile;
1847 std::string m_root;
1848 std::string m_configFile;
1849 error m_actualError;
1850
1851
1852};
1853
1854#endif
1855// vim:set ts=2 :
Definition: archive_utils.h:69
Definition: libcards.h:1662
File Download Event class.
Definition: file_download.h:65
virtual void OnFileDownloadProgressInfo(FileDownloadState state)
Definition: libcards.h:1216
File Download State class.
Definition: file_download.h:46
File Download class.
Definition: file_download.h:90
FileDownload(std::vector< InfoFile > destinationFiles, bool progress)
FileDownload(std::string fileInfo, std::string url, std::string dirName, std::string fileName, std::string MD5Sum, bool progress)
FileDownload(std::string url, std::string dirName, std::string fileName, bool progress)
~FileDownload()
Definition: libcards.h:1265
Definition: libcards.h:851
~Pkg()
Destructor.
Definition: pkg.cxx:35
Pkg()
Constructor.
Definition: pkg.cxx:29
std::vector< std::string > getSet()
Return.
Definition: pkg.cxx:65
Pkgadd class.
Definition: libcards.h:1688
Pkgadd()
Definition: pkgadd.cxx:28
Definition: libcards.h:1530
void buildSimpleDatabase()
Definition: pkgdbh.cxx:506
void buildSimpleDependenciesDatabase()
Definition: pkgdbh.cxx:475
void buildCompleteDatabase(const bool &silent)
Definition: pkgdbh.cxx:572
void buildDatabase(const bool &progress, const bool &simple, const bool &all, const bool &files, const std::string &packageName)
Definition: pkgdbh.cxx:361
Definition: libcards.h:1761
Definition: libcards.h:1791
Definition: libcards.h:944
std::set< std::string > getListOutOfDate()
Definition: pkgrepo.cxx:283
std::set< std::string > getListOfPackagesFromCollection(const std::string &collectionName)
Definition: pkgrepo.cxx:371
void parseCollectionDirectory()
Definition: pkgrepo.cxx:187
void parsePackagePkgfileFile()
Definition: pkgrepo.cxx:300
std::string getPortDir(const std::string &portName)
Definition: pkgrepo.cxx:624
int getPortRelease(const std::string &portName)
Definition: pkgrepo.cxx:729
std::set< std::string > getBinaryPackageList()
Definition: pkgrepo.cxx:408
bool checkPortExist(const std::string &portName)
Definition: pkgrepo.cxx:747
std::string getPortVersion(const std::string &portName)
Definition: pkgrepo.cxx:698
time_t getBinaryBuildTime(const std::string &portName)
Definition: pkgrepo.cxx:769
void parsePkgRepoCollectionFile()
Definition: pkgrepo.cxx:54
std::set< std::string > getListOfPackagesFromSet(const std::string &collectionName)
Definition: pkgrepo.cxx:390
std::string getBasePackageName(const std::string &packageName)
Definition: pkgrepo.cxx:644
unsigned int getPortsList()
Definition: pkgrepo.cxx:515
int getBasePackageRelease(const std::string &packageName)
Definition: pkgrepo.cxx:714
void parseCurrentPackagePkgRepoFile()
Definition: pkgrepo.cxx:215
std::string getBasePackageVersion(const std::string &packageName)
std::vector< RepoInfo > getRepoInfo()
Definition: pkgrepo.cxx:485
std::string getBasePortName(const std::string &portName)
Definition: pkgrepo.cxx:678
std::set< Pkg * > getBinaryPackageSet()
Definition: pkgrepo.cxx:449
Definition: libcards.h:1733
Definition: libcards.h:1815
Pkgsync()
Definition: pkgsync.cxx:26
Definition: libcards.h:1128
void downloadPortsPkgRepo(const std::string &packageName)
Definition: repodwl.cxx:30
void downloadPackageFileName(const std::string &packageName)
Definition: repodwl.cxx:62
Definition: error_treat.h:91
Definition: libcards.h:1344
int executeShell()
Definition: process.cxx:175
int execute()
Definition: process.cxx:59
std::string name()
Definition: process.cxx:51
std::string args()
Definition: process.cxx:55
Definition: libcards.h:907
Definition: file_utils.h:69
Definition: file_utils.h:64
Definition: file_utils.h:54
Definition: libcards.h:889
Definition: libcards.h:928
Definition: libcards.h:936
Definition: libcards.h:484
Definition: libcards.h:475
Definition: libcards.h:446
Definition: libcards.h:1483
Definition: libcards.h:1524