| 110 | } |
| 111 | |
| 112 | void Corrupt(FileType filetype, int offset, int bytes_to_corrupt) { |
| 113 | // Pick file to corrupt |
| 114 | std::vector<std::string> filenames; |
| 115 | ASSERT_OK(env_.target()->GetChildren(dbname_, &filenames)); |
| 116 | uint64_t number; |
| 117 | FileType type; |
| 118 | std::string fname; |
| 119 | int picked_number = -1; |
| 120 | for (size_t i = 0; i < filenames.size(); i++) { |
| 121 | if (ParseFileName(filenames[i], &number, &type) && type == filetype && |
| 122 | int(number) > picked_number) { // Pick latest file |
| 123 | fname = dbname_ + "/" + filenames[i]; |
| 124 | picked_number = number; |
| 125 | } |
| 126 | } |
| 127 | ASSERT_TRUE(!fname.empty()) << filetype; |
| 128 | |
| 129 | uint64_t file_size; |
| 130 | ASSERT_OK(env_.target()->GetFileSize(fname, &file_size)); |
| 131 | |
| 132 | if (offset < 0) { |
| 133 | // Relative to end of file; make it absolute |
| 134 | if (-offset > file_size) { |
| 135 | offset = 0; |
| 136 | } else { |
| 137 | offset = file_size + offset; |
| 138 | } |
| 139 | } |
| 140 | if (offset > file_size) { |
| 141 | offset = file_size; |
| 142 | } |
| 143 | if (offset + bytes_to_corrupt > file_size) { |
| 144 | bytes_to_corrupt = file_size - offset; |
| 145 | } |
| 146 | |
| 147 | // Do it |
| 148 | std::string contents; |
| 149 | Status s = ReadFileToString(env_.target(), fname, &contents); |
| 150 | ASSERT_TRUE(s.ok()) << s.ToString(); |
| 151 | for (int i = 0; i < bytes_to_corrupt; i++) { |
| 152 | contents[i + offset] ^= 0x80; |
| 153 | } |
| 154 | s = WriteStringToFile(env_.target(), contents, fname); |
| 155 | ASSERT_TRUE(s.ok()) << s.ToString(); |
| 156 | } |
| 157 | |
| 158 | int Property(const std::string& name) { |
| 159 | std::string property; |
nothing calls this directly
no test coverage detected