[Filesystem] Fixed errno issue found by Coverity system 76/180176/1
authorPiotr Kosko <p.kosko@samsung.com>
Fri, 25 May 2018 08:26:20 +0000 (10:26 +0200)
committerPiotr Kosko <p.kosko@samsung.com>
Fri, 25 May 2018 08:27:12 +0000 (10:27 +0200)
[Bug] Coverity issue 835432
  Documentation of nftw() function says that the result can be -1,
  which is not valid error code for system_error constructor. To
  resolve such problem, the -1 value is translated to IOError code.

[Verification] Code compiles without errors.
  TCT passrate of filesystem module is 100%.

Change-Id: I92805294270b4969fd545a413c03c565fdef7afd
Signed-off-by: Piotr Kosko <p.kosko@samsung.com>
src/filesystem/filesystem_utils.cc

index 3ab4dd3..f56cab7 100644 (file)
@@ -234,6 +234,11 @@ void RemoveDirectoryRecursively(const std::string& path) {
            128, FTW_DEPTH | FTW_PHYS);
 
   if (res) {
+    if (-1 == res) {
+      // -1 can be returned by nftw() function, to prevent invalid translation of error in
+      // std::system_error constructor, such situation will be treated as generic IOError
+      res = EIO;
+    }
     throw std::system_error{res, std::generic_category(),
                             "Failed to remove directory recursively: "s + std::strerror(res)};
   }