From 5ddd78fbca6807164ff77cba980f322109ccffd4 Mon Sep 17 00:00:00 2001
From: Pawel Andruszkiewicz
Date: Wed, 20 May 2015 13:18:26 +0200
Subject: [PATCH] [Filesystem] Fix for TCT test. Resolve should report
InvalidValuesError if application does not have access to a file/directory.
[Verification] FileSystemManager_resolve_wgt_package_of_another_app passes.
Change-Id: I9ccc2dd0dea6775f769e8f9f2ad50a6427a0622a
Signed-off-by: Pawel Andruszkiewicz
---
src/filesystem/filesystem_instance.cc | 3 +++
src/filesystem/filesystem_manager.cc | 2 +-
src/filesystem/filesystem_stat.cc | 14 ++++++++++----
src/filesystem/filesystem_stat.h | 6 +++++-
src/filesystem/filesystem_utils.h | 1 +
5 files changed, 20 insertions(+), 6 deletions(-)
diff --git a/src/filesystem/filesystem_instance.cc b/src/filesystem/filesystem_instance.cc
index 3bc2de06..3a351735 100644
--- a/src/filesystem/filesystem_instance.cc
+++ b/src/filesystem/filesystem_instance.cc
@@ -597,6 +597,9 @@ void FilesystemInstance::PrepareError(const FilesystemError& error, picojson::ob
case FilesystemError::Other:
ReportError(UnknownException("PLATFORM ERROR"), out);
break;
+ case FilesystemError::InvalidValue:
+ ReportError(InvalidValuesException("PLATFORM ERROR"), out);
+ break;
default:
ReportError(UnknownException("PLATFORM ERROR"), out);
break;
diff --git a/src/filesystem/filesystem_manager.cc b/src/filesystem/filesystem_manager.cc
index 8fbe22d7..d3a3a16f 100644
--- a/src/filesystem/filesystem_manager.cc
+++ b/src/filesystem/filesystem_manager.cc
@@ -228,7 +228,7 @@ void FilesystemManager::StatPath(
FilesystemStat statData = FilesystemStat::getStat(path);
if (!statData.valid) {
- error_cb(FilesystemError::NotFound);
+ error_cb(statData.error);
return;
}
diff --git a/src/filesystem/filesystem_stat.cc b/src/filesystem/filesystem_stat.cc
index 90e7333c..ce919bf5 100644
--- a/src/filesystem/filesystem_stat.cc
+++ b/src/filesystem/filesystem_stat.cc
@@ -14,7 +14,7 @@
namespace extension {
namespace filesystem {
-FilesystemStat::FilesystemStat() : valid(false) {}
+FilesystemStat::FilesystemStat() : error(FilesystemError::None), valid(false) {}
picojson::value FilesystemStat::toJSON() const {
picojson::value retval = picojson::value(picojson::object());
@@ -34,14 +34,20 @@ picojson::value FilesystemStat::toJSON() const {
FilesystemStat FilesystemStat::getStat(const std::string& path) {
struct stat aStatObj;
+ FilesystemStat _result;
+
LoggerD("enter");
+
if (0 != stat(path.c_str(), &aStatObj)) {
LoggerE("Failed to stat: (%d) %s", errno, strerror(errno));
- return FilesystemStat();
+ if (ENOENT == errno) {
+ _result.error = FilesystemError::NotFound;
+ } else {
+ _result.error = FilesystemError::InvalidValue;
+ }
+ return _result;
}
- FilesystemStat _result;
-
_result.path = path;
_result.readOnly = true;
if (getuid() == aStatObj.st_uid && (aStatObj.st_mode & S_IWUSR) == S_IWUSR) {
diff --git a/src/filesystem/filesystem_stat.h b/src/filesystem/filesystem_stat.h
index 7358045f..0120e049 100644
--- a/src/filesystem/filesystem_stat.h
+++ b/src/filesystem/filesystem_stat.h
@@ -6,7 +6,10 @@
#define FILESYSTEM_FILESYSTEM_STAT_H
#include
-#include
+
+#include "common/picojson.h"
+
+#include "filesystem/filesystem_utils.h"
namespace extension {
namespace filesystem {
@@ -15,6 +18,7 @@ class FilesystemStat {
FilesystemStat();
public:
+ FilesystemError error;
bool valid;
std::string path;
diff --git a/src/filesystem/filesystem_utils.h b/src/filesystem/filesystem_utils.h
index 03750871..42d834f4 100644
--- a/src/filesystem/filesystem_utils.h
+++ b/src/filesystem/filesystem_utils.h
@@ -19,6 +19,7 @@ enum class FilesystemError {
DirectoryExists,
PermissionDenied,
IOError,
+ InvalidValue,
Other
};
} // namespace filesystem
--
2.34.1