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"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be"
|
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]]
|
[[package]]
|
||||||
name = "flate2"
|
name = "flate2"
|
||||||
version = "1.1.2"
|
version = "1.1.2"
|
||||||
@ -2171,7 +2161,6 @@ dependencies = [
|
|||||||
"derive-getters",
|
"derive-getters",
|
||||||
"enum_dispatch",
|
"enum_dispatch",
|
||||||
"env_logger",
|
"env_logger",
|
||||||
"file-guard",
|
|
||||||
"flate2",
|
"flate2",
|
||||||
"futures",
|
"futures",
|
||||||
"itertools 0.14.0",
|
"itertools 0.14.0",
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
name = "pumpkin-world"
|
name = "pumpkin-world"
|
||||||
version.workspace = true
|
version.workspace = true
|
||||||
edition.workspace = true
|
edition.workspace = true
|
||||||
rust-version = "1.88"
|
rust-version = "1.89"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
pumpkin-nbt = { path = "../pumpkin-nbt" }
|
pumpkin-nbt = { path = "../pumpkin-nbt" }
|
||||||
@ -38,7 +38,6 @@ lz4-java-wrc = "0.2.0"
|
|||||||
ruzstd = "0.8.1"
|
ruzstd = "0.8.1"
|
||||||
|
|
||||||
itertools = "0.14.0"
|
itertools = "0.14.0"
|
||||||
file-guard = "0.2"
|
|
||||||
enum_dispatch = "0.3"
|
enum_dispatch = "0.3"
|
||||||
derive-getters = "0.5.0"
|
derive-getters = "0.5.0"
|
||||||
|
|
||||||
|
|||||||
@ -691,8 +691,8 @@ mod test {
|
|||||||
base_router: &ProtoNoiseRouters,
|
base_router: &ProtoNoiseRouters,
|
||||||
) -> (
|
) -> (
|
||||||
WorldAquiferSampler,
|
WorldAquiferSampler,
|
||||||
ChunkNoiseRouter,
|
ChunkNoiseRouter<'_>,
|
||||||
SurfaceHeightEstimateSampler,
|
SurfaceHeightEstimateSampler<'_>,
|
||||||
ChunkNoiseFunctionSampleOptions,
|
ChunkNoiseFunctionSampleOptions,
|
||||||
) {
|
) {
|
||||||
let surface_config = GENERATION_SETTINGS
|
let surface_config = GENERATION_SETTINGS
|
||||||
|
|||||||
@ -1,11 +1,9 @@
|
|||||||
use file_guard::{FileGuard, Lock};
|
|
||||||
|
|
||||||
use super::{LevelLocker, LockError};
|
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 {
|
pub struct AnvilLevelLocker {
|
||||||
_lock: Option<FileGuard<Arc<File>>>,
|
_locked_file: File,
|
||||||
}
|
}
|
||||||
|
|
||||||
const SESSION_LOCK_FILE_NAME: &str = "session.lock";
|
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
|
// im not joking, mojang writes a snowman into the lock file
|
||||||
file.write_all(SNOWMAN)
|
file.write_all(SNOWMAN)
|
||||||
.map_err(|_| LockError::FailedWrite)?;
|
.map_err(|_| LockError::FailedWrite)?;
|
||||||
let file_arc = Arc::new(file);
|
file.try_lock()
|
||||||
let lock = file_guard::try_lock(file_arc, Lock::Exclusive, 0, 1)
|
|
||||||
.map_err(|_| LockError::AlreadyLocked(SESSION_LOCK_FILE_NAME.to_string()))?;
|
.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
|
version.workspace = true
|
||||||
description = "Empowering everyone to host fast and efficient Minecraft servers."
|
description = "Empowering everyone to host fast and efficient Minecraft servers."
|
||||||
edition.workspace = true
|
edition.workspace = true
|
||||||
rust-version = "1.88"
|
rust-version = "1.89"
|
||||||
|
|
||||||
[package.metadata.tauri-winres]
|
[package.metadata.tauri-winres]
|
||||||
# FileDescription is handled as the Program name by Windows!
|
# FileDescription is handled as the Program name by Windows!
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user