return Step::Status::MANIFEST_NOT_FOUND;
}
+ new_path_ = bf::path(getUserManifestPath(context_->uid.get(),
+ context_->is_readonly_package.get())) / bf::path(context_->pkgid.get());
+ new_path_ += ".xml";
+ if (bf::exists(new_path_)) {
+ backup_path_ = new_path_.string() + ".bck";
+ bs::error_code error;
+ bf::copy_file(new_path_, backup_path_, error);
+ if (error)
+ LOG(WARNING) << "Failed to backup original manifest file " << new_path_
+ << " due to error: " << error;
+ }
+
return Step::Status::OK;
}
if (!ConvertXml(doc))
return Step::Status::MANIFEST_ERROR;
- bf::path new_path =
- bf::path(getUserManifestPath(context_->uid.get(),
- context_->is_readonly_package.get()))
- / bf::path(context_->pkgid.get());
- new_path += ".xml";
- if (!bf::exists(new_path.parent_path())) {
+ if (!bf::exists(new_path_.parent_path())) {
bs::error_code error;
- bf::create_directories(new_path.parent_path(), error);
+ bf::create_directories(new_path_.parent_path(), error);
}
- if (xmlSaveFile(new_path.string().c_str(), doc) == -1) {
+ if (xmlSaveFile(new_path_.string().c_str(), doc) == -1) {
LOG(ERROR) << "Failed to write xml file";
return Step::Status::MANIFEST_ERROR;
}
- context_->xml_path.set(new_path.string());
+ context_->xml_path.set(new_path_.string());
if (pkgmgr_parser_check_manifest_validation(
context_->xml_path.get().c_str()) != 0) {
}
common_installer::Step::Status StepConvertXml::clean() {
+ if (!backup_path_.empty()) {
+ bs::error_code error;
+ bf::remove(backup_path_, error);
+ LOG(WARNING) << "Failed to remove backup file " << backup_path_
+ << " due to error: " << error;
+ }
+
return Step::Status::OK;
}
common_installer::Step::Status StepConvertXml::undo() {
- bs::error_code error;
-
- if (bf::exists(context_->xml_path.get()))
- bf::remove_all(context_->xml_path.get(), error);
+ if (!backup_path_.empty()) {
+ bs::error_code error;
+ bf::remove(new_path_, error);
+ if (error) {
+ LOG(WARNING) << "Failed to remove " << new_path_
+ << " due to error " << error;
+ } else {
+ bf::rename(backup_path_, new_path_, error);
+ if (error)
+ LOG(WARNING) << "Failed to restore " << new_path_
+ << " due to error " << error;
+ }
+ }
return Step::Status::OK;
}