summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/manager/service/file-system.cpp13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/manager/service/file-system.cpp b/src/manager/service/file-system.cpp
index 6a70c206..079a4cd8 100644
--- a/src/manager/service/file-system.cpp
+++ b/src/manager/service/file-system.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2000 - 2019 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -122,11 +122,18 @@ void FileSystem::saveFile(const std::string &path,
{
std::ofstream os(path, std::ios::out | std::ofstream::binary |
std::ofstream::trunc);
+
+ if (os.fail())
+ ThrowErr(Exc::FileSystemFailed, "Can't open file for writing: ", path);
+
std::copy(buffer.begin(), buffer.end(), std::ostreambuf_iterator<char>(os));
- // Prevent desynchronization in batter remove test.
+ // Prevent desynchronization in battery remove test.
os.flush();
- fsync(FstreamAccessors<std::ofstream>::GetFd(os)); // flush kernel space buffer
+ if (fsync(FstreamAccessors<std::ofstream>::GetFd(os)) != 0) { // flush kernel space buffer
+ auto desc = GetErrnoString(errno);
+ ThrowErr(Exc::FileSystemFailed, "Failed to sync file: ", path, " Reason: ", desc);
+ }
os.close();
if (os.fail())