From 9494ec4225bec23e43c5db73566c34e9350c3c1a 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 a4176310..d2154598 100755 --- a/src/filesystem/filesystem_instance.cc +++ b/src/filesystem/filesystem_instance.cc @@ -615,6 +615,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 3c5d997a..a9cdf9cc 100755 --- a/src/filesystem/filesystem_manager.cc +++ b/src/filesystem/filesystem_manager.cc @@ -243,7 +243,7 @@ void FilesystemManager::StatPath( LoggerD("enter"); 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 a407fcc1..520c12f5 100755 --- a/src/filesystem/filesystem_stat.cc +++ b/src/filesystem/filesystem_stat.cc @@ -26,7 +26,7 @@ namespace extension { namespace filesystem { -FilesystemStat::FilesystemStat() : valid(false) {} +FilesystemStat::FilesystemStat() : error(FilesystemError::None), valid(false) {} picojson::value FilesystemStat::toJSON() const { LoggerD("Enter"); @@ -48,14 +48,20 @@ picojson::value FilesystemStat::toJSON() const { FilesystemStat FilesystemStat::getStat(const std::string& path) { LoggerD("Enter"); 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 78f38521..62b78373 100755 --- a/src/filesystem/filesystem_stat.h +++ b/src/filesystem/filesystem_stat.h @@ -17,7 +17,10 @@ #define FILESYSTEM_FILESYSTEM_STAT_H #include -#include + +#include "common/picojson.h" + +#include "filesystem/filesystem_utils.h" namespace extension { namespace filesystem { @@ -26,6 +29,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 343bc5a9..3522c59c 100755 --- a/src/filesystem/filesystem_utils.h +++ b/src/filesystem/filesystem_utils.h @@ -31,6 +31,7 @@ enum class FilesystemError { DirectoryExists, PermissionDenied, IOError, + InvalidValue, Other }; } // namespace filesystem -- 2.34.1