MCPcopy Create free account
hub / github.com/ElementsProject/elements / Corrupt

Method Corrupt

src/leveldb/db/corruption_test.cc:112–156  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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;

Callers

nothing calls this directly

Calls 8

ParseFileNameFunction · 0.85
ReadFileToStringFunction · 0.85
WriteStringToFileFunction · 0.85
GetChildrenMethod · 0.45
sizeMethod · 0.45
emptyMethod · 0.45
GetFileSizeMethod · 0.45
ToStringMethod · 0.45

Tested by

no test coverage detected