From dc973c0313c5459eb1d407e6f5d7773e155cea7e Mon Sep 17 00:00:00 2001 From: Dennis Schwerdel Date: Wed, 12 Apr 2017 10:32:46 +0200 Subject: [PATCH] Fixed deadlock in uploader --- src/bundledb/uploader.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/bundledb/uploader.rs b/src/bundledb/uploader.rs index 5f24178..9be818f 100644 --- a/src/bundledb/uploader.rs +++ b/src/bundledb/uploader.rs @@ -44,8 +44,10 @@ impl BundleUploader { pub fn queue(&self, local_path: PathBuf, remote_path: PathBuf) -> Result<(), BundleDbError> { while self.waiting.load(Ordering::SeqCst) >= self.capacity { + debug!("Upload queue is full, waiting for slots"); let _ = self.wait.0.wait(self.wait.1.lock().unwrap()).unwrap(); } + trace!("Adding to upload queue: {:?}", local_path); if !self.error_present.load(Ordering::SeqCst) { self.waiting.fetch_add(1, Ordering::SeqCst); self.queue.push(Some((local_path, remote_path))); @@ -66,12 +68,14 @@ impl BundleUploader { fn worker_thread_inner(&self) -> Result<(), BundleDbError> { while let Some((src_path, dst_path)) = self.queue.pop() { + trace!("Uploading {:?} to {:?}", src_path, dst_path); + self.waiting.fetch_sub(1, Ordering::SeqCst); + self.wait.0.notify_all(); let folder = dst_path.parent().unwrap(); try!(fs::create_dir_all(&folder).context(&folder as &Path)); - if fs::rename(&src_path, &dst_path).is_err() { - try!(fs::copy(&src_path, &dst_path).context(&dst_path as &Path)); - try!(fs::remove_file(&src_path).context(&src_path as &Path)); - } + try!(fs::copy(&src_path, &dst_path).context(&dst_path as &Path)); + try!(fs::remove_file(&src_path).context(&src_path as &Path)); + debug!("Uploaded {:?} to {:?}", src_path, dst_path); } Ok(()) }