Coverage / crates/oxy-core/src/durable.rs 93.4%
99 of 106 lines run, 31 of 37 functions · run #279 on switch-says · run missed
| 1 | //! Durable file updates (spec §13.6): every write that must survive a | |
| 2 | //! crash goes through here. | |
| 3 | //! | |
| 4 | //! A file is replaced by writing a uniquely named temporary file in the | |
| 5 | //! same directory, syncing it, renaming it over the target, and syncing | |
| 6 | //! the directory so the rename itself is on disk. A crash at any point | |
| 7 | //! leaves either the old file or the new one, never a torn one; at worst | |
| 8 | //! a stray temporary file, which nothing reads. | |
| 9 | //! | |
| 10 | //! In tests, `crash_after(n)` makes the n-th durable step on the current | |
| 11 | //! thread fail as if the process had died there, so a test can stop an | |
| 12 | //! operation at every step and check what is left behind. | |
| 13 | | |
| 14 | use RngCore; | |
| 15 | use fs; | |
| 16 | use ; | |
| 17 | use Path; | |
| 18 | ||
| 19 | /// Replace `path` with `data`, atomically and durably. | |
| 20 | 6837× | |
| 21 | 6837× | |
| 22 | 6837× | |
| 23 | ||
| 24 | /// [`write_atomic`] for a secret: on Unix the file is created readable by | |
| 25 | /// its owner only, so the secret is never on disk with wider permissions. | |
| 26 | 64× | |
| 27 | 64× | |
| 28 | 64× | |
| 29 | ||
| 30 | 6901× | |
| 31 | 6901× | |
| 32 | 6901× | |
| 33 | 6901× | |
| 34 | 6901× | |
| 35 | 6901× | |
| 36 | 6901× | |
| 37 | 6901× | |
| 38 | 6901× | |
| 39 | 6901× | |
| 40 | 6896× | |
| 41 | 6896× | |
| 42 | 6896× | |
| 43 | | |
| 44 | 6896× | |
| 45 | | |
| 46 | 64× | |
| 47 | 6832× | |
| 48 | | |
| 49 | | |
| 50 | 6896× | |
| 51 | 6894× | |
| 52 | 6894× | |
| 53 | 6894× | |
| 54 | 6889× | |
| 55 | | |
| 56 | 6896× | |
| 57 | 7× | |
| 58 | 2× | |
| 59 | 5× | |
| 60 | 7× | |
| 61 | 6889× | |
| 62 | 6889× | |
| 63 | 6901× | |
| 64 | ||
| 65 | /// `e`, naming what failed and on which file, so a failure deep in a | |
| 66 | /// command says where it happened (an injected test crash stays as is). | |
| 67 | /// The kind is kept for callers that test it. | |
| 68 | 8× | |
| 69 | 8× | |
| 70 | 5× | |
| 71 | 3× | |
| 72 | 3× | |
| 73 | 8× | |
| 74 | ||
| 75 | /// Rename `from` to `to` and make the rename durable. | |
| 76 | 1× | |
| 77 | 1× | |
| 78 | 1× | |
| 79 | 0× | |
| 80 | 1× | |
| 81 | ||
| 82 | /// Flush a directory's entries (new, renamed or removed files) to disk. | |
| 83 | /// A no-op where directories cannot be opened for syncing. | |
| 84 | 29064× | |
| 85 | | |
| 86 | | |
| 87 | 29064× | |
| 88 | | |
| 89 | | |
| 90 | | |
| 91 | | |
| 92 | | |
| 93 | | |
| 94 | 29064× | |
| 95 | ||
| 96 | /// A point where a crash may happen. Outside tests it does nothing. | |
| 97 | 23217× | |
| 98 | | |
| 99 | | |
| 100 | 13424× | |
| 101 | | |
| 102 | | |
| 103 | | |
| 104 | 9793× | |
| 105 | 9793× | |
| 106 | | |
| 107 | 23217× | |
| 108 | ||
| 109 | const INJECTED: &str = "injected crash"; | |
| 110 | ||
| 111 | 15× | |
| 112 | 15× | |
| 113 | 15× | |
| 114 | ||
| 115 | | |
| 116 | pub | |
| 117 | | |
| 118 | | |
| 119 | | |
| 120 | | |
| 121 | | |
| 122 | | |
| 123 | | |
| 124 | | |
| 125 | | |
| 126 | | |
| 127 | 21× | |
| 128 | 21× | |
| 129 | 21× | |
| 130 | 21× | |
| 131 | | |
| 132 | | |
| 133 | 21× | |
| 134 | 21× | |
| 135 | 21× | |
| 136 | 21× | |
| 137 | | |
| 138 | 13424× | |
| 139 | 13424× | |
| 140 | 0× | |
| 141 | 0× | |
| 142 | 0× | |
| 143 | 0× | |
| 144 | 13424× | |
| 145 | 13424× | |
| 146 | | |
| 147 | 19× | |
| 148 | 19× | |
| 149 | 19× | |
| 150 | | |
| 151 | 130× | |
| 152 | 130× | |
| 153 | 130× | |
| 154 | | |
| 155 | 13275× | |
| 156 | 13424× | |
| 157 | 13424× | |
| 158 | | |
| 159 | ||
| 160 | | |
| 161 | | |
| 162 | | |
| 163 | | |
| 164 | | |
| 165 | 1× | |
| 166 | 1× | |
| 167 | 1× | |
| 168 | 1× | |
| 169 | 1× | |
| 170 | 1× | |
| 171 | 1× | |
| 172 | 1× | |
| 173 | | |
| 174 | | |
| 175 | 1× | |
| 176 | 1× | |
| 177 | 1× | |
| 178 | 1× | |
| 179 | | |
| 180 | | |
| 181 | 1× | |
| 182 | |