1 /*#############################################################################
3 # Pakfire - The IPFire package management system #
4 # Copyright (C) 2013 Pakfire development team #
6 # This program is free software: you can redistribute it and/or modify #
7 # it under the terms of the GNU General Public License as published by #
8 # the Free Software Foundation, either version 3 of the License, or #
9 # (at your option) any later version. #
11 # This program is distributed in the hope that it will be useful, #
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
14 # GNU General Public License for more details. #
16 # You should have received a copy of the GNU General Public License #
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
19 #############################################################################*/
22 #include <linux/limits.h>
26 #include <uuid/uuid.h>
31 #include <solv/pool.h>
32 #include <solv/repo.h>
33 #include <solv/solvable.h>
35 #include <pakfire/archive.h>
36 #include <pakfire/constants.h>
37 #include <pakfire/dependencies.h>
38 #include <pakfire/digest.h>
39 #include <pakfire/file.h>
40 #include <pakfire/filelist.h>
41 #include <pakfire/i18n.h>
42 #include <pakfire/logging.h>
43 #include <pakfire/package.h>
44 #include <pakfire/pakfire.h>
45 #include <pakfire/private.h>
46 #include <pakfire/repo.h>
47 #include <pakfire/string.h>
48 #include <pakfire/util.h>
50 struct pakfire_package
{
51 struct pakfire
* pakfire
;
54 // Reference to this package in the SOLV pool
56 struct pakfire_repo
* repo
;
59 char source_nevra
[NAME_MAX
];
61 char filename
[NAME_MAX
];
65 static Solvable
* get_solvable(struct pakfire_package
* pkg
) {
66 Pool
* pool
= pakfire_get_solv_pool(pkg
->pakfire
);
68 return pool_id2solvable(pool
, pkg
->id
);
71 static int pakfire_package_dep2id(const enum pakfire_package_key key
,
74 case PAKFIRE_PKG_PROVIDES
:
75 *id
= SOLVABLE_PROVIDES
;
76 *marker
= -SOLVABLE_FILEMARKER
;
79 case PAKFIRE_PKG_PREREQUIRES
:
80 *id
= SOLVABLE_REQUIRES
;
81 *marker
= SOLVABLE_PREREQMARKER
;
84 case PAKFIRE_PKG_REQUIRES
:
85 *id
= SOLVABLE_REQUIRES
;
86 *marker
= -SOLVABLE_PREREQMARKER
;
89 case PAKFIRE_PKG_CONFLICTS
:
90 *id
= SOLVABLE_CONFLICTS
;
93 case PAKFIRE_PKG_OBSOLETES
:
94 *id
= SOLVABLE_OBSOLETES
;
97 case PAKFIRE_PKG_RECOMMENDS
:
98 *id
= SOLVABLE_RECOMMENDS
;
101 case PAKFIRE_PKG_SUGGESTS
:
102 *id
= SOLVABLE_SUGGESTS
;
105 case PAKFIRE_PKG_SUPPLEMENTS
:
106 *id
= SOLVABLE_SUPPLEMENTS
;
109 case PAKFIRE_PKG_ENHANCES
:
110 *id
= SOLVABLE_ENHANCES
;
113 // This operation is not possible for any other types
122 static int pakfire_package_add_depid(struct pakfire_package
* pkg
,
123 const enum pakfire_package_key key
, Id dep
) {
124 Solvable
* s
= get_solvable(pkg
);
130 // Translate the dependency type
131 r
= pakfire_package_dep2id(key
, &id
, &marker
);
135 // Append to the dependency array
136 solvable_add_deparray(s
, id
, dep
, marker
);
141 static int pakfire_package_add_self_provides(struct pakfire_package
* pkg
) {
142 // Fetch the solvable
143 Solvable
* s
= get_solvable(pkg
);
147 // Get the self-provides ID
148 Id dep
= solvable_selfprovidedep(s
);
150 // Add it to the package
151 return pakfire_package_add_depid(pkg
, PAKFIRE_PKG_PROVIDES
, dep
);
154 int pakfire_package_create_from_solvable(struct pakfire_package
** package
,
155 struct pakfire
* pakfire
, Id id
) {
156 struct pakfire_package
* pkg
= calloc(1, sizeof(*pkg
));
160 pkg
->pakfire
= pakfire_ref(pakfire
);
171 PAKFIRE_EXPORT
int pakfire_package_create(struct pakfire_package
** package
,
172 struct pakfire
* pakfire
, struct pakfire_repo
* repo
,
173 const char* name
, const char* evr
, const char* arch
) {
174 struct pakfire_repo
* dummy
= NULL
;
177 // Check for some valid input
178 if (!name
|| !evr
|| !arch
) {
183 // Default to dummy repository
185 dummy
= pakfire_get_repo(pakfire
, PAKFIRE_REPO_DUMMY
);
194 // Allocate a new solvable
195 Id id
= pakfire_repo_add_solvable(repo
);
197 ERROR(pakfire
, "Could not allocate a solvable: %m\n");
202 // Create a new package object
203 r
= pakfire_package_create_from_solvable(package
, pakfire
, id
);
207 // Reference the repository
208 (*package
)->repo
= pakfire_repo_ref(repo
);
211 r
= pakfire_package_set_string(*package
, PAKFIRE_PKG_NAME
, name
);
213 ERROR(pakfire
, "Could not set package name '%s': %m\n", name
);
218 r
= pakfire_package_set_string(*package
, PAKFIRE_PKG_EVR
, evr
);
220 ERROR(pakfire
, "Could not set package EVR '%s': %m\n", evr
);
225 r
= pakfire_package_set_string(*package
, PAKFIRE_PKG_ARCH
, arch
);
227 ERROR(pakfire
, "Could not set package arch '%s': %m\n", arch
);
232 r
= pakfire_package_add_self_provides(*package
);
234 ERROR(pakfire
, "Could not create self-provides: %m\n");
240 pakfire_repo_unref(dummy
);
245 static void pakfire_package_free(struct pakfire_package
* pkg
) {
247 pakfire_repo_unref(pkg
->repo
);
249 pakfire_unref(pkg
->pakfire
);
253 PAKFIRE_EXPORT
struct pakfire_package
* pakfire_package_ref(struct pakfire_package
* pkg
) {
259 PAKFIRE_EXPORT
struct pakfire_package
* pakfire_package_unref(struct pakfire_package
* pkg
) {
260 if (--pkg
->nrefs
> 0)
263 pakfire_package_free(pkg
);
267 PAKFIRE_EXPORT
struct pakfire
* pakfire_package_get_pakfire(struct pakfire_package
* pkg
) {
268 return pakfire_ref(pkg
->pakfire
);
271 PAKFIRE_EXPORT
int pakfire_package_eq(struct pakfire_package
* pkg1
, struct pakfire_package
* pkg2
) {
272 return pkg1
->id
== pkg2
->id
;
275 PAKFIRE_EXPORT
int pakfire_package_cmp(struct pakfire_package
* pkg1
, struct pakfire_package
* pkg2
) {
276 Pool
* pool
= pakfire_get_solv_pool(pkg1
->pakfire
);
278 Solvable
* s1
= get_solvable(pkg1
);
279 Solvable
* s2
= get_solvable(pkg2
);
282 const char* str1
= pool_id2str(pool
, s1
->name
);
283 const char* str2
= pool_id2str(pool
, s2
->name
);
285 int ret
= strcmp(str1
, str2
);
289 // Check the version string
290 ret
= pakfire_package_evr_cmp(pkg1
, pkg2
);
294 // Check repositories
295 struct pakfire_repo
* repo1
= pakfire_package_get_repo(pkg1
);
296 struct pakfire_repo
* repo2
= pakfire_package_get_repo(pkg2
);
298 if (repo1
&& repo2
) {
299 ret
= pakfire_repo_cmp(repo1
, repo2
);
302 pakfire_repo_unref(repo1
);
303 pakfire_repo_unref(repo2
);
308 // Check package architectures
309 str1
= pool_id2str(pool
, s1
->arch
);
310 str2
= pool_id2str(pool
, s2
->arch
);
312 return strcmp(str1
, str2
);
315 PAKFIRE_EXPORT
int pakfire_package_evr_cmp(struct pakfire_package
* pkg1
, struct pakfire_package
* pkg2
) {
316 Pool
* pool
= pakfire_get_solv_pool(pkg1
->pakfire
);
318 Solvable
* s1
= get_solvable(pkg1
);
319 Solvable
* s2
= get_solvable(pkg2
);
321 return pool_evrcmp(pool
, s1
->evr
, s2
->evr
, EVRCMP_COMPARE
);
324 PAKFIRE_EXPORT
unsigned int pakfire_package_id(struct pakfire_package
* pkg
) {
328 char* pakfire_package_join_evr(const char* e
, const char* v
, const char* r
) {
331 // Check for valid input
332 if (!e
|| !v
|| !r
) {
337 // Skip any zeroes in epoch
338 while (*e
&& *e
== '0')
341 // Format string with epoch
343 if (asprintf(&buffer
, "%s:%s-%s", e
, v
, r
) < 0)
346 // Or format it without epoch
348 if (asprintf(&buffer
, "%s-%s", v
, r
) < 0)
355 int pakfire_package_is_source(struct pakfire_package
* pkg
) {
356 const char* arch
= pakfire_package_get_string(pkg
, PAKFIRE_PKG_ARCH
);
360 return (strcmp(arch
, "src") == 0);
363 static void pakfire_package_internalize_repo(struct pakfire_package
* pkg
) {
364 struct pakfire_repo
* repo
= pakfire_package_get_repo(pkg
);
366 pakfire_repo_internalize(repo
, 0);
367 pakfire_repo_unref(repo
);
371 static void pakfire_package_has_changed(struct pakfire_package
* pkg
) {
372 struct pakfire_repo
* repo
= pakfire_package_get_repo(pkg
);
374 pakfire_repo_has_changed(repo
);
375 pakfire_repo_unref(repo
);
380 static const char* evr2vr(const char* evr
) {
383 // Skip any leading digits
384 for (; *p
>= '0' && *p
<= '9'; p
++);
386 // If after the leading digits, we found :, we return the rest of the string
387 if (p
!= evr
&& *p
== ':')
393 static const char* pakfire_package_make_filename(struct pakfire_package
* pkg
) {
396 if (!*pkg
->filename
) {
397 const char* name
= pakfire_package_get_string(pkg
, PAKFIRE_PKG_NAME
);
398 const char* evr
= pakfire_package_get_string(pkg
, PAKFIRE_PKG_EVR
);
399 const char* arch
= pakfire_package_get_string(pkg
, PAKFIRE_PKG_ARCH
);
401 if (!name
|| !evr
|| !arch
)
404 const char* vr
= evr2vr(evr
);
408 r
= pakfire_string_format(pkg
->filename
, "%s-%s.%s.pfm", name
, vr
, arch
);
413 return pkg
->filename
;
416 static int pakfire_package_make_cache_path(struct pakfire_package
* pkg
) {
417 const char* filename
= pakfire_package_get_string(pkg
, PAKFIRE_PKG_FILENAME
);
419 enum pakfire_digest_types digest_type
= PAKFIRE_DIGEST_UNDEFINED
;
420 size_t digest_length
= 0;
423 const unsigned char* digest
= pakfire_package_get_digest(pkg
,
424 &digest_type
, &digest_length
);
426 if (digest
&& digest_length
>= 4)
427 return pakfire_cache_path(pkg
->pakfire
, pkg
->path
,
428 "%02x/%02x/%02x/%02x/%s", digest
[0], digest
[1], digest
[2], digest
[3], filename
);
430 return pakfire_cache_path(pkg
->pakfire
, pkg
->path
, "%s", filename
);
433 PAKFIRE_EXPORT
const char* pakfire_package_get_string(
434 struct pakfire_package
* pkg
, const enum pakfire_package_key key
) {
435 const char* ret
= NULL
;
438 pakfire_package_internalize_repo(pkg
);
440 Pool
* pool
= pakfire_get_solv_pool(pkg
->pakfire
);
441 Solvable
* s
= get_solvable(pkg
);
444 case PAKFIRE_PKG_NAME
:
445 return pool_id2str(pool
, s
->name
);
447 case PAKFIRE_PKG_EVR
:
448 return pool_id2str(pool
, s
->evr
);
450 case PAKFIRE_PKG_ARCH
:
451 return pool_id2str(pool
, s
->arch
);
453 case PAKFIRE_PKG_NEVRA
:
455 r
= pakfire_string_set(pkg
->nevra
, pool_solvable2str(pool
, s
));
462 case PAKFIRE_PKG_UUID
:
463 ret
= solvable_lookup_str(s
, SOLVABLE_PKGID
);
466 case PAKFIRE_PKG_SUMMARY
:
467 ret
= solvable_lookup_str(s
, SOLVABLE_SUMMARY
);
470 case PAKFIRE_PKG_DESCRIPTION
:
471 ret
= solvable_lookup_str(s
, SOLVABLE_DESCRIPTION
);
474 case PAKFIRE_PKG_LICENSE
:
475 ret
= solvable_lookup_str(s
, SOLVABLE_LICENSE
);
478 case PAKFIRE_PKG_URL
:
479 ret
= solvable_lookup_str(s
, SOLVABLE_URL
);
482 case PAKFIRE_PKG_GROUPS
:
483 ret
= solvable_lookup_str(s
, SOLVABLE_GROUP
);
486 case PAKFIRE_PKG_VENDOR
:
487 ret
= solvable_lookup_str(s
, SOLVABLE_VENDOR
);
490 case PAKFIRE_PKG_DISTRO
:
491 ret
= solvable_lookup_str(s
, SOLVABLE_DISTRIBUTION
);
494 case PAKFIRE_PKG_PACKAGER
:
495 ret
= solvable_lookup_str(s
, SOLVABLE_PACKAGER
);
498 case PAKFIRE_PKG_PATH
:
500 const char* base
= solvable_lookup_str(s
, SOLVABLE_MEDIABASE
);
502 const char* filename
= pakfire_package_get_string(pkg
, PAKFIRE_PKG_FILENAME
);
506 pakfire_string_format(pkg
->path
, "%s/%s", base
, filename
);
508 r
= pakfire_package_make_cache_path(pkg
);
516 case PAKFIRE_PKG_FILENAME
:
517 ret
= solvable_lookup_str(s
, SOLVABLE_MEDIAFILE
);
519 // Generate the filename if not set
521 ret
= pakfire_package_make_filename(pkg
);
524 case PAKFIRE_PKG_BUILD_HOST
:
525 ret
= solvable_lookup_str(s
, SOLVABLE_BUILDHOST
);
528 case PAKFIRE_PKG_BUILD_ID
:
529 ret
= solvable_lookup_str(s
, SOLVABLE_BUILDVERSION
);
532 case PAKFIRE_PKG_SOURCE_PKG
:
533 if (!*pkg
->source_nevra
) {
534 const char* name
= pakfire_package_get_string(pkg
, PAKFIRE_PKG_SOURCE_NAME
);
535 const char* evr
= pakfire_package_get_string(pkg
, PAKFIRE_PKG_SOURCE_EVR
);
536 const char* arch
= pakfire_package_get_string(pkg
, PAKFIRE_PKG_SOURCE_ARCH
);
538 // Return nothing if we don't have all information
539 if (!name
|| !evr
|| !arch
)
542 // Format package name
543 r
= pakfire_string_format(pkg
->source_nevra
, "%s-%s.%s", name
, evr
, arch
);
548 return pkg
->source_nevra
;
550 case PAKFIRE_PKG_SOURCE_NAME
:
551 ret
= solvable_lookup_str(s
, SOLVABLE_SOURCENAME
);
554 case PAKFIRE_PKG_SOURCE_EVR
:
555 ret
= solvable_lookup_str(s
, SOLVABLE_SOURCEEVR
);
558 case PAKFIRE_PKG_SOURCE_ARCH
:
559 ret
= solvable_lookup_str(s
, SOLVABLE_SOURCEARCH
);
569 PAKFIRE_EXPORT
int pakfire_package_set_string(
570 struct pakfire_package
* pkg
, const enum pakfire_package_key key
, const char* value
) {
573 Pool
* pool
= pakfire_get_solv_pool(pkg
->pakfire
);
574 Solvable
* s
= get_solvable(pkg
);
576 const char* basename
= NULL
;
577 const char* dirname
= NULL
;
580 // Do not allow to change name, evr, or arch
581 case PAKFIRE_PKG_NAME
:
582 // Reset nevra & filename
583 *pkg
->nevra
= *pkg
->filename
= '\0';
585 s
->name
= pool_str2id(pool
, value
, 1);
588 case PAKFIRE_PKG_EVR
:
589 // Reset nevra & filename
590 *pkg
->nevra
= *pkg
->filename
= '\0';
593 if (pakfire_string_startswith(value
, "0:"))
596 s
->evr
= pool_str2id(pool
, value
, 1);
599 case PAKFIRE_PKG_ARCH
:
600 // Reset nevra & filename
601 *pkg
->nevra
= *pkg
->filename
= '\0';
603 s
->arch
= pool_str2id(pool
, value
, 1);
606 case PAKFIRE_PKG_NEVRA
:
610 case PAKFIRE_PKG_UUID
:
614 case PAKFIRE_PKG_SUMMARY
:
615 id
= SOLVABLE_SUMMARY
;
618 case PAKFIRE_PKG_DESCRIPTION
:
619 id
= SOLVABLE_DESCRIPTION
;
622 case PAKFIRE_PKG_LICENSE
:
623 id
= SOLVABLE_LICENSE
;
626 case PAKFIRE_PKG_URL
:
630 case PAKFIRE_PKG_GROUPS
:
634 case PAKFIRE_PKG_VENDOR
:
635 id
= SOLVABLE_VENDOR
;
638 case PAKFIRE_PKG_DISTRO
:
639 id
= SOLVABLE_DISTRIBUTION
;
642 case PAKFIRE_PKG_PACKAGER
:
643 id
= SOLVABLE_PACKAGER
;
646 case PAKFIRE_PKG_PATH
:
648 basename
= pakfire_basename(value
);
649 dirname
= pakfire_dirname(value
);
653 solvable_set_str(s
, SOLVABLE_MEDIAFILE
, basename
);
655 solvable_unset(s
, SOLVABLE_MEDIAFILE
);
658 solvable_set_str(s
, SOLVABLE_MEDIABASE
, dirname
);
660 solvable_unset(s
, SOLVABLE_MEDIABASE
);
663 pakfire_string_set(pkg
->path
, value
);
665 // Mark the package as changed
666 pakfire_package_has_changed(pkg
);
670 case PAKFIRE_PKG_FILENAME
:
671 id
= SOLVABLE_MEDIAFILE
;
674 case PAKFIRE_PKG_BUILD_HOST
:
675 id
= SOLVABLE_BUILDHOST
;
678 case PAKFIRE_PKG_BUILD_ID
:
679 id
= SOLVABLE_BUILDVERSION
;
682 case PAKFIRE_PKG_SOURCE_PKG
:
683 // The source package name cannot be set
686 case PAKFIRE_PKG_SOURCE_NAME
:
687 id
= SOLVABLE_SOURCENAME
;
690 case PAKFIRE_PKG_SOURCE_EVR
:
692 if (pakfire_string_startswith(value
, "0:"))
695 id
= SOLVABLE_SOURCEEVR
;
698 case PAKFIRE_PKG_SOURCE_ARCH
:
699 id
= SOLVABLE_SOURCEARCH
;
706 // Check if we have found a valid ID
712 // Unset on empty string
714 solvable_unset(s
, id
);
718 solvable_set_str(s
, id
, value
);
720 // Mark the package as changed
721 pakfire_package_has_changed(pkg
);
726 PAKFIRE_EXPORT
int pakfire_package_get_uuid(struct pakfire_package
* pkg
,
727 const enum pakfire_package_key key
, uuid_t uuid
) {
728 const char* buffer
= NULL
;
732 case PAKFIRE_PKG_UUID
:
733 case PAKFIRE_PKG_BUILD_ID
:
738 buffer
= pakfire_package_get_string(pkg
, key
);
742 // Read buffer into the output
743 r
= uuid_parse(buffer
, uuid
);
755 PAKFIRE_EXPORT
int pakfire_package_set_uuid(struct pakfire_package
* pkg
,
756 const enum pakfire_package_key key
, const uuid_t uuid
) {
757 char buffer
[UUID_STR_LEN
];
760 case PAKFIRE_PKG_UUID
:
761 case PAKFIRE_PKG_BUILD_ID
:
762 // Convert the UUID to string
763 uuid_unparse_lower(uuid
, buffer
);
765 // Store the UUID as string
766 return pakfire_package_set_string(pkg
, key
, buffer
);
774 PAKFIRE_EXPORT
unsigned long long pakfire_package_get_num(struct pakfire_package
* pkg
,
775 const enum pakfire_package_key key
, unsigned long long notfound
) {
779 case PAKFIRE_PKG_DBID
:
783 case PAKFIRE_PKG_DOWNLOADSIZE
:
784 id
= SOLVABLE_DOWNLOADSIZE
;
787 case PAKFIRE_PKG_INSTALLSIZE
:
788 id
= SOLVABLE_INSTALLSIZE
;
791 case PAKFIRE_PKG_BUILD_TIME
:
792 id
= SOLVABLE_BUILDTIME
;
795 case PAKFIRE_PKG_INSTALLTIME
:
796 id
= SOLVABLE_INSTALLTIME
;
799 // Return zero for all unhandled keys
805 Solvable
* s
= get_solvable(pkg
);
807 pakfire_package_internalize_repo(pkg
);
809 return solvable_lookup_num(s
, id
, notfound
);
812 PAKFIRE_EXPORT
int pakfire_package_set_num(struct pakfire_package
* pkg
,
813 const enum pakfire_package_key key
, unsigned long long num
) {
817 case PAKFIRE_PKG_DBID
:
821 case PAKFIRE_PKG_DOWNLOADSIZE
:
822 id
= SOLVABLE_DOWNLOADSIZE
;
825 case PAKFIRE_PKG_INSTALLSIZE
:
826 id
= SOLVABLE_INSTALLSIZE
;
829 case PAKFIRE_PKG_BUILD_TIME
:
830 id
= SOLVABLE_BUILDTIME
;
833 case PAKFIRE_PKG_INSTALLTIME
:
834 id
= SOLVABLE_INSTALLTIME
;
837 // Return zero for all unhandled keys
843 Solvable
* s
= get_solvable(pkg
);
846 solvable_set_num(s
, id
, num
);
848 // Mark the package as changed
849 pakfire_package_has_changed(pkg
);
854 static enum pakfire_digest_types
pakfire_package_id2digest(Id id
) {
856 case REPOKEY_TYPE_SHA512
:
857 return PAKFIRE_DIGEST_SHA2_512
;
859 case REPOKEY_TYPE_SHA256
:
860 return PAKFIRE_DIGEST_SHA2_256
;
866 PAKFIRE_EXPORT
const unsigned char* pakfire_package_get_digest(
867 struct pakfire_package
* pkg
, enum pakfire_digest_types
* type
, size_t* length
) {
868 Solvable
* s
= get_solvable(pkg
);
871 const unsigned char* checksum
= solvable_lookup_bin_checksum(s
, SOLVABLE_CHECKSUM
, &id
);
873 // Convert ID to digest type
874 *type
= pakfire_package_id2digest(id
);
880 // Store the length (if requested)
882 *length
= pakfire_digest_length(*type
);
887 PAKFIRE_EXPORT
int pakfire_package_set_digest(struct pakfire_package
* pkg
,
888 enum pakfire_digest_types type
, const unsigned char* digest
, const size_t length
) {
889 Solvable
* s
= get_solvable(pkg
);
890 Pool
* pool
= s
->repo
->pool
;
895 case PAKFIRE_DIGEST_SHA2_256
:
896 id
= REPOKEY_TYPE_SHA256
;
899 case PAKFIRE_DIGEST_SHA2_512
:
900 id
= REPOKEY_TYPE_SHA512
;
908 // Check if the digest length matches
909 if (pakfire_digest_length(type
) != length
) {
914 struct pakfire_repo
* repo
= pakfire_package_get_repo(pkg
);
916 Repodata
* data
= pakfire_repo_get_repodata(repo
);
920 repodata_set_bin_checksum(data
, s
- pool
->solvables
, SOLVABLE_CHECKSUM
, id
, digest
);
926 pakfire_repo_unref(repo
);
931 int pakfire_package_is_installed(struct pakfire_package
* pkg
) {
932 Pool
* pool
= pakfire_get_solv_pool(pkg
->pakfire
);
933 Solvable
* s
= get_solvable(pkg
);
935 return pool
->installed
== s
->repo
;
938 PAKFIRE_EXPORT
size_t pakfire_package_get_size(struct pakfire_package
* pkg
) {
939 if (pakfire_package_is_installed(pkg
))
940 return pakfire_package_get_num(pkg
, PAKFIRE_PKG_INSTALLSIZE
, 0);
942 return pakfire_package_get_num(pkg
, PAKFIRE_PKG_DOWNLOADSIZE
, 0);
947 PAKFIRE_EXPORT
char** pakfire_package_get_deps(struct pakfire_package
* pkg
,
948 const enum pakfire_package_key key
) {
949 Solvable
* s
= get_solvable(pkg
);
956 const char* dep
= NULL
;
958 r
= pakfire_package_dep2id(key
, &id
, &marker
);
962 // Initialize the output queue
966 solvable_lookup_deparray(s
, id
, &q
, marker
);
969 ret
= calloc(q
.count
+ 1, sizeof(*ret
));
973 for (int i
= 0; i
< q
.count
; i
++) {
974 dep
= pakfire_dep2str(pkg
->pakfire
, q
.elements
[i
]);
978 ret
[i
] = strdup(dep
);
988 for (char** e
= ret
; *e
; e
++)
1001 int pakfire_package_add_dep(struct pakfire_package
* pkg
,
1002 const enum pakfire_package_key key
, const char* dep
) {
1003 // Parse the dependency
1004 Id id
= pakfire_str2dep(pkg
->pakfire
, dep
);
1006 // Silently ignore any invalid dependencies
1010 return pakfire_package_add_depid(pkg
, key
, id
);
1013 PAKFIRE_EXPORT
int pakfire_package_get_reverse_requires(struct pakfire_package
* pkg
,
1014 struct pakfire_packagelist
* list
) {
1016 queue_init(&matches
);
1018 // Get the pool ready
1019 pakfire_pool_internalize(pkg
->pakfire
);
1021 Pool
* pool
= pakfire_get_solv_pool(pkg
->pakfire
);
1023 // Search for any matches
1024 pool_whatmatchessolvable(pool
, SOLVABLE_REQUIRES
, pkg
->id
, &matches
, 0);
1026 // Import the result to the package list
1027 int r
= pakfire_packagelist_import_solvables(list
, &matches
);
1032 queue_free(&matches
);
1037 static int pakfire_package_has_rich_deps_in_deparray(
1038 struct pakfire_package
* pkg
, Id type
) {
1041 Solvable
* s
= get_solvable(pkg
);
1047 solvable_lookup_deparray(s
, type
, &q
, 0);
1049 // Nothing to do if the array was empty
1053 for (int i
= 0; i
< q
.count
; i
++) {
1054 const char* dep
= pakfire_dep2str(pkg
->pakfire
, q
.elements
[i
]);
1056 // Is this a rich dependency?
1057 if (dep
&& *dep
== '(') {
1069 int pakfire_package_has_rich_deps(struct pakfire_package
* pkg
) {
1070 const Id types
[] = {
1071 // Requires (includes pre-requires)
1076 SOLVABLE_RECOMMENDS
,
1078 SOLVABLE_SUPPLEMENTS
,
1083 for (const Id
* type
= types
; *type
; type
++) {
1084 int r
= pakfire_package_has_rich_deps_in_deparray(pkg
, *type
);
1093 int pakfire_package_matches_dep(struct pakfire_package
* pkg
,
1094 const enum pakfire_package_key key
, const char* dep
) {
1100 // Translate the dependency type
1101 r
= pakfire_package_dep2id(key
, &id
, &marker
);
1105 // Get the dependency
1106 Id depid
= pakfire_str2dep(pkg
->pakfire
, dep
);
1110 // Fetch the solvable
1111 Solvable
* s
= get_solvable(pkg
);
1113 // Check whether this solvable matches the requested dependency
1114 return solvable_matchesdep(s
, id
, depid
, marker
);
1117 PAKFIRE_EXPORT
struct pakfire_repo
* pakfire_package_get_repo(struct pakfire_package
* pkg
) {
1119 Solvable
* s
= get_solvable(pkg
);
1121 pkg
->repo
= pakfire_repo_create_from_repo(pkg
->pakfire
, s
->repo
);
1124 return pakfire_repo_ref(pkg
->repo
);
1127 static void pakfire_package_dump_add_line(char** str
, const char* key
, const char* val
) {
1129 asprintf(str
, "%s%-15s: %s\n", *str
, key
? key
: "", val
);
1132 static void pakfire_package_dump_add_lines(char** str
, const char* key
, const char* val
) {
1133 char** lines
= pakfire_string_split(val
, '\n');
1138 pakfire_package_dump_add_line(str
, key
, *lines
);
1143 static void pakfire_package_dump_add_line_date(char** str
, const char* key
, time_t date
) {
1148 r
= pakfire_strftime(buffer
, "%a, %d %b %Y %T %z", date
);
1152 pakfire_package_dump_add_line(str
, key
, buffer
);
1155 static void pakfire_package_dump_add_line_hex(char** str
,
1156 const char* key
, const unsigned char* buffer
, const size_t length
) {
1157 char* hex
= __pakfire_hexlify(buffer
, length
);
1161 pakfire_package_dump_add_line(str
, key
, hex
);
1165 static void pakfire_package_dump_add_line_size(char** str
, const char* key
, size_t size
) {
1168 // Format size in human-readable format
1169 int r
= pakfire_format_size(buffer
, size
);
1173 pakfire_package_dump_add_line(str
, key
, buffer
);
1176 static int pakfire_sort_dependencies(const void* p1
, const void* p2
) {
1177 const char* dep1
= *(const char**)p1
;
1178 const char* dep2
= *(const char**)p2
;
1180 return strcmp(dep1
, dep2
);
1183 PAKFIRE_EXPORT
char* pakfire_package_dump(struct pakfire_package
* pkg
, int flags
) {
1187 const char* name
= pakfire_package_get_string(pkg
, PAKFIRE_PKG_NAME
);
1189 pakfire_package_dump_add_line(&string
, _("Name"), name
);
1192 const char* evr
= pakfire_package_get_string(pkg
, PAKFIRE_PKG_EVR
);
1194 pakfire_package_dump_add_line(&string
, _("Version"), evr
);
1197 const char* arch
= pakfire_package_get_string(pkg
, PAKFIRE_PKG_ARCH
);
1199 pakfire_package_dump_add_line(&string
, _("Arch"), arch
);
1202 size_t size
= pakfire_package_get_size(pkg
);
1204 pakfire_package_dump_add_line_size(&string
, _("Size"), size
);
1207 if (pakfire_package_is_installed(pkg
)) {
1208 size_t installsize
= pakfire_package_get_num(pkg
, PAKFIRE_PKG_INSTALLSIZE
, 0);
1210 pakfire_package_dump_add_line_size(&string
, _("Installed Size"), installsize
);
1214 size_t downloadsize
= pakfire_package_get_num(pkg
, PAKFIRE_PKG_DOWNLOADSIZE
, 0);
1216 pakfire_package_dump_add_line_size(&string
, _("Download Size"), downloadsize
);
1220 struct pakfire_repo
* repo
= pakfire_package_get_repo(pkg
);
1222 if (!pakfire_repo_name_equals(repo
, PAKFIRE_REPO_DUMMY
)) {
1223 const char* repo_name
= pakfire_repo_get_name(repo
);
1224 pakfire_package_dump_add_line(&string
, _("Repo"), repo_name
);
1227 pakfire_repo_unref(repo
);
1231 const char* summary
= pakfire_package_get_string(pkg
, PAKFIRE_PKG_SUMMARY
);
1233 pakfire_package_dump_add_line(&string
, _("Summary"), summary
);
1236 const char* description
= pakfire_package_get_string(pkg
, PAKFIRE_PKG_DESCRIPTION
);
1238 pakfire_package_dump_add_lines(&string
, _("Description"), description
);
1241 const char* groups
= pakfire_package_get_string(pkg
, PAKFIRE_PKG_GROUPS
);
1243 pakfire_package_dump_add_lines(&string
, _("Groups"), groups
);
1246 const char* url
= pakfire_package_get_string(pkg
, PAKFIRE_PKG_URL
);
1248 pakfire_package_dump_add_line(&string
, _("URL"), url
);
1251 const char* license
= pakfire_package_get_string(pkg
, PAKFIRE_PKG_LICENSE
);
1253 pakfire_package_dump_add_line(&string
, _("License"), license
);
1255 if (flags
& PAKFIRE_PKG_DUMP_LONG
) {
1257 time_t install_time
= pakfire_package_get_num(pkg
, PAKFIRE_PKG_INSTALLTIME
, 0);
1259 pakfire_package_dump_add_line_date(&string
, _("Install Time"), install_time
);
1262 const char* distro
= pakfire_package_get_string(pkg
, PAKFIRE_PKG_DISTRO
);
1264 pakfire_package_dump_add_line(&string
, _("Distribution"), distro
);
1267 const char* packager
= pakfire_package_get_string(pkg
, PAKFIRE_PKG_PACKAGER
);
1269 pakfire_package_dump_add_line(&string
, _("Packager"), packager
);
1272 const char* vendor
= pakfire_package_get_string(pkg
, PAKFIRE_PKG_VENDOR
);
1274 pakfire_package_dump_add_line(&string
, _("Vendor"), vendor
);
1277 const char* uuid
= pakfire_package_get_string(pkg
, PAKFIRE_PKG_UUID
);
1279 pakfire_package_dump_add_line(&string
, _("UUID"), uuid
);
1282 const char* build_id
= pakfire_package_get_string(pkg
, PAKFIRE_PKG_BUILD_ID
);
1284 pakfire_package_dump_add_line(&string
, _("Build ID"), build_id
);
1286 enum pakfire_digest_types digest_type
= PAKFIRE_DIGEST_UNDEFINED
;
1287 size_t digest_length
= 0;
1290 const unsigned char* digest
= pakfire_package_get_digest(pkg
,
1291 &digest_type
, &digest_length
);
1293 switch (digest_type
) {
1294 case PAKFIRE_DIGEST_SHA2_512
:
1295 pakfire_package_dump_add_line_hex(&string
,
1296 _("SHA2-512 Digest"), digest
, digest_length
);
1299 case PAKFIRE_DIGEST_SHA2_256
:
1300 pakfire_package_dump_add_line_hex(&string
,
1301 _("SHA2-256 Digest"), digest
, digest_length
);
1304 case PAKFIRE_DIGEST_SHA3_512
:
1305 case PAKFIRE_DIGEST_SHA3_256
:
1306 case PAKFIRE_DIGEST_BLAKE2B512
:
1307 case PAKFIRE_DIGEST_BLAKE2S256
:
1308 case PAKFIRE_DIGEST_UNDEFINED
:
1314 const char* source_package
= pakfire_package_get_string(pkg
, PAKFIRE_PKG_SOURCE_PKG
);
1316 pakfire_package_dump_add_line(&string
, _("Source Package"), source_package
);
1319 time_t build_time
= pakfire_package_get_num(pkg
, PAKFIRE_PKG_BUILD_TIME
, 0);
1321 pakfire_package_dump_add_line_date(&string
, _("Build Time"), build_time
);
1324 const char* build_host
= pakfire_package_get_string(pkg
, PAKFIRE_PKG_BUILD_HOST
);
1326 pakfire_package_dump_add_line(&string
, _("Build Host"), build_host
);
1329 for (const struct pakfire_dep
* dep
= pakfire_deps
; dep
->key
; dep
++) {
1330 char** deps
= pakfire_package_get_deps(pkg
, dep
->key
);
1334 // Count elements in the list
1335 for (char** d
= deps
; *d
; d
++)
1339 qsort(deps
, count
, sizeof(*deps
), pakfire_sort_dependencies
);
1342 case PAKFIRE_PKG_PROVIDES
:
1343 name
= _("Provides");
1346 case PAKFIRE_PKG_PREREQUIRES
:
1347 name
= _("Pre-Requires");
1350 case PAKFIRE_PKG_REQUIRES
:
1351 name
= _("Requires");
1354 case PAKFIRE_PKG_CONFLICTS
:
1355 name
= _("Conflicts");
1358 case PAKFIRE_PKG_OBSOLETES
:
1359 name
= _("Obsoletes");
1362 case PAKFIRE_PKG_RECOMMENDS
:
1363 name
= _("Recommends");
1366 case PAKFIRE_PKG_SUGGESTS
:
1367 name
= _("Suggests");
1370 case PAKFIRE_PKG_SUPPLEMENTS
:
1371 name
= _("Supplements");
1374 case PAKFIRE_PKG_ENHANCES
:
1375 name
= _("Enhances");
1383 // Write it to the console
1384 for (char** d
= deps
; *d
; d
++) {
1385 pakfire_package_dump_add_line(&string
, name
, *d
);
1388 // Clear name after first line
1396 if (flags
& PAKFIRE_PKG_DUMP_FILELIST
) {
1397 struct pakfire_filelist
* filelist
= pakfire_package_get_filelist(pkg
);
1399 const char* prefix
= _("Filelist");
1401 for (unsigned int i
= 0; i
< pakfire_filelist_length(filelist
); i
++) {
1402 struct pakfire_file
* file
= pakfire_filelist_get(filelist
, i
);
1404 const char* path
= pakfire_file_get_path(file
);
1405 pakfire_package_dump_add_line(&string
, prefix
, path
);
1407 pakfire_file_unref(file
);
1409 // Only prefix the first line
1413 pakfire_filelist_unref(filelist
);
1419 PAKFIRE_EXPORT
struct pakfire_archive
* pakfire_package_get_archive(struct pakfire_package
* pkg
) {
1420 struct pakfire_archive
* archive
= NULL
;
1422 // Otherwise open the archive from the cache
1423 const char* path
= pakfire_package_get_string(pkg
, PAKFIRE_PKG_PATH
);
1428 int r
= pakfire_archive_open(&archive
, pkg
->pakfire
, path
);
1435 struct pakfire_package_filelist_search
{
1436 struct pakfire
* pakfire
;
1437 struct pakfire_filelist
* filelist
;
1441 static int __pakfire_package_fetch_filelist(void* data
, Solvable
* s
, Repodata
* repodata
,
1442 Repokey
* key
, struct s_KeyValue
* kv
) {
1443 struct pakfire_package_filelist_search
* search
= (struct pakfire_package_filelist_search
*)data
;
1445 struct pakfire_file
* file
= NULL
;
1448 // Skip any results of the wrong type
1449 if (key
->type
!= REPOKEY_TYPE_DIRSTRARRAY
)
1453 const char* path
= repodata_dir2str(repodata
, kv
->id
, kv
->str
);
1459 // Create a new file entry
1460 r
= pakfire_file_create(&file
, search
->pakfire
);
1465 r
= pakfire_file_set_path(file
, path
);
1469 // Append the file to the filelist
1470 r
= pakfire_filelist_add(search
->filelist
, file
);
1475 // Store the error code
1479 pakfire_file_unref(file
);
1484 static int pakfire_package_fetch_filelist(struct pakfire_package
* pkg
, struct pakfire_filelist
* filelist
) {
1485 struct pakfire_package_filelist_search search
= {
1486 .pakfire
= pkg
->pakfire
,
1487 .filelist
= filelist
,
1491 pakfire_package_internalize_repo(pkg
);
1493 Solvable
* s
= get_solvable(pkg
);
1495 Repodata
* repodata
= repo_last_repodata(s
->repo
);
1497 // Search for all files
1498 repodata_search(repodata
, pkg
->id
, SOLVABLE_FILELIST
, SEARCH_FILES
,
1499 __pakfire_package_fetch_filelist
, &search
);
1501 // Break on any error
1508 PAKFIRE_EXPORT
struct pakfire_filelist
* pakfire_package_get_filelist(struct pakfire_package
* pkg
) {
1509 struct pakfire_filelist
* filelist
= NULL
;
1511 // Create a new filelist
1512 int r
= pakfire_filelist_create(&filelist
, pkg
->pakfire
);
1516 // Fetch all entries from the repository database
1517 r
= pakfire_package_fetch_filelist(pkg
, filelist
);
1525 pakfire_filelist_unref(filelist
);
1530 int pakfire_package_append_file(struct pakfire_package
* pkg
, const char* path
) {
1532 struct pakfire_repo
* repo
= pakfire_package_get_repo(pkg
);
1534 ERROR(pkg
->pakfire
, "Could not find repository for %s: %m\n",
1535 pakfire_package_get_string(pkg
, PAKFIRE_PKG_NEVRA
));
1539 Repodata
* repodata
= pakfire_repo_get_repodata(repo
);
1541 const char* basename
= pakfire_basename(path
);
1542 const char* dirname
= pakfire_dirname(path
);
1544 // Convert directory into ID
1545 Id did
= repodata_str2dir(repodata
, dirname
, 1);
1547 did
= repodata_str2dir(repodata
, "/", 1);
1550 repodata_add_dirstr(repodata
, pkg
->id
,
1551 SOLVABLE_FILELIST
, did
, basename
);
1553 pakfire_repo_unref(repo
);
1555 // This package has changed
1556 pakfire_package_has_changed(pkg
);
1561 static int __pakfire_package_set_filelist(struct pakfire
* pakfire
,
1562 struct pakfire_file
* file
, void* data
) {
1563 struct pakfire_package
* pkg
= (struct pakfire_package
*)data
;
1566 const char* path
= pakfire_file_get_path(file
);
1568 return pakfire_package_append_file(pkg
, path
);
1571 PAKFIRE_EXPORT
int pakfire_package_set_filelist(
1572 struct pakfire_package
* pkg
, struct pakfire_filelist
* filelist
) {
1573 return pakfire_filelist_walk(filelist
, __pakfire_package_set_filelist
, pkg
);
1576 int pakfire_package_set_filelist_from_string(struct pakfire_package
* pkg
, const char* files
) {
1581 char* buffer
= strdup(files
);
1585 // Walk through all files
1586 char* path
= strtok_r(buffer
, "\n", &p
);
1588 r
= pakfire_package_append_file(pkg
, path
);
1592 path
= strtok_r(NULL
, "\n", &p
);
1602 static int _pakfire_package_add_json_dependencies(
1603 struct pakfire_package
* pkg
,
1604 struct json_object
* json
,
1606 const enum pakfire_package_key key
) {
1607 // Fetch dependencies
1608 char** dependencies
= pakfire_package_get_deps(pkg
, key
);
1613 int r
= pakfire_json_add_string_array(pkg
->pakfire
, json
, name
, dependencies
);
1619 for (char** dep
= dependencies
; *dep
; dep
++)
1627 static int pakfire_package_add_json_dependencies(
1628 struct pakfire_package
* pkg
, struct json_object
* md
) {
1631 // Create new dependencies object
1632 struct json_object
* object
= json_object_new_object();
1637 r
= _pakfire_package_add_json_dependencies(pkg
, object
,
1638 "prerequires", PAKFIRE_PKG_PREREQUIRES
);
1643 r
= _pakfire_package_add_json_dependencies(pkg
, object
,
1644 "requires", PAKFIRE_PKG_REQUIRES
);
1649 r
= _pakfire_package_add_json_dependencies(pkg
, object
,
1650 "provides", PAKFIRE_PKG_PROVIDES
);
1655 r
= _pakfire_package_add_json_dependencies(pkg
, object
,
1656 "conflicts", PAKFIRE_PKG_CONFLICTS
);
1661 r
= _pakfire_package_add_json_dependencies(pkg
, object
,
1662 "obsoletes", PAKFIRE_PKG_OBSOLETES
);
1667 r
= _pakfire_package_add_json_dependencies(pkg
, object
,
1668 "recommends", PAKFIRE_PKG_RECOMMENDS
);
1673 r
= _pakfire_package_add_json_dependencies(pkg
, object
,
1674 "suggests", PAKFIRE_PKG_SUGGESTS
);
1679 r
= _pakfire_package_add_json_dependencies(pkg
, object
,
1680 "supplements", PAKFIRE_PKG_SUPPLEMENTS
);
1685 r
= _pakfire_package_add_json_dependencies(pkg
, object
,
1686 "enhances", PAKFIRE_PKG_ENHANCES
);
1691 r
= json_object_object_add(md
, "dependencies", object
);
1697 json_object_put(object
);
1702 static int __pakfire_package_add_json_filelist(struct pakfire
* pakfire
,
1703 struct pakfire_file
* file
, void* data
) {
1704 struct json_object
* filelist
= (struct json_object
*)data
;
1707 // Fetch the file path
1708 const char* path
= pakfire_file_get_path(file
);
1710 // Create a new JSON string
1711 struct json_object
* object
= json_object_new_string(path
);
1715 // Append the string
1716 r
= json_object_array_add(filelist
, object
);
1725 json_object_put(object
);
1730 static int pakfire_package_add_json_filelist(
1731 struct pakfire_package
* pkg
, struct json_object
* md
) {
1732 struct pakfire_filelist
* filelist
= NULL
;
1733 struct json_object
* object
= NULL
;
1736 // Fetch the filelist
1737 filelist
= pakfire_package_get_filelist(pkg
);
1739 ERROR(pkg
->pakfire
, "Could not fetch package filelist\n");
1744 // Create a new JSON array
1745 object
= json_object_new_array();
1747 ERROR(pkg
->pakfire
, "Could not create a JSON array\n");
1752 // Walk through the filelist
1753 r
= pakfire_filelist_walk(filelist
, __pakfire_package_add_json_filelist
, object
);
1758 r
= json_object_object_add(md
, "filelist", object
);
1763 // Free JSON object on error
1765 json_object_put(object
);
1767 pakfire_filelist_unref(filelist
);
1772 static int __pakfire_package_add_build_packages(struct pakfire
* pakfire
,
1773 struct pakfire_package
* pkg
, void* p
) {
1774 struct json_object
* object
= (struct json_object
*)p
;
1777 const char* name
= pakfire_package_get_string(pkg
, PAKFIRE_PKG_NAME
);
1778 const char* evr
= pakfire_package_get_string(pkg
, PAKFIRE_PKG_EVR
);
1780 if (!name
|| !evr
) {
1781 ERROR(pakfire
, "Could not fetch package information: %m\n");
1785 // Add package information to the list
1786 r
= pakfire_json_add_string(pakfire
, object
, name
, evr
);
1788 ERROR(pakfire
, "Could not add package to packages list: %m\n");
1795 static int pakfire_package_add_build_packages(struct pakfire_package
* pkg
,
1796 struct json_object
* md
) {
1797 struct pakfire_repo
* repo
= NULL
;
1798 struct pakfire_packagelist
* packages
= NULL
;
1799 struct json_object
* object
= NULL
;
1802 // Create a new JSON array
1803 object
= json_object_new_object();
1805 ERROR(pkg
->pakfire
, "Could not create a new JSON object: %m\n");
1810 // Fetch the installed repository
1811 repo
= pakfire_get_installed_repo(pkg
->pakfire
);
1813 ERROR(pkg
->pakfire
, "Could not fetch the installed repository: %m\n");
1818 // Create a new list
1819 r
= pakfire_packagelist_create(&packages
, pkg
->pakfire
);
1823 // Fetch all installed packages
1824 r
= pakfire_repo_to_packagelist(repo
, packages
);
1826 ERROR(pkg
->pakfire
, "Could not fetch packages from installed repository: %m\n");
1830 // Add all packages to the array
1831 r
= pakfire_packagelist_walk(packages
, __pakfire_package_add_build_packages
, object
);
1836 r
= json_object_object_add(md
, "packages", json_object_get(object
));
1842 pakfire_packagelist_unref(packages
);
1844 pakfire_repo_unref(repo
);
1846 json_object_put(object
);
1851 static int pakfire_package_add_build_metadata(struct pakfire_package
* pkg
,
1852 struct json_object
* md
) {
1855 // Create a new JSON object
1856 struct json_object
* object
= json_object_new_object();
1860 // Add pakfire version that generated this metadata
1861 r
= pakfire_json_add_string(pkg
->pakfire
, object
, "pakfire", PACKAGE_VERSION
);
1866 const char* build_host
= pakfire_package_get_string(pkg
, PAKFIRE_PKG_BUILD_HOST
);
1868 r
= pakfire_json_add_string(pkg
->pakfire
, object
, "host", build_host
);
1874 const char* build_id
= pakfire_package_get_string(pkg
, PAKFIRE_PKG_BUILD_ID
);
1876 r
= pakfire_json_add_string(pkg
->pakfire
, object
, "id", build_id
);
1882 time_t build_time
= pakfire_package_get_num(pkg
, PAKFIRE_PKG_BUILD_TIME
, 0);
1884 r
= pakfire_json_add_integer(pkg
->pakfire
, object
, "time", build_time
);
1889 // Source package name
1890 const char* name
= pakfire_package_get_string(pkg
, PAKFIRE_PKG_SOURCE_NAME
);
1892 r
= pakfire_json_add_string(pkg
->pakfire
, object
, "source-name", name
);
1897 // Source package EVR
1898 const char* evr
= pakfire_package_get_string(pkg
, PAKFIRE_PKG_SOURCE_EVR
);
1900 r
= pakfire_json_add_string(pkg
->pakfire
, object
, "source-evr", evr
);
1905 // Source package arch
1906 const char* arch
= pakfire_package_get_string(pkg
, PAKFIRE_PKG_SOURCE_ARCH
);
1908 r
= pakfire_json_add_string(pkg
->pakfire
, object
, "source-arch", arch
);
1914 if (!pakfire_package_is_source(pkg
)) {
1915 r
= pakfire_package_add_build_packages(pkg
, object
);
1921 r
= json_object_object_add(md
, "build", object
);
1927 json_object_put(object
);
1932 struct json_object
* pakfire_package_to_json(struct pakfire_package
* pkg
) {
1933 struct json_object
* md
= json_object_new_object();
1937 const char* name
= pakfire_package_get_string(pkg
, PAKFIRE_PKG_NAME
);
1939 r
= pakfire_json_add_string(pkg
->pakfire
, md
, "name", name
);
1945 const char* evr
= pakfire_package_get_string(pkg
, PAKFIRE_PKG_EVR
);
1947 r
= pakfire_json_add_string(pkg
->pakfire
, md
, "evr", evr
);
1953 const char* arch
= pakfire_package_get_string(pkg
, PAKFIRE_PKG_ARCH
);
1955 r
= pakfire_json_add_string(pkg
->pakfire
, md
, "arch", arch
);
1961 const char* vendor
= pakfire_package_get_string(pkg
, PAKFIRE_PKG_VENDOR
);
1963 r
= pakfire_json_add_string(pkg
->pakfire
, md
, "vendor", vendor
);
1969 const char* distribution
= pakfire_package_get_string(pkg
, PAKFIRE_PKG_DISTRO
);
1971 r
= pakfire_json_add_string(pkg
->pakfire
, md
, "distribution", distribution
);
1977 const char* uuid
= pakfire_package_get_string(pkg
, PAKFIRE_PKG_UUID
);
1979 r
= pakfire_json_add_string(pkg
->pakfire
, md
, "uuid", uuid
);
1985 const char* groups
= pakfire_package_get_string(pkg
, PAKFIRE_PKG_GROUPS
);
1987 r
= pakfire_json_add_string(pkg
->pakfire
, md
, "groups", groups
);
1993 const char* packager
= pakfire_package_get_string(pkg
, PAKFIRE_PKG_PACKAGER
);
1995 r
= pakfire_json_add_string(pkg
->pakfire
, md
, "packager", packager
);
2001 const char* url
= pakfire_package_get_string(pkg
, PAKFIRE_PKG_URL
);
2003 r
= pakfire_json_add_string(pkg
->pakfire
, md
, "url", url
);
2009 const char* license
= pakfire_package_get_string(pkg
, PAKFIRE_PKG_LICENSE
);
2011 r
= pakfire_json_add_string(pkg
->pakfire
, md
, "license", license
);
2017 const char* summary
= pakfire_package_get_string(pkg
, PAKFIRE_PKG_SUMMARY
);
2019 r
= pakfire_json_add_string(pkg
->pakfire
, md
, "summary", summary
);
2025 const char* description
= pakfire_package_get_string(pkg
, PAKFIRE_PKG_DESCRIPTION
);
2027 r
= pakfire_json_add_string(pkg
->pakfire
, md
, "description", description
);
2032 // Installed package size
2033 size_t installsize
= pakfire_package_get_num(pkg
, PAKFIRE_PKG_INSTALLSIZE
, 0);
2035 r
= pakfire_json_add_integer(pkg
->pakfire
, md
, "size", installsize
);
2039 // Generate dependency metadata
2040 r
= pakfire_package_add_json_dependencies(pkg
, md
);
2044 // Generate filelist
2045 r
= pakfire_package_add_json_filelist(pkg
, md
);
2049 // Generate build metadata
2050 r
= pakfire_package_add_build_metadata(pkg
, md
);
2056 json_object_put(md
);