Just because it's interesting to me.
Unified · Split
| @@ -45,8 +45,8 @@ quick_error! { · 44 unmodified lines | ||
| 45 | 45 | from() |
| 46 | 46 | source(err) |
| 47 | 47 | } |
| 48 | − PermanentlyLocked { resource_path: PathBuf, mode: Fail } { | |
| 49 | − display("The lock for resource '{} could not be obtained {}. The lockfile at '{}{}' might need manual deletion.", resource_path.display(), mode, resource_path.display(), super::DOT_SUFFIX) | |
| 48 | + PermanentlyLocked { resource_path: PathBuf, mode: Fail, attempts: usize } { | |
| 49 | + display("The lock for resource '{} could not be obtained {} after {} attempt(s). The lockfile at '{}{}' might need manual deletion.", resource_path.display(), mode, attempts, resource_path.display(), super::DOT_SUFFIX) | |
| 50 | 50 | } |
| 51 | 51 | } |
| 52 | 52 | } |
| @@ -107,10 +107,12 @@ fn lock_with_mode<T>( · 54 unmodified lines | ||
| 107 | 107 | use std::io::ErrorKind::*; |
| 108 | 108 | let (directory, cleanup) = dir_cleanup(boundary_directory); |
| 109 | 109 | let lock_path = add_lock_suffix(resource); |
| 110 | + let mut attempts = 1; | |
| 110 | 111 | match mode { |
| 111 | 112 | Fail::Immediately => try_lock(&lock_path, directory, cleanup), |
| 112 | 113 | Fail::AfterDurationWithBackoff(time) => { |
| 113 | 114 | for wait in backoff::Exponential::default_with_random().until_no_remaining(time) { |
| 115 | + attempts += 1; | |
| 114 | 116 | match try_lock(&lock_path, directory, cleanup.clone()) { |
| 115 | 117 | Ok(v) => return Ok(v), |
| 116 | 118 | Err(err) if err.kind() == AlreadyExists => { |
| @@ -127,6 +129,7 @@ fn lock_with_mode<T>( · 10 unmodified lines | ||
| 127 | 129 | AlreadyExists => Error::PermanentlyLocked { |
| 128 | 130 | resource_path: resource.into(), |
| 129 | 131 | mode, |
| 132 | + attempts, | |
| 130 | 133 | }, |
| 131 | 134 | _ => Error::Io(err), |
| 132 | 135 | }) |