/*
- * Copyright (c) 2014-2017 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2014-2020 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.
struct AppInstallHelper {
using TypePathsMap = std::map<app_install_path_type, std::vector<std::string>>;
+ using TypePathMap = std::map<app_install_path_type, std::string>;
+
AppInstallHelper(const std::string &appNamePrefix,
const std::string &pkgNamePrefix,
bool isLocal,
uid_t uid,
std::string version = std::string())
- : m_appName(appNamePrefix), m_pkgName(pkgNamePrefix), m_isLocal(isLocal), m_uidGid(uid), m_version(version),
- m_installType(SM_APP_INSTALL_NONE), m_isHybrid(false), m_isInstallDirCreated(false), m_creatorPid(getpid())
- {
- setInstallPath();
- }
+ : m_appName(appNamePrefix + "_app_id"), m_pkgName(pkgNamePrefix + "_pkg_id"), m_isLocal(isLocal), m_uidGid(uid), m_version(version),
+ m_installType(SM_APP_INSTALL_NONE), m_isHybrid(false), m_creatorPid(getpid())
+ {}
AppInstallHelper(const std::string &appNamePrefix,
const std::string &pkgNamePrefix,
AppInstallHelper(AppInstallHelper &&other);
// App info getters and setters
- std::string getAppId() const;
- std::string getPkgId() const;
+ const std::string& getAppId() const;
+ const std::string& getPkgId() const;
int getUID() const;
int getGID() const;
void setVersion(const std::string &version);
void setHybrid();
bool getIsHybrid() const;
+ enum RootType {
+ BASE,
+ SKEL,
+ EXTENDED,
+ SHARED,
+ SHARED_TMP
+ };
+
+ enum PathType {
+ FILE,
+ DIR
+ };
+
// Path types creation and removal on file system
- void createInstallDir();
- void createTrustedDir(int i = 0);
- void createPrivateDir(int i = 0);
- void createPublicDir();
- void createPrivateFile(int i = 0);
- void createSharedRODir(int i = 0);
- void createPrivateRODir(int i = 0);
+ void createPath(app_install_path_type smType, PathType pType, int i = 0, RootType rType = RootType::BASE);
+
+ // below methods are deprecated
+ void createTrustedDir(int i = 0, RootType type = RootType::BASE);
+ void createPrivateDir(int i = 0, RootType type = RootType::BASE);
+ void createPublicDir(RootType type = RootType::BASE);
+ void createPrivateFile(int i = 0, RootType type = RootType::BASE);
+ void createSharedRODir(int i = 0, RootType type = RootType::BASE);
+ void createSharedROFile(int i = 0, RootType type = RootType::BASE);
+ void createPrivateRODir(int i = 0, RootType type = RootType::BASE);
void removePaths();
// Path getters
- std::string getInstallDir() const;
- std::string getTrustedDir(int i = 0) const;
- std::string getPrivateDir(int i = 0) const;
- std::string getPrivateRODir(int i = 0) const;
- std::string getPublicDir() const;
- std::string getPrivatePath(int i = 0) const;
- std::string getSharedRODir(int i = 0) const;
+ std::string getPath(app_install_path_type smType, PathType pType, int i = 0, RootType rType = RootType::BASE) const;
+
+ // below methods are deprecated
+ std::string getInstallDir(RootType type) const;
+ std::string getTrustedDir(int i = 0, RootType type = RootType::BASE) const;
+ std::string getPrivateDir(int i = 0, RootType type = RootType::BASE) const;
+ std::string getPrivateRODir(int i = 0, RootType type = RootType::BASE) const;
+ std::string getPublicDir(RootType type = RootType::BASE) const;
+ std::string getPrivatePath(int i = 0, RootType type = RootType::BASE) const;
+ std::string getSharedRODir(int i = 0, RootType type = RootType::BASE) const;
+ std::string getSharedROPath(int i = 0, RootType type = RootType::BASE) const;
const TypePathsMap& getDirsMap() const;
const TypePathsMap& getFilesMap() const;
// Privileges
- std::vector<std::string> getPrivilegesNames() const; // deprecated
- void addPrivileges(const std::vector<std::string> &privileges); // deprecated
void addPrivilege(Privilege privilege);
void addPrivileges(const PrivilegeVector &privileges);
const PrivilegeVector& getPrivileges() const;
}
protected:
- void setInstallPath();
- bool create(std::function<int(const char*, mode_t)> &&creatFun, const std::string &path);
- std::string m_appName;
- std::string m_pkgName;
+ struct RootInfo {
+ RootInfo() : isCreated(false) {}
+ std::string path;
+ int isCreated;
+ };
+ using RootTypeInfoMap = std::map<RootType, RootInfo>;
+
+ void setInstallPath(RootType type) const;
+
+ bool createFile(app_install_path_type smType, const std::string &path);
+ bool createDir(app_install_path_type smType, const std::string &path, bool isBasePath = false);
+ void createDirLink(app_install_path_type smType, const std::string &dest, int i = 0,
+ RootType rType = RootType::BASE);
+ void createInstallDir(RootType type);
+
+ const std::string m_appName;
+ const std::string m_pkgName;
bool m_isLocal;
int m_uidGid;
std::string m_version;
app_install_type m_installType;
bool m_isHybrid;
- std::string m_installDir;
- bool m_isInstallDirCreated;
+
+ mutable RootTypeInfoMap m_rootPaths;
TypePathsMap m_dirTypeMap;
TypePathsMap m_fileTypeMap;
+
PrivilegeVector m_privileges;
PrivilegeVector m_appDefinedPrivileges;
+
std::string m_author;
pid_t m_creatorPid;