forked from anydistro/bxt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(daemon): use pacman's repo-add desc field order
Fixes anydistro#121
- Loading branch information
1 parent
1b5e83a
commit 65cca92
Showing
8 changed files
with
148 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* === This file is part of bxt === | ||
* | ||
* SPDX-FileCopyrightText: 2024 Artem Grinev <[email protected]> | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
* | ||
*/ | ||
#pragma once | ||
|
||
#include <algorithm> | ||
|
||
// Needed for string literals to be used as template parameters. | ||
template<unsigned N> struct FixedString { | ||
char buf[N + 1] {}; | ||
constexpr FixedString(char const* s) { std::copy(s, s + N, buf); } | ||
constexpr operator char const*() const { return buf; } | ||
}; | ||
|
||
template<unsigned N> FixedString(char const (&)[N]) -> FixedString<N - 1>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* === This file is part of bxt === | ||
* | ||
* SPDX-FileCopyrightText: 2024 Artem Grinev <[email protected]> | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
* | ||
*/ | ||
|
||
#include "DescFormatter.h" | ||
|
||
#include "utilities/base64.h" | ||
#include "utilities/hash_from_file.h" | ||
|
||
#include <sstream> | ||
|
||
namespace bxt::Utilities::AlpmDb { | ||
|
||
// This function formats package information into a desc contents string | ||
// It follows the format used by repo-add.sh in pacman for compatibility: | ||
// https://gitlab.archlinux.org/pacman/pacman/-/blob/6ba5c20e7629ae9bdd7ceaf5a45484c434363ec5/scripts/repo-add.sh.in#L296-326 | ||
std::string DescFormatter::format() const { | ||
std::ostringstream oss; | ||
oss << format_entry<"FILENAME">(m_filepath.filename().string()); | ||
oss << format_pkginfo_entry<"NAME", "pkgname">(); | ||
oss << format_pkginfo_entry<"BASE", "pkgbase">(); | ||
oss << format_pkginfo_entry<"VERSION", "pkgver">(); | ||
oss << format_pkginfo_entry<"DESC", "pkgdesc">(); | ||
oss << format_pkginfo_entry<"GROUPS", "groups">(); | ||
oss << format_entry<"CSIZE">( | ||
std::to_string(std::filesystem::file_size(m_filepath))); | ||
oss << format_pkginfo_entry<"ISIZE", "size">(); | ||
|
||
// add checksums | ||
oss << format_entry<"MD5SUM">( | ||
bxt::hash_from_file<MD5, MD5_DIGEST_LENGTH>(m_filepath.string())); | ||
|
||
oss << format_entry<"SHA256SUM">( | ||
bxt::hash_from_file<SHA256, SHA256_DIGEST_LENGTH>(m_filepath.string())); | ||
|
||
// add PGP sig | ||
if (!m_signature.empty()) { | ||
oss << format_entry<"PGPSIG">(bxt::Utilities::b64_encode(m_signature)); | ||
} | ||
|
||
oss << format_pkginfo_entry<"URL", "url">(); | ||
oss << format_pkginfo_entry<"LICENSE", "license">(); | ||
oss << format_pkginfo_entry<"ARCH", "arch">(); | ||
oss << format_pkginfo_entry<"BUILDDATE", "builddate">(); | ||
oss << format_pkginfo_entry<"PACKAGER", "packager">(); | ||
oss << format_pkginfo_entry<"REPLACES", "replaces">(); | ||
oss << format_pkginfo_entry<"CONFLICTS", "conflict">(); | ||
oss << format_pkginfo_entry<"PROVIDES", "provides">(); | ||
oss << format_pkginfo_entry<"DEPENDS", "depend">(); | ||
oss << format_pkginfo_entry<"OPTDEPENDS", "optdepend">(); | ||
oss << format_pkginfo_entry<"MAKEDEPENDS", "makedepend">(); | ||
oss << format_pkginfo_entry<"CHECKDEPENDS", "checkdepend">(); | ||
return oss.str(); | ||
} | ||
} // namespace bxt::Utilities::AlpmDb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* === This file is part of bxt === | ||
* | ||
* SPDX-FileCopyrightText: 2024 Artem Grinev <[email protected]> | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
* | ||
*/ | ||
#pragma once | ||
|
||
#include "utilities/FixedString.h" | ||
#include "utilities/alpmdb/PkgInfo.h" | ||
|
||
#include <boost/algorithm/string/join.hpp> | ||
#include <filesystem> | ||
#include <fmt/format.h> | ||
#include <openssl/md5.h> | ||
#include <openssl/sha.h> | ||
#include <string> | ||
|
||
namespace bxt::Utilities::AlpmDb { | ||
class DescFormatter { | ||
public: | ||
DescFormatter(PkgInfo m_pkg_info, | ||
std::filesystem::path m_filepath, | ||
std::string m_signature) | ||
: m_pkg_info(std::move(m_pkg_info)), | ||
m_filepath(std::move(m_filepath)), | ||
m_signature(std::move(m_signature)) {} | ||
|
||
static constexpr char format_string[] = "%{}%\n{}\n\n"; | ||
|
||
template<FixedString desc_field, FixedString pkginfo_field> | ||
std::string format_pkginfo_entry() const { | ||
auto values = m_pkg_info.values(pkginfo_field.buf); | ||
if (values.empty()) { return ""; } | ||
|
||
return fmt::format(format_string, desc_field.buf, | ||
boost::join(values, "\n")); | ||
} | ||
template<FixedString desc_field> | ||
std::string format_entry(const std::string& value) const { | ||
if (value.empty()) return ""; | ||
return fmt::format(format_string, desc_field.buf, value); | ||
} | ||
|
||
std::string format() const; | ||
|
||
private: | ||
PkgInfo m_pkg_info; | ||
std::filesystem::path m_filepath; | ||
std::string m_signature; | ||
}; | ||
|
||
} // namespace bxt::Utilities::AlpmDb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters