File indexing completed on 2025-01-31 10:12:04
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef GOOGLE_PROTOBUF_TESTING_FILE_H__
0012 #define GOOGLE_PROTOBUF_TESTING_FILE_H__
0013
0014 #include "absl/status/status.h"
0015 #include "absl/strings/string_view.h"
0016 #include "google/protobuf/stubs/common.h"
0017
0018 namespace google {
0019 namespace protobuf {
0020
0021 const int DEFAULT_FILE_MODE = 0777;
0022
0023
0024
0025 class File {
0026 public:
0027 File(const File&) = delete;
0028 File& operator=(const File&) = delete;
0029
0030
0031 static bool Exists(const std::string& name);
0032
0033
0034
0035 static absl::Status ReadFileToString(const std::string& name,
0036 std::string* output,
0037 bool text_mode = false);
0038
0039
0040 static void ReadFileToStringOrDie(const std::string& name,
0041 std::string* output);
0042
0043
0044 static absl::Status WriteStringToFile(absl::string_view contents,
0045 const std::string& name);
0046
0047
0048 static void WriteStringToFileOrDie(absl::string_view contents,
0049 const std::string& name);
0050
0051
0052 static absl::Status CreateDir(const std::string& name, int mode);
0053
0054
0055 static absl::Status RecursivelyCreateDir(const std::string& path, int mode);
0056
0057
0058
0059
0060
0061
0062 static void DeleteRecursively(const std::string& name, void* dummy1,
0063 void* dummy2);
0064
0065
0066 static bool ChangeWorkingDirectory(const std::string& new_working_directory);
0067
0068 static absl::Status GetContents(const std::string& name, std::string* output,
0069 bool ) {
0070 return ReadFileToString(name, output);
0071 }
0072
0073 static absl::Status GetContentsAsText(const std::string& name,
0074 std::string* output,
0075 bool ) {
0076 return ReadFileToString(name, output, true);
0077 }
0078
0079 static absl::Status SetContents(const std::string& name,
0080 absl::string_view contents,
0081 bool ) {
0082 return WriteStringToFile(contents, name);
0083 }
0084 };
0085
0086 }
0087 }
0088
0089 #endif