summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyungwook Tak <k.tak@samsung.com>2017-01-31 14:23:00 +0900
committerKyungwook Tak <k.tak@samsung.com>2017-02-02 15:55:34 +0900
commitfd222dc14da5bf890ae42b6c5195f08be0b3253a (patch)
treee45d07b9fffa9d8c14219619d361d4042cca88d7
parent6f0940d3e4d099a06a147c76cf0411ccecc85e45 (diff)
downloadcsr-framework-tizen_3.0_tv.tar.gz
csr-framework-tizen_3.0_tv.tar.bz2
csr-framework-tizen_3.0_tv.zip
tizen branch head: 327e9ccafbb83370a88509885cb4480010bf745c 1. Add error handling for getting stat (cherry picked from commit 10dc9a7398e9c1e86edc3fe9089bf83a43b5ab20) 2. Make File::Type class to encapsulate filetype op (cherry picked from commit d52589e9d88c3d6399ddb7e493a944602125abd9) 3. Run set cap script after csr rpm installation (cherry picked from commit 327e9ccafbb83370a88509885cb4480010bf745c) Change-Id: I1eef203984229fc84c7ad513550b1fdaff9be850 Signed-off-by: Kyungwook Tak <k.tak@samsung.com>
-rw-r--r--packaging/csr-framework.spec5
-rw-r--r--src/framework/service/file-system.cpp58
-rw-r--r--src/framework/service/file-system.h139
3 files changed, 143 insertions, 59 deletions
diff --git a/packaging/csr-framework.spec b/packaging/csr-framework.spec
index 5325fdd..7f9f809 100644
--- a/packaging/csr-framework.spec
+++ b/packaging/csr-framework.spec
@@ -220,6 +220,11 @@ mkdir -p %{buildroot}%{engine_rw_working_dir}
%find_lang %{service_name}
%post
+set_cap_script=%{ro_data_dir}/security-config/set_capability
+if [ -f $set_cap_script ]; then
+ $set_cap_script
+fi
+
rm -f %{rw_db_dir}/.%{service_name}.db*
systemctl daemon-reload
diff --git a/src/framework/service/file-system.cpp b/src/framework/service/file-system.cpp
index c27f8f9..4d25271 100644
--- a/src/framework/service/file-system.cpp
+++ b/src/framework/service/file-system.cpp
@@ -39,7 +39,7 @@
namespace Csr {
-int File::getPkgTypes(const std::string &user, const std::string &pkgid)
+File::Type File::Type::get(const std::string &user, const std::string &pkgid)
{
pkgmgrinfo_pkginfo_h handle;
@@ -54,13 +54,15 @@ int File::getPkgTypes(const std::string &user, const std::string &pkgid)
auto ret = ::pkgmgrinfo_pkginfo_get_pkginfo(pkgid.c_str(), &handle);
#endif
+ Type type;
+
if (ret != PMINFO_R_OK) {
INFO("Extracted pkgid[" << pkgid << "] from filepath isn't pkg id. "
"It's not package.");
- return 0;
+ return type;
}
- auto type = static_cast<int>(Type::Package);
+ type.m_attributes.set(Attribute::Package);
bool isPreloaded = false;
ret = ::pkgmgrinfo_pkginfo_is_preload(handle, &isPreloaded);
@@ -69,10 +71,25 @@ int File::getPkgTypes(const std::string &user, const std::string &pkgid)
ERROR("Failed to ::pkgmgrinfo_pkginfo_is_preload: " << ret);
if (isPreloaded)
- type |= static_cast<int>(Type::PreLoaded);
+ type.m_attributes.set(Attribute::PreLoaded);
::pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+ return Type(type);
+}
+
+File::Type File::Type::get(const struct stat &s, time_t modifiedSince)
+{
+ Type type;
+
+ if (S_ISREG(s.st_mode))
+ type.m_attributes.set(Attribute::File);
+ else
+ type.m_attributes.set(Attribute::Directory);
+
+ if (modifiedSince == -1 || s.st_ctime > modifiedSince)
+ type.m_attributes.set(Attribute::Modified);
+
return type;
}
@@ -99,34 +116,27 @@ std::string File::getPkgPath(const std::string &path)
continue;
}
- auto type = File::getPkgTypes(pkgUser, pkgId);
-
- return ((type & static_cast<int>(Type::Package)) &&
- (!(type & static_cast<int>(Type::PreLoaded)))) ? pkgPath : path;
+ return Type::get(pkgUser, pkgId).isInApp() ? pkgPath : path;
}
return path;
}
-File::File(const std::string &fpath, const FilePtr &parentdir, int type,
+File::File(const std::string &fpath, const FilePtr &parentdir, const Type &type,
std::unique_ptr<struct stat> &&statptr) :
m_path(fpath), m_type(type), m_statptr(std::move(statptr))
{
if (parentdir != nullptr) {
- if (parentdir->isPackage()) {
+ if (parentdir->m_type.isPackage()) {
this->m_appPkgPath = parentdir->getAppPkgPath();
this->m_appPkgId = parentdir->getAppPkgId();
this->m_appUser = parentdir->getAppUser();
- this->m_type |= static_cast<int>(File::Type::Package);
-
- if (parentdir->isPreloaded())
- this->m_type |= static_cast<int>(File::Type::PreLoaded);
+ this->m_type.inheritParentType(parentdir->m_type);
return;
} else if (!this->isDir()) {
- this->m_type &= ~(static_cast<int>(File::Type::Package) |
- static_cast<int>(File::Type::PreLoaded));
+ this->m_type.unsetDirAttributes();
}
}
@@ -148,7 +158,7 @@ File::File(const std::string &fpath, const FilePtr &parentdir, int type,
continue;
}
- this->m_type |= File::getPkgTypes(this->m_appUser, this->m_appPkgId);
+ this->m_type |= Type::get(this->m_appUser, this->m_appPkgId);
break;
}
@@ -188,14 +198,9 @@ FilePtr File::createInternal(const std::string &fpath, const FilePtr &parentdir,
else if (!S_ISREG(statptr->st_mode) && !S_ISDIR(statptr->st_mode))
ThrowExc(CSR_ERROR_FILE_SYSTEM, "file type is not reguler or dir: " << fpath);
- auto type = static_cast<int>(S_ISREG(statptr->st_mode) ? Type::File : Type::Directory);
+ auto type = Type::get(*statptr, modifiedSince);
- if (modifiedSince == -1 || statptr->st_ctime > modifiedSince) {
- DEBUG("file[" << fpath << "] is changed since[" << modifiedSince << "]");
- type |= static_cast<int>(Type::Modified);
- }
-
- if (isModifiedOnly && !(type & static_cast<int>(Type::Modified)))
+ if (isModifiedOnly && !type.isModified())
return nullptr;
else
return FilePtr(new File(fpath, parentdir, type, std::move(statptr)));
@@ -270,6 +275,11 @@ void FsVisitor::run(const DirPtr &dirptr, const FilePtr &currentdir)
continue;
auto stat = getStat(fullpath);
+ if (stat == nullptr) {
+ WARN("Skip the file(" << fullpath << ") whose stat can't be retrieved");
+ continue;
+ }
+
if (S_ISREG(stat->st_mode))
this->visitFile(fullpath, currentdir);
else if (S_ISDIR(stat->st_mode))
diff --git a/src/framework/service/file-system.h b/src/framework/service/file-system.h
index d7a4580..993d20a 100644
--- a/src/framework/service/file-system.h
+++ b/src/framework/service/file-system.h
@@ -25,6 +25,7 @@
#include <memory>
#include <queue>
#include <functional>
+#include <bitset>
#include <cstddef>
#include <ctime>
@@ -40,36 +41,11 @@ class File {
public:
File() = delete;
- inline bool isInApp() const noexcept
- {
- return this->isPackage() && !this->isPreloaded();
- }
-
- inline bool isPackage() const noexcept
- {
- return this->m_type & static_cast<int>(Type::Package);
- }
-
- inline bool isPreloaded() const noexcept
- {
- return this->m_type & static_cast<int>(Type::PreLoaded);
- }
-
- inline bool isModified() const noexcept
- {
- return this->m_type & static_cast<int>(Type::Modified);
- }
-
inline bool isModifiedSince(time_t since) const noexcept
{
return this->m_statptr->st_ctime > since;
}
- inline bool isDir() const noexcept
- {
- return this->m_type & static_cast<int>(Type::Directory);
- }
-
inline const std::string &getName() const noexcept
{
return (this->isInApp()) ? this->m_appPkgPath : this->m_path;
@@ -95,6 +71,16 @@ public:
return this->m_appPkgPath;
}
+ inline bool isInApp() const noexcept
+ {
+ return this->m_type.isInApp();
+ }
+
+ inline bool isDir() const noexcept
+ {
+ return this->m_type.isDir();
+ }
+
void remove() const;
// throws FileNotExist and FileSystemError
@@ -106,23 +92,106 @@ public:
static std::string getPkgPath(const std::string &path);
private:
- enum class Type : int {
- Modified = (1 << 0),
- Package = (1 << 1),
- PreLoaded = (1 << 2),
- File = (1 << 3),
- Directory = (1 << 4)
+ class Type {
+ public:
+ inline Type &operator|=(const Type &other)
+ {
+ this->m_attributes |= other.m_attributes;
+ return *this;
+ }
+
+ inline bool isInApp() const noexcept
+ {
+ return Type::isInApp(this->m_attributes);
+ }
+
+ inline bool isPackage() const noexcept
+ {
+ return Type::isPackage(this->m_attributes);
+ }
+
+ inline bool isPreloaded() const noexcept
+ {
+ return Type::isPreloaded(this->m_attributes);
+ }
+
+ inline bool isModified() const noexcept
+ {
+ return Type::isModified(this->m_attributes);
+ }
+
+ inline bool isDir() const noexcept
+ {
+ return Type::isDir(this->m_attributes);
+ }
+
+ inline void unsetDirAttributes() noexcept
+ {
+ this->m_attributes.reset(Attribute::Package);
+ this->m_attributes.reset(Attribute::PreLoaded);
+ }
+
+ inline void inheritParentType(const Type &parent) noexcept
+ {
+ if (parent.isPackage())
+ this->m_attributes.set(Attribute::Package);
+ if (parent.isPreloaded())
+ this->m_attributes.set(Attribute::PreLoaded);
+ }
+
+ static Type get(const std::string &user, const std::string &pkgid);
+ static Type get(const struct stat &s, time_t modifiedSince);
+
+ private:
+ enum Attribute {
+ Modified = 0,
+ Package = 1,
+ PreLoaded = 2,
+ File = 3,
+ Directory = 4,
+ ENUM_COUNT = 5
+ };
+
+ using Attributes = std::bitset<static_cast<std::underlying_type<Attribute>::type>(Attribute::ENUM_COUNT)>;
+
+ static inline bool isInApp(const Attributes &attributes) noexcept
+ {
+ return isPackage(attributes) && !isPreloaded(attributes);
+ }
+
+ static inline bool isPackage(const Attributes &attributes) noexcept
+ {
+ return attributes[Attribute::Package];
+ }
+
+ static inline bool isPreloaded(const Attributes &attributes) noexcept
+ {
+ return attributes[Attribute::PreLoaded];
+ }
+
+ static inline bool isModified(const Attributes &attributes) noexcept
+ {
+ return attributes[Attribute::Modified];
+ }
+
+ static inline bool isDir(const Attributes &attributes) noexcept
+ {
+ return attributes[Attribute::Directory];
+ }
+
+ Type() {}
+
+ Attributes m_attributes;
};
static FilePtr createInternal(const std::string &fpath, const FilePtr &parentdir,
time_t modifiedSince, bool isModifiedOnly);
- static int getPkgTypes(const std::string &user, const std::string &pkgid);
- explicit File(const std::string &fpath, const FilePtr &parentdir, int type,
- std::unique_ptr<struct stat> &&statptr);
+ explicit File(const std::string &fpath, const FilePtr &parentdir,
+ const Type &type, std::unique_ptr<struct stat> &&statptr);
std::string m_path;
- int m_type;
+ Type m_type;
std::unique_ptr<struct stat> m_statptr;
std::string m_appPkgId; // meaningful only if inApp == true
std::string m_appUser; // meaningful only if inApp == true