Remove boost dependency
[platform/core/appfw/app-installers.git] / src / common / utils / file_util.h
1 /* 2014, Copyright © Intel Coporation, license APACHE-2.0, see LICENSE file */
2
3 #ifndef COMMON_UTILS_FILE_UTIL_H_
4 #define COMMON_UTILS_FILE_UTIL_H_
5
6 #include <sys/types.h>
7
8 #include <filesystem>
9 #include <string>
10 #include <vector>
11
12 namespace common_installer {
13
14 enum FSFlag : int {
15   FS_NONE              = 0,
16   FS_MERGE_SKIP        = (1 << 0),
17   FS_MERGE_OVERWRITE   = (1 << 1),
18   FS_COMMIT_COPY_FILE  = (1 << 2),
19   FS_PRESERVE_OWNERSHIP_AND_PERMISSIONS = (1 << 3)
20 };
21
22 FSFlag operator|(FSFlag a, FSFlag b);
23
24 bool SetOwnership(const std::filesystem::path& path, uid_t uid, gid_t gid);
25
26 bool SetOwnershipAll(const std::filesystem::path& path, uid_t uid, gid_t gid);
27
28 bool CreateDir(const std::filesystem::path& path);
29
30 bool CopyDir(const std::filesystem::path& src,
31              const std::filesystem::path& dst,
32              FSFlag flags = FS_NONE, bool skip_symlink = false);
33
34 bool CopyFile(const std::filesystem::path& src,
35              const std::filesystem::path& dst);
36
37 bool RestoreBackup(const std::filesystem::path& path);
38
39 bool MakeBackup(const std::filesystem::path& path);
40
41 bool RemoveBackup(const std::filesystem::path& path);
42
43 bool RemoveAll(const std::filesystem::path& path);
44
45 bool Remove(const std::filesystem::path& path);
46
47 bool MoveDir(const std::filesystem::path& src,
48              const std::filesystem::path& dst, FSFlag flags = FS_NONE);
49
50 bool MoveFile(const std::filesystem::path& src,
51               const std::filesystem::path& dst, bool force = false);
52
53 bool BackupDir(const std::filesystem::path& src,
54     const std::filesystem::path& dst, const std::string& entry);
55
56 bool SetDirPermissions(const std::filesystem::path& path,
57                        std::filesystem::perms permissions,
58                        bool add_perms = false);
59
60 bool SetDirOwnershipAndPermissions(const std::filesystem::path& path,
61                       std::filesystem::perms permissions, uid_t uid,
62                       gid_t gid);
63
64 bool CopyOwnershipAndPermissions(const std::filesystem::path& src,
65                                  const std::filesystem::path& dst);
66
67 int64_t GetUnpackedPackageSize(const std::filesystem::path& path);
68
69 int64_t GetDirectorySize(const std::filesystem::path& path);
70
71 bool CheckFreeSpaceAtPath(int64_t required_size,
72     const std::filesystem::path& target_location);
73
74 std::filesystem::path GenerateTmpDir(const std::filesystem::path& app_path);
75
76 std::filesystem::path GenerateTemporaryPath(
77     const std::filesystem::path& path);
78
79 bool ExtractToTmpDir(const char* zip_path,
80                      const std::filesystem::path& tmp_dir);
81
82 bool ExtractToTmpDir(const char* zip_path,
83                      const std::filesystem::path& tmp_dir,
84                      const std::string& filter_prefix);
85
86 bool CheckPathInZipArchive(const char* zip_archive_path,
87                            const std::filesystem::path& relative_zip_path,
88                            bool* found);
89
90 bool HasDirectoryClimbing(const std::filesystem::path& path);
91
92 std::filesystem::path MakeRelativePath(const std::filesystem::path& input,
93                                          const std::filesystem::path& base);
94
95 bool IsSubDir(const std::filesystem::path& path,
96               const std::filesystem::path& root);
97
98 std::vector<std::string> GetDirectoryList(const std::filesystem::path& cwd);
99
100 std::filesystem::path GenerateUniquePathString(const std::string& format) ;
101
102 bool SyncFile(const std::filesystem::path& path);
103
104 }  // namespace common_installer
105
106 #endif  // COMMON_UTILS_FILE_UTIL_H_