Remove boost dependency
[platform/core/appfw/app-installers.git] / src / common / external_storage.h
1 // Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
2 // Use of this source code is governed by an apache-2.0 license that can be
3 // found in the LICENSE file.
4
5 #ifndef COMMON_EXTERNAL_STORAGE_H_
6 #define COMMON_EXTERNAL_STORAGE_H_
7
8 #include <sys/types.h>
9
10 #include <filesystem>
11 #include <memory>
12 #include <string>
13 #include <vector>
14
15 #include "common/app2ext_dynamic_service.h"
16 #include "common/utils/request.h"
17
18 namespace common_installer {
19
20 /**
21  * @brief The ExternalStorage class
22  *        Encapsulates mounting package in external memory for performing
23  *        installation request.
24  */
25 class ExternalStorage final {
26  public:
27   static std::unique_ptr<ExternalStorage> MoveInstalledStorage(
28       RequestType type, const std::filesystem::path& application_root,
29       const std::string& pkgid, const std::string& package_type,
30       uid_t uid, bool is_external_move);
31
32   static std::unique_ptr<ExternalStorage> AcquireExternalStorage(
33       RequestType type, const std::filesystem::path& application_root,
34       const std::string& pkgid, const std::string& package_type,
35       const std::filesystem::path& space_requirement, uid_t uid);
36
37   static std::unique_ptr<ExternalStorage> MigrateExternalStorage(
38       RequestType type, const std::string& pkgid, uid_t uid);
39
40   ExternalStorage(RequestType type, const std::string& pkgid,
41                   const std::string& package_type,
42                   const std::filesystem::path& application_root, uid_t uid);
43
44   ExternalStorage(RequestType type, const std::string& pkgid,
45                   const std::string& package_type,
46                   const std::filesystem::path& application_root, uid_t uid,
47                   bool is_external_move);
48   ExternalStorage(RequestType type, const std::string& pkgid, uid_t uid);
49   ~ExternalStorage();
50
51   bool Commit();
52   bool Abort();
53
54   const std::vector<std::string>& external_dirs() const;
55
56  private:
57   App2ExtDynamicService service;
58
59   bool Initialize(const std::filesystem::path& space_requirement);
60   bool Finalize(bool success);
61
62   RequestType type_;
63   std::string pkgid_;
64   std::string package_type_;
65   std::filesystem::path application_root_;
66   uid_t uid_;
67   int move_type_;
68   std::shared_ptr<app2ext_handle> handle_;
69   std::vector<std::string> external_dirs_;
70 };
71
72 }  // namespace common_installer
73
74 #endif  // COMMON_EXTERNAL_STORAGE_H_