use rust's new file::try_lock
I was already waiting for this for a long time, now in the newest rust 1.89 it got stabilized :D https://doc.rust-lang.org/stable/std/fs/struct.File.html#method.try_lock
This commit is contained in:
parent
7e3a1c0972
commit
386fe547ad
11
Cargo.lock
generated
11
Cargo.lock
generated
@ -875,16 +875,6 @@ version = "2.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be"
|
||||
|
||||
[[package]]
|
||||
name = "file-guard"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "21ef72acf95ec3d7dbf61275be556299490a245f017cf084bd23b4f68cf9407c"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "flate2"
|
||||
version = "1.1.2"
|
||||
@ -2171,7 +2161,6 @@ dependencies = [
|
||||
"derive-getters",
|
||||
"enum_dispatch",
|
||||
"env_logger",
|
||||
"file-guard",
|
||||
"flate2",
|
||||
"futures",
|
||||
"itertools 0.14.0",
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
name = "pumpkin-world"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
rust-version = "1.88"
|
||||
rust-version = "1.89"
|
||||
|
||||
[dependencies]
|
||||
pumpkin-nbt = { path = "../pumpkin-nbt" }
|
||||
@ -38,7 +38,6 @@ lz4-java-wrc = "0.2.0"
|
||||
ruzstd = "0.8.1"
|
||||
|
||||
itertools = "0.14.0"
|
||||
file-guard = "0.2"
|
||||
enum_dispatch = "0.3"
|
||||
derive-getters = "0.5.0"
|
||||
|
||||
|
||||
@ -691,8 +691,8 @@ mod test {
|
||||
base_router: &ProtoNoiseRouters,
|
||||
) -> (
|
||||
WorldAquiferSampler,
|
||||
ChunkNoiseRouter,
|
||||
SurfaceHeightEstimateSampler,
|
||||
ChunkNoiseRouter<'_>,
|
||||
SurfaceHeightEstimateSampler<'_>,
|
||||
ChunkNoiseFunctionSampleOptions,
|
||||
) {
|
||||
let surface_config = GENERATION_SETTINGS
|
||||
|
||||
@ -1,11 +1,9 @@
|
||||
use file_guard::{FileGuard, Lock};
|
||||
|
||||
use super::{LevelLocker, LockError};
|
||||
|
||||
use std::{fs::File, io::Write, path::Path, sync::Arc};
|
||||
use std::{fs::File, io::Write, path::Path};
|
||||
|
||||
pub struct AnvilLevelLocker {
|
||||
_lock: Option<FileGuard<Arc<File>>>,
|
||||
_locked_file: File,
|
||||
}
|
||||
|
||||
const SESSION_LOCK_FILE_NAME: &str = "session.lock";
|
||||
@ -25,9 +23,8 @@ impl LevelLocker<Self> for AnvilLevelLocker {
|
||||
// im not joking, mojang writes a snowman into the lock file
|
||||
file.write_all(SNOWMAN)
|
||||
.map_err(|_| LockError::FailedWrite)?;
|
||||
let file_arc = Arc::new(file);
|
||||
let lock = file_guard::try_lock(file_arc, Lock::Exclusive, 0, 1)
|
||||
file.try_lock()
|
||||
.map_err(|_| LockError::AlreadyLocked(SESSION_LOCK_FILE_NAME.to_string()))?;
|
||||
Ok(Self { _lock: Some(lock) })
|
||||
Ok(Self { _locked_file: file })
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,7 +3,7 @@ name = "pumpkin"
|
||||
version.workspace = true
|
||||
description = "Empowering everyone to host fast and efficient Minecraft servers."
|
||||
edition.workspace = true
|
||||
rust-version = "1.88"
|
||||
rust-version = "1.89"
|
||||
|
||||
[package.metadata.tauri-winres]
|
||||
# FileDescription is handled as the Program name by Windows!
|
||||
|
||||
Loading…
Reference in New Issue
Block a user