From 386fe547add3cdc57ea7f8757cdef6d0468fd106 Mon Sep 17 00:00:00 2001 From: Alexander Medvedev Date: Mon, 11 Aug 2025 21:03:29 +0200 Subject: [PATCH] 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 --- Cargo.lock | 11 ----------- pumpkin-world/Cargo.toml | 3 +-- pumpkin-world/src/generation/aquifer_sampler.rs | 4 ++-- pumpkin-world/src/lock/anvil.rs | 11 ++++------- pumpkin/Cargo.toml | 2 +- 5 files changed, 8 insertions(+), 23 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0b7d8309d..e2ae5f5bb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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", diff --git a/pumpkin-world/Cargo.toml b/pumpkin-world/Cargo.toml index 6ae324266..65d3933cb 100644 --- a/pumpkin-world/Cargo.toml +++ b/pumpkin-world/Cargo.toml @@ -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" diff --git a/pumpkin-world/src/generation/aquifer_sampler.rs b/pumpkin-world/src/generation/aquifer_sampler.rs index 160fa7a36..b81555bba 100644 --- a/pumpkin-world/src/generation/aquifer_sampler.rs +++ b/pumpkin-world/src/generation/aquifer_sampler.rs @@ -691,8 +691,8 @@ mod test { base_router: &ProtoNoiseRouters, ) -> ( WorldAquiferSampler, - ChunkNoiseRouter, - SurfaceHeightEstimateSampler, + ChunkNoiseRouter<'_>, + SurfaceHeightEstimateSampler<'_>, ChunkNoiseFunctionSampleOptions, ) { let surface_config = GENERATION_SETTINGS diff --git a/pumpkin-world/src/lock/anvil.rs b/pumpkin-world/src/lock/anvil.rs index ac0e46112..f314c6bab 100644 --- a/pumpkin-world/src/lock/anvil.rs +++ b/pumpkin-world/src/lock/anvil.rs @@ -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>>, + _locked_file: File, } const SESSION_LOCK_FILE_NAME: &str = "session.lock"; @@ -25,9 +23,8 @@ impl LevelLocker 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 }) } } diff --git a/pumpkin/Cargo.toml b/pumpkin/Cargo.toml index daad2c10d..2036e25ca 100644 --- a/pumpkin/Cargo.toml +++ b/pumpkin/Cargo.toml @@ -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!