Skip to content

Commit 4bd25a1

Browse files
output message for skipped upload; fix database behaviour
1 parent 89bf631 commit 4bd25a1

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

src/sub_commands/import.rs

+16-12
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ fn import_pack(pack: &String, config: &Config, opt: &Opt) -> anyhow::Result<()>
193193
}
194194

195195
let mut sticker = None;
196-
if !opt.noupload && database.is_some() {
196+
if !opt.noupload {
197197
let mut hasher = Sha512::new();
198198
hasher.update(&sticker_image);
199199
let hash = hasher.finalize();
@@ -208,6 +208,11 @@ fn import_pack(pack: &String, config: &Config, opt: &Opt) -> anyhow::Result<()>
208208
);
209209

210210
let mxc_url = if let Some(value) = database_tree.get(&hash) {
211+
pb.println(format!(
212+
" upload sticker {:02} {} skipped; file with this hash was already uploaded",
213+
i + 1,
214+
tg_sticker.emoji
215+
));
211216
value.clone()
212217
} else {
213218
pb.println(format!(" upload sticker {:02} {}", i + 1, tg_sticker.emoji));
@@ -242,17 +247,16 @@ fn import_pack(pack: &String, config: &Config, opt: &Opt) -> anyhow::Result<()>
242247
pb.finish();
243248

244249
// write new entries into the database
245-
for sticker in &stickers {
246-
let db = database.as_mut().unwrap();
247-
let hash_url = HashUrl {
248-
hash: sticker.file_hash,
249-
url: sticker.mxc_url.clone()
250-
};
251-
writeln!(db, "{}", serde_json::to_string(&hash_url)?)?;
252-
// TODO write into database_tree
253-
}
254-
if database.is_some() {
255-
database.unwrap().sync_data()?;
250+
if let Some(ref mut db) = database {
251+
for sticker in &stickers {
252+
let hash_url = HashUrl {
253+
hash: sticker.file_hash,
254+
url: sticker.mxc_url.clone()
255+
};
256+
writeln!(db, "{}", serde_json::to_string(&hash_url)?)?;
257+
// TODO write into database_tree
258+
}
259+
db.sync_data()?;
256260
}
257261

258262
// save the stickerpack to file

0 commit comments

Comments
 (0)