diff options
author | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2019-09-27 22:38:10 +0300 |
---|---|---|
committer | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2019-09-27 22:38:10 +0300 |
commit | 5a262f3ffc2c28c79c41cc382c7a4e29bfd07f54 (patch) | |
tree | 5870a7d1191cfad6589abd64dfda12aa2eb20783 | |
parent | 250129665b0a74d0946cbfd39d3dcc36e62a67d4 (diff) |
maildir: check for moved mail before moving
When moving mail from new/ to cur/ in a Maildir folder, don't panic if
it fails; someone else must have moved it.
-rw-r--r-- | melib/src/backends/maildir/backend.rs | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/melib/src/backends/maildir/backend.rs b/melib/src/backends/maildir/backend.rs index ae6984f9..6ac0e62d 100644 --- a/melib/src/backends/maildir/backend.rs +++ b/melib/src/backends/maildir/backend.rs @@ -165,7 +165,7 @@ pub(super) fn get_file_hash(file: &Path) -> EnvelopeHash { hasher.finish() } -fn move_to_cur(p: PathBuf) -> PathBuf { +fn move_to_cur(p: PathBuf) -> Result<PathBuf> { let mut new = p.clone(); let file_name = p.to_string_lossy(); let slash_pos = file_name.bytes().rposition(|c| c == b'/').unwrap() + 1; @@ -178,8 +178,8 @@ fn move_to_cur(p: PathBuf) -> PathBuf { new.set_extension(":2,"); } debug!("moved to cur: {}", new.display()); - fs::rename(&p, &new).unwrap(); - new + fs::rename(&p, &new)?; + Ok(new) } impl MailBackend for MaildirType { @@ -229,7 +229,15 @@ impl MailBackend for MaildirType { if path_is_new!(pathbuf) { debug!("path_is_new"); /* This creates a Rename event that we will receive later */ - pathbuf = move_to_cur(pathbuf); + pathbuf = match move_to_cur(pathbuf) { + Ok(p) => p, + Err(e) => { + debug!("error: {}", e.to_string()); + continue; + } + }; + + } let folder_hash = get_path_hash!(pathbuf); let file_name = pathbuf @@ -696,7 +704,7 @@ impl MaildirType { path.push("new"); for d in path.read_dir()? { if let Ok(p) = d { - move_to_cur(p.path()); + move_to_cur(p.path()).ok().take(); } } path.pop(); |