+16 -12 +/-1 browse
1 | diff --git a/core/src/db.rs b/core/src/db.rs |
2 | index 2f400bc..7a9b63e 100644 |
3 | --- a/core/src/db.rs |
4 | +++ b/core/src/db.rs |
5 | @@ -253,20 +253,24 @@ impl Connection { |
6 | } |
7 | |
8 | /// Loads archive databases from [`Configuration::data_path`], if any. |
9 | - pub fn load_archives(&self) -> Result<()> { |
10 | - let mut stmt = self.connection.prepare("ATTACH ? AS ?;")?; |
11 | - for archive in std::fs::read_dir(&self.conf.data_path)? { |
12 | - let archive = archive?; |
13 | - let path = archive.path(); |
14 | - let name = path.file_name().unwrap_or_default(); |
15 | - if path == self.conf.db_path { |
16 | - continue; |
17 | + pub fn load_archives(&mut self) -> Result<()> { |
18 | + let tx = self.connection.transaction()?; |
19 | + { |
20 | + let mut stmt = tx.prepare("ATTACH ? AS ?;")?; |
21 | + for archive in std::fs::read_dir(&self.conf.data_path)? { |
22 | + let archive = archive?; |
23 | + let path = archive.path(); |
24 | + let name = path.file_name().unwrap_or_default(); |
25 | + if path == self.conf.db_path { |
26 | + continue; |
27 | + } |
28 | + stmt.execute(rusqlite::params![ |
29 | + path.to_str().unwrap(), |
30 | + name.to_str().unwrap() |
31 | + ])?; |
32 | } |
33 | - stmt.execute(rusqlite::params![ |
34 | - path.to_str().unwrap(), |
35 | - name.to_str().unwrap() |
36 | - ])?; |
37 | } |
38 | + tx.commit()?; |
39 | |
40 | Ok(()) |
41 | } |