mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-11-29 14:25:45 +03:00
Merge pull request #1094 from gitbutlerapp/if-locked--return
if locked, return
This commit is contained in:
commit
605c3e0dc1
@ -1,4 +1,4 @@
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::sync::{Arc, Mutex, TryLockError};
|
||||
use std::{path, time};
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
@ -60,7 +60,11 @@ impl TryFrom<&AppHandle> for HandlerInner {
|
||||
|
||||
impl HandlerInner {
|
||||
pub fn handle(&self, project_id: &str, now: &time::SystemTime) -> Result<Vec<events::Event>> {
|
||||
let _lock = self.mutex.lock().unwrap();
|
||||
let _lock = match self.mutex.try_lock() {
|
||||
Ok(lock) => lock,
|
||||
Err(TryLockError::Poisoned(_)) => return Err(anyhow::anyhow!("mutex poisoned")),
|
||||
Err(TryLockError::WouldBlock) => return Ok(vec![]),
|
||||
};
|
||||
|
||||
let gb_repo = gb_repository::Repository::open(
|
||||
self.local_data_dir.clone(),
|
||||
|
@ -1,5 +1,5 @@
|
||||
use std::path;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::sync::{Arc, Mutex, TryLockError};
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use tauri::AppHandle;
|
||||
@ -48,18 +48,34 @@ impl TryFrom<&AppHandle> for HandlerInner {
|
||||
.path_resolver()
|
||||
.app_local_data_dir()
|
||||
.context("failed to get local data dir")?;
|
||||
Ok(Self {
|
||||
local_data_dir: local_data_dir.to_path_buf(),
|
||||
project_storage: projects::Storage::try_from(value)?,
|
||||
user_storage: users::Storage::try_from(value)?,
|
||||
mutex: Mutex::new(()),
|
||||
})
|
||||
Ok(Self::new(
|
||||
local_data_dir.to_path_buf(),
|
||||
projects::Storage::try_from(value)?,
|
||||
users::Storage::try_from(value)?,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
impl HandlerInner {
|
||||
fn new(
|
||||
local_data_dir: path::PathBuf,
|
||||
project_storage: projects::Storage,
|
||||
user_storage: users::Storage,
|
||||
) -> Self {
|
||||
Self {
|
||||
local_data_dir,
|
||||
project_storage,
|
||||
user_storage,
|
||||
mutex: Mutex::new(()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn handle(&self, project_id: &str) -> Result<Vec<events::Event>> {
|
||||
let _lock = self.mutex.lock().unwrap();
|
||||
let _lock = match self.mutex.try_lock() {
|
||||
Ok(lock) => lock,
|
||||
Err(TryLockError::Poisoned(_)) => return Err(anyhow::anyhow!("mutex poisoned")),
|
||||
Err(TryLockError::WouldBlock) => return Ok(vec![]),
|
||||
};
|
||||
|
||||
let gb_repo = gb_repository::Repository::open(
|
||||
&self.local_data_dir,
|
||||
|
Loading…
Reference in New Issue
Block a user