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_
8 #include <boost/filesystem.hpp>
9 #include <boost/filesystem/path.hpp>
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 boost::filesystem::path& path, uid_t uid, gid_t gid);
26 bool SetOwnershipAll(const boost::filesystem::path& path, uid_t uid, gid_t gid);
28 bool CreateDir(const boost::filesystem::path& path);
30 bool CopyDir(const boost::filesystem::path& src,
31 const boost::filesystem::path& dst,
32 FSFlag flags = FS_NONE, bool skip_symlink = false);
34 bool CopyFile(const boost::filesystem::path& src,
35 const boost::filesystem::path& dst);
37 bool RestoreBackup(const boost::filesystem::path& path);
39 bool MakeBackup(const boost::filesystem::path& path);
41 bool RemoveBackup(const boost::filesystem::path& path);
43 bool RemoveAll(const boost::filesystem::path& path);
45 bool Remove(const boost::filesystem::path& path);
47 bool MoveDir(const boost::filesystem::path& src,
48 const boost::filesystem::path& dst, FSFlag flags = FS_NONE);
50 bool MoveFile(const boost::filesystem::path& src,
51 const boost::filesystem::path& dst, bool force = false);
53 bool BackupDir(const boost::filesystem::path& src,
54 const boost::filesystem::path& dst, const std::string& entry);
56 bool SetDirPermissions(const boost::filesystem::path& path,
57 boost::filesystem::perms permissions);
59 bool SetDirOwnershipAndPermissions(const boost::filesystem::path& path,
60 boost::filesystem::perms permissions, uid_t uid,
63 bool CopyOwnershipAndPermissions(const boost::filesystem::path& src,
64 const boost::filesystem::path& dst);
66 int64_t GetUnpackedPackageSize(const boost::filesystem::path& path);
68 int64_t GetDirectorySize(const boost::filesystem::path& path);
70 bool CheckFreeSpaceAtPath(int64_t required_size,
71 const boost::filesystem::path& target_location);
73 boost::filesystem::path GenerateTmpDir(const boost::filesystem::path& app_path);
75 boost::filesystem::path GenerateTemporaryPath(
76 const boost::filesystem::path& path);
78 bool ExtractToTmpDir(const char* zip_path,
79 const boost::filesystem::path& tmp_dir);
81 bool ExtractToTmpDir(const char* zip_path,
82 const boost::filesystem::path& tmp_dir,
83 const std::string& filter_prefix);
85 bool CheckPathInZipArchive(const char* zip_archive_path,
86 const boost::filesystem::path& relative_zip_path,
89 bool HasDirectoryClimbing(const boost::filesystem::path& path);
91 boost::filesystem::path MakeRelativePath(const boost::filesystem::path& input,
92 const boost::filesystem::path& base);
94 bool IsSubDir(const boost::filesystem::path& path,
95 const boost::filesystem::path& root);
97 boost::filesystem::path RelativePath(const boost::filesystem::path& from,
98 const boost::filesystem::path& to);
100 } // namespace common_installer
102 #endif // COMMON_UTILS_FILE_UTIL_H_