This commit force to save encrypted data as soon as possible.
There is still small time window then desynhronization may happen.
Desynchronization may occure if you take out battery exectly after the
data was saved by ckm and the confirmation was not send to
security-server yet.
Change-Id: Ib4d4f0299001d9c71b13acdcfa136298d942ab6c
* See the License for the specific language governing permissions and
* limitations under the License
*
- * @file fstream-helper.h
+ * @file fstream-accessors.h
* @author Marek Smolinski (m.smolinski@samsung.com)
* @version 1.0
- * @brief This file is the implementation file of fstream-helper
+ * @brief This file is the implementation file of fstream-accessors
*
*/
#ifndef CENT_KEY_FSTREAM_ACCESSORS_H
#define CENT_KEY_FSTREAM_ACCESSORS_H
-namespace DPL {
+namespace CKM {
/*
* Bypass lack of public member function to get file
}
};
-} // namespace DPL
+} // namespace CKM
#endif // CENT_KEY_FSTREAM_ACCESSORS_H
#include <stdexcept>
#include <dpl/errno_string.h>
+#include <dpl/fstream_accessors.h>
#include <dpl/log/log.h>
#include <file-system.h>
}
bool FileSystem::saveFile(const std::string &path, const RawBuffer &buffer) const {
- std::ofstream os(path, std::ios::out | std::ofstream::binary);
+ std::ofstream os(path, std::ios::out | std::ofstream::binary | std::ofstream::trunc);
std::copy(buffer.begin(), buffer.end(), std::ostreambuf_iterator<char>(os));
+ if (os.fail())
+ return false;
+
+ // Prevent desynchronization in batter remove test.
+ os.flush();
+ fsync(FstreamAccessors<std::ofstream>::GetFd(os)); // flush kernel space buffer
+ os.close();
return !os.fail();
}