Renames a file stored with an `old` key to a `new` key.
(&self, old: &Key, new: &Key)
| 177 | |
| 178 | /// Renames a file stored with an `old` key to a `new` key. |
| 179 | fn rename(&self, old: &Key, new: &Key) -> io::Result<()> { |
| 180 | let old = old.serialized(); |
| 181 | let new = new.serialized(); |
| 182 | |
| 183 | let raw = match self.storage.get(old) { |
| 184 | Ok(Some(content)) => content, |
| 185 | Ok(None) => return Err(io::Error::new(io::ErrorKind::NotFound, "File not found")), |
| 186 | Err(e) => { |
| 187 | return Err(io::Error::other(format!( |
| 188 | "Failed to get local storage entry with key {}: {:?}", |
| 189 | old, e |
| 190 | ))); |
| 191 | } |
| 192 | }; |
| 193 | |
| 194 | if let Err(e) = self.storage.set(new, &raw) { |
| 195 | return Err(io::Error::other(format!( |
| 196 | "Failed to put local storage entry with key {}: {:?}", |
| 197 | new, e |
| 198 | ))); |
| 199 | }; |
| 200 | |
| 201 | if let Err(e) = self.storage.delete(old) { |
| 202 | return Err(io::Error::other(format!( |
| 203 | "Failed to put remove storage entry with key {}: {:?}", |
| 204 | old, e |
| 205 | ))); |
| 206 | }; |
| 207 | |
| 208 | Ok(()) |
| 209 | } |
| 210 | |
| 211 | /// Obtains and parses the entry given by `key`. |
| 212 | fn get_entry(&self, key: &Key) -> io::Result<Entry> { |
no test coverage detected