Skip to content

Commit f16cfe2

Browse files
committed
Updated version and fixed windows only stuff
1 parent 2832254 commit f16cfe2

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tmc-langs-cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "tmc-langs-cli"
3-
version = "0.18.0"
3+
version = "0.21.0"
44
authors = ["University of Helsinki <mooc@cs.helsinki.fi>", "Daniel Martinez <daniel.x.martinez@helsinki.fi>"]
55
edition = "2018"
66
description = "CLI client for TMC"

tmc-langs-util/src/file_util/lock_windows.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
use crate::error::FileError;
77
use crate::file_util::*;
8-
use fd_lock::{FdLock, FdLockGuard};
8+
use fd_lock::{RwLock, RwLockWriteGuard};
99
use std::os::windows::fs::OpenOptionsExt;
1010
use std::path::PathBuf;
1111
use std::{borrow::Cow, io::ErrorKind};
@@ -18,13 +18,13 @@ use winapi::um::{
1818
winnt::{FILE_ATTRIBUTE_HIDDEN, FILE_ATTRIBUTE_TEMPORARY},
1919
};
2020

21-
/// Wrapper for fd_lock::FdLock. Used to lock files/directories to prevent concurrent access
21+
/// Wrapper for fd_lock::RwLock. Used to lock files/directories to prevent concurrent access
2222
/// from multiple instances of tmc-langs.
2323
pub struct FileLock {
2424
path: PathBuf,
2525
// this is re-set in every lock command if the target is a file
2626
// ideally it would be set to none when the guard is dropped, but doing so is probably not worth the trouble
27-
lock: Option<FdLock<File>>,
27+
lock: Option<RwLock<File>>,
2828
}
2929

3030
impl FileLock {
@@ -42,12 +42,12 @@ impl FileLock {
4242
if self.path.is_file() {
4343
// for files, just use the path
4444
let file = open_file(&self.path)?;
45-
let lock = FdLock::new(file);
45+
let lock = RwLock::new(file);
4646
self.lock = Some(lock);
4747
let lock = self.lock.as_mut().expect("set to Some before this call");
48-
let guard = lock.lock().expect("cannot fail on Windows");
48+
let guard = lock.write().expect("cannot fail on Windows");
4949
Ok(FileLockGuard {
50-
_guard: LockInner::FdLockGuard(guard),
50+
_guard: LockInner::RwLockWriteGuard(guard),
5151
path: Cow::Borrowed(&self.path),
5252
})
5353
} else if self.path.is_dir() {
@@ -123,7 +123,7 @@ pub struct FileLockGuard<'a> {
123123

124124
enum LockInner<'a> {
125125
LockFile(File),
126-
FdLockGuard(FdLockGuard<'a, File>),
126+
RwLockWriteGuard(RwLockWriteGuard<'a, File>),
127127
}
128128

129129
impl Drop for FileLockGuard<'_> {
@@ -155,7 +155,7 @@ mod test {
155155
let mutex = Arc::new(Mutex::new(vec![]));
156156

157157
// take file lock and then mutex
158-
let guard = lock.lock().unwrap();
158+
let guard = lock.write().unwrap();
159159
let mut mguard = mutex.try_lock().unwrap();
160160

161161
let handle = {
@@ -165,7 +165,7 @@ mod test {
165165
std::thread::spawn(move || {
166166
// if the file lock doesn't block, the mutex lock will panic and the test will fail
167167
let mut lock = FileLock::new(temp_path).unwrap();
168-
let _guard = lock.lock().unwrap();
168+
let _guard = lock.write().unwrap();
169169
mutex.try_lock().unwrap().push(1);
170170
})
171171
};
@@ -191,7 +191,7 @@ mod test {
191191
let mutex = Arc::new(Mutex::new(vec![]));
192192

193193
// take file lock and mutex
194-
let guard = lock.lock().unwrap();
194+
let guard = lock.write().unwrap();
195195
let mut mguard = mutex.try_lock().unwrap();
196196

197197
let handle = {
@@ -201,7 +201,7 @@ mod test {
201201
std::thread::spawn(move || {
202202
// if the file lock doesn't block, the mutex lock will panic and the test will fail
203203
let mut lock = FileLock::new(temp_path).unwrap();
204-
let _guard = lock.lock().unwrap();
204+
let _guard = lock.write().unwrap();
205205
mutex.try_lock().unwrap().push(1);
206206
})
207207
};
@@ -225,7 +225,7 @@ mod test {
225225
let mut lock = FileLock::new(temp.path().to_path_buf()).unwrap();
226226
let lock_path = temp.path().join(".tmc.lock");
227227
assert!(!lock_path.exists());
228-
let guard = lock.lock().unwrap();
228+
let guard = lock.write().unwrap();
229229
assert!(lock_path.exists());
230230
drop(guard);
231231
assert!(!lock_path.exists());

0 commit comments

Comments
 (0)