21#ifndef CYBER_COMMON_FILE_H_
22#define CYBER_COMMON_FILE_H_
35#include "google/protobuf/io/zero_copy_stream_impl.h"
36#include "google/protobuf/text_format.h"
51bool SetProtoToASCIIFile(
const google::protobuf::Message &message,
60bool SetProtoToASCIIFile(
const google::protobuf::Message &message,
61 const std::string &file_name);
70bool SetStringToASCIIFile(
const std::string &content,
71 const std::string &file_name);
81bool GetProtoFromASCIIFile(
const std::string &file_name,
82 google::protobuf::Message *message);
92 const std::string &file_name);
103 google::protobuf::Message *message);
113bool GetProtoFromFile(
const std::string &file_name,
114 google::protobuf::Message *message);
125 google::protobuf::Message *message);
133bool GetContent(
const std::string &file_name, std::string *content);
139std::string GetAbsolutePath(
const std::string &prefix,
140 const std::string &relative_path);
147bool PathExists(
const std::string &path);
158bool DirectoryExists(
const std::string &directory_path);
165std::vector<std::string>
Glob(
const std::string &pattern);
173bool CopyFile(
const std::string &from,
const std::string &to);
181bool CopyDir(
const std::string &from,
const std::string &to);
189bool Copy(
const std::string &from,
const std::string &to);
197bool EnsureDirectory(
const std::string &directory_path);
205bool RemoveAllFiles(
const std::string &directory_path);
213std::vector<std::string>
ListSubPaths(
const std::string &directory_path,
214 const unsigned char d_type = DT_DIR);
226 const unsigned char d_type,
const bool recursive,
227 std::vector<std::string> *result_list);
234std::string
GetDirName(
const std::string &path);
236std::string GetFileName(
const std::string &path,
237 const bool remove_extension =
false);
253 std::string *file_path);
265bool LoadConfig(
const std::string &relative_path, T *config) {
266 CHECK_NOTNULL(config);
268 std::string actual_config_path;
270 &actual_config_path)) {
271 AERROR <<
"conf file [" << relative_path
272 <<
"] is not found in APOLLO_CONF_PATH";
275 AINFO <<
"load conf file: " << actual_config_path;
bool DeleteFile(const string &filename)
std::vector< std::string > Glob(const std::string &pattern)
Expand path pattern to matched paths.
size_t FindPathByPattern(const std::string &base_path, const std::string &patt, const unsigned char d_type, const bool recursive, std::vector< std::string > *result_list)
Find path with pattern
bool CopyFile(const std::string &from, const std::string &to)
Copy a file.
bool CreateDir(const string &dir)
bool GetType(const string &filename, FileType *type)
bool GetProtoFromFile(const std::string &file_name, google::protobuf::Message *message)
Parses the content of the file specified by the file_name as a representation of protobufs,...
std::string GetDirName(const std::string &path)
get directory name of path
bool CopyDir(const std::string &from, const std::string &to)
Copy a directory.
std::string GetCurrentPath()
bool GetFilePathWithEnv(const std::string &path, const std::string &env_var, std::string *file_path)
get file path, judgement priority:
bool Copy(const std::string &from, const std::string &to)
Copy a file or directory.
bool SetProtoToBinaryFile(const google::protobuf::Message &message, const std::string &file_name)
Sets the content of the file specified by the file_name to be the binary representation of the input ...
bool GetProtoFromJsonFile(const std::string &file_name, google::protobuf::Message *message)
Parses the content of the json file specified by the file_name as ascii representation of protobufs,...
bool LoadConfig(const std::string &relative_path, T *config)
bool PathIsAbsolute(const std::string &path)
bool GetProtoFromBinaryFile(const std::string &file_name, google::protobuf::Message *message)
Parses the content of the file specified by the file_name as binary representation of protobufs,...
bool GetContent(const std::string &file_name, std::string *content)
Get file content as string.
std::vector< std::string > ListSubPaths(const std::string &directory_path, const unsigned char d_type)
List sub-paths.