#include <tzplatform_config.h>
#include <unistd.h>
+#include <filesystem>
+#include <fstream>
#include <string>
#include <regex>
#include "common/utils/file_util.h"
#include "common/utils/request.h"
-namespace bf = boost::filesystem;
-namespace bi = boost::iostreams;
namespace ci = common_installer;
+namespace fs = std::filesystem;
namespace common_installer {
bool Signature::SetPath() {
- bf::path path = bf::path((is_readonly_package_) ?
+ fs::path path = fs::path((is_readonly_package_) ?
tzplatform_getenv(TZ_SYS_RO_SHARE) : tzplatform_getenv(TZ_SYS_SHARE)) /
"signatures";
if (!CreateDir(path))
file_path_ = path / std::string(pkgid_ + ".txt");
backup_path_ = path / std::string(pkgid_ + "_backup.txt");
- if (bf::exists(backup_path_))
- bf::remove(backup_path_);
- if (bf::exists(file_path_))
- bf::rename(file_path_, backup_path_);
+ if (fs::exists(backup_path_))
+ fs::remove(backup_path_);
+ if (fs::exists(file_path_))
+ fs::rename(file_path_, backup_path_);
return true;
}
bool Signature::CheckSignatures(bool check_reference, PrivilegeLevel* level,
- boost::filesystem::path sig_root_path,
+ std::filesystem::path sig_root_path,
std::string *error_message) {
if (!ValidateSignatures(sig_root_path, level, cert_info_,
check_reference, error_message))
return true;
}
-bool Signature::GetPrivilegeLevel(boost::filesystem::path sig_root_path,
+bool Signature::GetPrivilegeLevel(std::filesystem::path sig_root_path,
PrivilegeLevel* level,
std::string* error_message) {
bool check_reference = true;
return true;
}
-bool Signature::StoreSignature(bi::stream<bi::file_descriptor_sink> *ofs,
+bool Signature::StoreSignature(std::ofstream* ofs,
const ValidationCore::CertificatePtr& cert,
const ValidationCore::CertificatePtr& im_cert,
const ValidationCore::CertificatePtr& root_cert) {
if (!ofs)
return false;
- *ofs << ((cert) ? cert->getBase64().c_str() : "") << std::endl;
- *ofs << ((im_cert) ? im_cert->getBase64().c_str() : "") << std::endl;
- *ofs << ((root_cert) ? root_cert->getBase64().c_str() : "") << std::endl;
+ *ofs << ((cert) ? cert->getBase64() : "") << std::endl;
+ *ofs << ((im_cert) ? im_cert->getBase64() : "") << std::endl;
+ *ofs << ((root_cert) ? root_cert->getBase64() : "") << std::endl;
return true;
}
bool Signature::Store() {
bool ret = true;
- bi::stream<bi::file_descriptor_sink> ofs(file_path_);
+ std::ofstream ofs(file_path_);
if (!StoreSignature(&ofs,
cert_info_->dist2_cert.get(),
cert_info_->dist2_im_cert.get(),
cert_info_->dist_root_cert.get()))
ret = false;
ofs.flush();
- ::fsync(ofs->handle());
ofs.close();
+ SyncFile(file_path_);
return ret;
}
-bool Signature::RemoveSignature(const bf::path& path) {
+bool Signature::RemoveSignature(const fs::path& path) {
// dist signatures cannot be removed when mount install/update
if (request_type_ == RequestType::MountInstall ||
request_type_ == RequestType::MountUpdate)
return true;
- for (bf::directory_iterator file(path);
- file != bf::directory_iterator();
+ for (fs::directory_iterator file(path);
+ file != fs::directory_iterator();
++file) {
try {
- bf::path file_path(file->path());
+ fs::path file_path(file->path());
- if (bf::is_symlink(symlink_status(file_path)) ||
- bf::is_directory(file_path))
+ if (fs::is_symlink(symlink_status(file_path)) ||
+ fs::is_directory(file_path))
continue;
std::regex distributor_regex("^(signature)([1-9][0-9]*)(\\.xml)");
return false;
}
}
- } catch (const bf::filesystem_error& error) {
+ } catch (const fs::filesystem_error& error) {
LOG(ERROR) << "Failed to remove signature files: " << error.what();
return false;
}
return true;
}
-bool Signature::SaveSignature(const bf::path& path) {
+bool Signature::SaveSignature(const fs::path& path) {
if (!SetPath() || !Store() || !RemoveSignature(path))
return false;
return true;
}
-const bf::path& Signature::GetFilePath() const {
+const fs::path& Signature::GetFilePath() const {
return file_path_;
}
-const bf::path& Signature::GetBackupPath() const {
+const fs::path& Signature::GetBackupPath() const {
return backup_path_;
}