#include "common/recovery_file.h"
#include <boost/filesystem/operations.hpp>
+#include <boost/iostreams/stream.hpp>
+#include <boost/iostreams/device/file_descriptor.hpp>
#include <boost/system/error_code.hpp>
#include <manifest_parser/utils/logging.h>
#include <array>
#include <cstring>
+#include <string>
#include <map>
#include <utility>
namespace bf = boost::filesystem;
namespace bs = boost::system;
+namespace bi = boost::iostreams;
namespace ci = common_installer;
namespace {
", error: " << error;
return false;
}
- sync();
}
- FILE* handle = fopen(path_.c_str(), "wx");
- if (!handle) {
+ bi::stream<bi::file_descriptor_sink> ofs(path_);
+ if (!ofs) {
LOG(ERROR) << "Cannot write recovery file";
return false;
}
+
switch (type_) {
case RequestType::Install:
- fputs(kRecoveryInstallString, handle);
+ ofs << kRecoveryInstallString << std::endl;
break;
case RequestType::Update:
- fputs(kRecoveryUpdateString, handle);
+ ofs << kRecoveryUpdateString << std::endl;
break;
case RequestType::Uninstall:
- fputs(kRecoveryUninstallationString, handle);
+ ofs << kRecoveryUninstallationString << std::endl;
break;
case RequestType::Reinstall:
- fputs(kRecoveryRdsString, handle);
+ ofs << kRecoveryRdsString << std::endl;
break;
case RequestType::Delta:
- fputs(kRecoveryDeltaString, handle);
+ ofs << kRecoveryDeltaString << std::endl;
break;
case RequestType::MountInstall:
- fputs(kRecoveryMountInstallString, handle);
+ ofs << kRecoveryMountInstallString << std::endl;
break;
case RequestType::MountUpdate:
- fputs(kRecoveryMountUpdateString, handle);
+ ofs << kRecoveryMountUpdateString << std::endl;
break;
case RequestType::ReadonlyUpdateInstall:
- fputs(kRecoveryReadonlyUpdateInstallString, handle);
+ ofs << kRecoveryReadonlyUpdateInstallString << std::endl;
break;
default:
- fputs(kRecoveryUnknownString, handle);
+ ofs << kRecoveryUnknownString << std::endl;
break;
}
- fputs("\n", handle);
- fputs(unpacked_dir_.c_str(), handle);
- fputs("\n", handle);
- fputs(pkgid_.c_str(), handle);
- fputs("\n", handle);
- fputs(backup_done_ ? "true" : "false", handle);
- fputs("\n", handle);
- fputs(cleanup_ ? "cleanup" : "rollback", handle);
- fputs("\n", handle);
- fclose(handle);
- sync();
+ ofs << unpacked_dir_ << std::endl;
+ ofs << pkgid_ << std::endl;
+ ofs << (backup_done_ ? "true" : "false") << std::endl;
+ ofs << (cleanup_ ? "cleanup" : "rollback") << std::endl;
+ ofs.flush();
+ ::fsync(ofs->handle());
+ ofs.close();
Remove(backup_path_);
return true;