1 /* 2014, Copyright © Intel Coporation, license APACHE-2.0, see LICENSE file */
3 #ifndef COMMON_UTILS_FILE_UTIL_H_
4 #define COMMON_UTILS_FILE_UTIL_H_
12 namespace common_installer {
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)
22 FSFlag operator|(FSFlag a, FSFlag b);
24 bool SetOwnership(const std::filesystem::path& path, uid_t uid, gid_t gid);
26 bool SetOwnershipAll(const std::filesystem::path& path, uid_t uid, gid_t gid);
28 bool CreateDir(const std::filesystem::path& path);
30 bool CopyDir(const std::filesystem::path& src,
31 const std::filesystem::path& dst,
32 FSFlag flags = FS_NONE, bool skip_symlink = false);
34 bool CopyFile(const std::filesystem::path& src,
35 const std::filesystem::path& dst);
37 bool RestoreBackup(const std::filesystem::path& path);
39 bool MakeBackup(const std::filesystem::path& path);
41 bool RemoveBackup(const std::filesystem::path& path);
43 bool RemoveAll(const std::filesystem::path& path);
45 bool Remove(const std::filesystem::path& path);
47 bool MoveDir(const std::filesystem::path& src,
48 const std::filesystem::path& dst, FSFlag flags = FS_NONE);
50 bool MoveFile(const std::filesystem::path& src,
51 const std::filesystem::path& dst, bool force = false);
53 bool BackupDir(const std::filesystem::path& src,
54 const std::filesystem::path& dst, const std::string& entry);
56 bool SetDirPermissions(const std::filesystem::path& path,
57 std::filesystem::perms permissions,
58 bool add_perms = false);
60 bool SetDirOwnershipAndPermissions(const std::filesystem::path& path,
61 std::filesystem::perms permissions, uid_t uid,
64 bool CopyOwnershipAndPermissions(const std::filesystem::path& src,
65 const std::filesystem::path& dst);
67 int64_t GetUnpackedPackageSize(const std::filesystem::path& path);
69 int64_t GetDirectorySize(const std::filesystem::path& path);
71 bool CheckFreeSpaceAtPath(int64_t required_size,
72 const std::filesystem::path& target_location);
74 std::filesystem::path GenerateTmpDir(const std::filesystem::path& app_path);
76 std::filesystem::path GenerateTemporaryPath(
77 const std::filesystem::path& path);
79 bool ExtractToTmpDir(const char* zip_path,
80 const std::filesystem::path& tmp_dir);
82 bool ExtractToTmpDir(const char* zip_path,
83 const std::filesystem::path& tmp_dir,
84 const std::string& filter_prefix);
86 bool CheckPathInZipArchive(const char* zip_archive_path,
87 const std::filesystem::path& relative_zip_path,
90 bool HasDirectoryClimbing(const std::filesystem::path& path);
92 std::filesystem::path MakeRelativePath(const std::filesystem::path& input,
93 const std::filesystem::path& base);
95 bool IsSubDir(const std::filesystem::path& path,
96 const std::filesystem::path& root);
98 std::vector<std::string> GetDirectoryList(const std::filesystem::path& cwd);
100 std::filesystem::path GenerateUniquePathString(const std::string& format) ;
102 bool SyncFile(const std::filesystem::path& path);
104 } // namespace common_installer
106 #endif // COMMON_UTILS_FILE_UTIL_H_