Skip to content
This repository was archived by the owner on Feb 19, 2026. It is now read-only.

Commit 816a04e

Browse files
committed
del: fs::lock
1 parent 5b25e85 commit 816a04e

File tree

10 files changed

+9
-215
lines changed

10 files changed

+9
-215
lines changed

cli/src/bms.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use futures::stream::{self, StreamExt as FuturesStreamExt};
99
use smol::{fs, io};
1010

1111
use self::work::extract_work_name;
12-
use crate::fs::lock::acquire_disk_lock;
1312

1413
pub const BMS_FILE_EXTS: &[&str] = &["bms", "bme", "bml", "pms"];
1514
pub const BMSON_FILE_EXTS: &[&str] = &["bmson"];
@@ -38,10 +37,7 @@ pub const MEDIA_FILE_EXTS_FILE_EXTS: LazyCell<Vec<&str>> = LazyCell::new(|| {
3837

3938
/// 仅负责读取 BMS 文件(异步 IO)
4039
async fn read_bms_file(file: &Path) -> io::Result<Vec<u8>> {
41-
let bytes = {
42-
let _lock_guard = acquire_disk_lock(file).await;
43-
fs::read(file).await?
44-
};
40+
let bytes = { fs::read(file).await? };
4541
Ok(bytes)
4642
}
4743

@@ -60,10 +56,7 @@ pub async fn parse_bms_file(file: &Path) -> io::Result<BmsOutput> {
6056

6157
/// 仅负责读取 BMSON 文件(异步 IO)
6258
async fn read_bmson_file(file: &Path) -> io::Result<Vec<u8>> {
63-
let bytes = {
64-
let _lock_guard = acquire_disk_lock(file).await;
65-
fs::read(file).await?
66-
};
59+
let bytes = { fs::read(file).await? };
6760
Ok(bytes)
6861
}
6962

cli/src/fs.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
pub mod lock;
21
pub mod moving;
32
pub mod rawpack;
43
pub mod sync;
@@ -12,8 +11,6 @@ use smol::{
1211
stream::StreamExt,
1312
};
1413

15-
use crate::fs::lock::acquire_disk_locks;
16-
1714
/// Signs:
1815
/// :\/*?"<>|
1916
pub fn get_vaild_fs_name(ori_name: &str) -> String {
@@ -45,7 +42,6 @@ pub async fn is_file_same_content(a: &Path, b: &Path) -> io::Result<bool> {
4542
}
4643
Ok(hasher.finalize())
4744
}
48-
let _locks = acquire_disk_locks(&[a, b]).await;
4945
let a_md = fs::metadata(a).await?;
5046
let b_md = fs::metadata(b).await?;
5147
if a_md.len() != b_md.len() || a_md.is_dir() || b_md.is_dir() {

cli/src/fs/lock.rs

Lines changed: 0 additions & 117 deletions
This file was deleted.

cli/src/fs/moving.rs

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use futures::stream::{self, StreamExt as FuturesStreamExt, TryStreamExt};
1414

1515
use crate::bms::{BMS_FILE_EXTS, BMSON_FILE_EXTS};
1616

17-
use super::{is_dir_having_file, is_file_same_content, lock::acquire_disk_locks};
17+
use super::{is_dir_having_file, is_file_same_content};
1818
use log::warn;
1919

2020
/// Same name enum as Python
@@ -117,12 +117,10 @@ pub async fn move_elements_across_dir(
117117
let dir_path_ori = dir_path_ori.as_ref();
118118
let dir_path_dst = dir_path_dst.as_ref();
119119
// Lock and read source metadata
120-
let _l_ori = acquire_disk_locks(&[dir_path_ori]).await;
121120
let ori_md = match fs::metadata(&dir_path_ori).await {
122121
Ok(m) => m,
123122
Err(_) => return Ok(()),
124123
};
125-
drop(_l_ori);
126124

127125
if dir_path_ori == dir_path_dst {
128126
return Ok(());
@@ -134,9 +132,7 @@ pub async fn move_elements_across_dir(
134132
// Do this check BEFORE creating the target directory, otherwise we'd
135133
// unnecessarily enumerate and move children one-by-one.
136134
// Lock and read destination metadata
137-
let _l_dst = acquire_disk_locks(&[dir_path_dst]).await;
138135
let dst_meta_res = fs::metadata(&dir_path_dst).await;
139-
drop(_l_dst);
140136

141137
match dst_meta_res {
142138
Ok(m) => {
@@ -148,7 +144,6 @@ pub async fn move_elements_across_dir(
148144
}
149145
Err(e) => {
150146
if e.kind() == io::ErrorKind::NotFound {
151-
let _l = acquire_disk_locks(&[dir_path_ori, dir_path_dst]).await;
152147
fs::rename(&dir_path_ori, &dir_path_dst).await?;
153148
return Ok(());
154149
} else {
@@ -189,9 +184,7 @@ async fn process_directory(
189184
replace_options: &ReplaceOptions,
190185
) -> io::Result<Vec<(PathBuf, PathBuf)>> {
191186
// Collect entries to be processed (files / subdirectories)
192-
let _l_rd = acquire_disk_locks(&[dir_path_ori]).await;
193187
let mut entries = fs::read_dir(dir_path_ori).await?;
194-
drop(_l_rd);
195188
let next_folder_paths = Arc::new(Mutex::new(Vec::new()));
196189
let mut pairs: Vec<(PathBuf, PathBuf)> = Vec::new();
197190

@@ -259,9 +252,7 @@ async fn process_directory(
259252
// Stage 2a: directory direct moves (streamed parallel)
260253
stream::iter(dir_direct_moves)
261254
.map(|(src, dst)| async move {
262-
let _locks = acquire_disk_locks(&[&src, &dst]).await;
263255
let r = fs::rename(&src, &dst).await.map(|_| ());
264-
drop(_locks);
265256
r
266257
})
267258
.buffer_unordered(64)
@@ -288,9 +279,7 @@ async fn process_directory(
288279
// Stage 2c: file Rename actions (streamed parallel)
289280
stream::iter(file_rename_ops)
290281
.map(|(src, dst)| async move {
291-
let _locks = acquire_disk_locks(&[&src, &dst]).await;
292282
let r = move_file_rename(&src, &dst).await.map(|_| ());
293-
drop(_locks);
294283
r
295284
})
296285
.buffer_unordered(128)
@@ -303,9 +292,7 @@ async fn process_directory(
303292
.map(|(src, dst)| {
304293
let rep = rep_clone2.clone();
305294
async move {
306-
let _locks = acquire_disk_locks(&[&src, &dst]).await;
307295
let r = move_file(&src, &dst, &rep).await.map(|_| ());
308-
drop(_locks);
309296
r
310297
}
311298
})
@@ -325,36 +312,28 @@ async fn move_file(src: &Path, dst: &Path, rep: &ReplaceOptions) -> io::Result<(
325312

326313
match action {
327314
ReplaceAction::Replace => {
328-
let _locks = acquire_disk_locks(&[src, dst]).await;
329315
let r = fs::rename(src, dst).await;
330-
drop(_locks);
331316
r
332317
}
333318
ReplaceAction::Skip => {
334319
let exists = fs::metadata(&dst).await.is_ok();
335320
if exists {
336321
return Ok(());
337322
}
338-
let _locks = acquire_disk_locks(&[src, dst]).await;
339323
let r = fs::rename(src, dst).await;
340-
drop(_locks);
341324
r
342325
}
343326
ReplaceAction::Rename => move_file_rename(src, dst).await,
344327
ReplaceAction::CheckReplace => {
345328
let dst_exists = fs::metadata(&dst).await.is_ok();
346329
if !dst_exists {
347-
let _locks = acquire_disk_locks(&[src, dst]).await;
348330
let r = fs::rename(src, dst).await;
349-
drop(_locks);
350331
r
351332
} else {
352333
let same = is_file_same_content(src, dst).await?;
353334
if same {
354335
// Same content, directly overwrite
355-
let _locks = acquire_disk_locks(&[src, dst]).await;
356336
let r = fs::rename(src, dst).await;
357-
drop(_locks);
358337
r
359338
} else {
360339
move_file_rename(src, dst).await
@@ -382,17 +361,13 @@ async fn move_file_rename(src: &Path, dst_dir: &Path) -> io::Result<()> {
382361
};
383362
dst.set_file_name(name);
384363
if fs::metadata(&dst).await.is_err() {
385-
let _locks = acquire_disk_locks(&[src, &dst]).await;
386364
fs::rename(src, &dst).await?;
387-
drop(_locks);
388365
return Ok(());
389366
}
390367
let same = is_file_same_content(src, &dst).await?;
391368
if same {
392369
// File with same name and content already exists, skip
393-
let _ls = acquire_disk_locks(&[src]).await;
394370
fs::remove_file(src).await?;
395-
drop(_ls);
396371
return Ok(());
397372
}
398373
}

cli/src/fs/rawpack.rs

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use std::path::Path;
55
use smol::stream::StreamExt;
66
use smol::{fs, io};
77

8-
use crate::fs::lock::{acquire_disk_lock, acquire_disk_locks};
98
use crate::fs::moving::{ReplacePreset, move_elements_across_dir, replace_options_from_preset};
109

1110
/// Extract supported archives to specified cache directory
@@ -28,30 +27,16 @@ pub async fn unzip_file_to_cache_dir(
2827
.to_lowercase();
2928

3029
match ext.as_str() {
31-
"zip" => {
32-
// Acquire disk locks for file operations (smart locking to avoid duplicate locks on same disk)
33-
let _lock_guards = acquire_disk_locks(&[file_path, cache_dir_path]).await;
34-
extract_zip(file_path, cache_dir_path).await?
35-
}
36-
"7z" => {
37-
// Acquire disk locks for file operations (smart locking to avoid duplicate locks on same disk)
38-
let _lock_guards = acquire_disk_locks(&[file_path, cache_dir_path]).await;
39-
extract_7z(file_path, cache_dir_path).await?
40-
}
41-
"rar" => {
42-
// Acquire disk locks for file operations (smart locking to avoid duplicate locks on same disk)
43-
let _lock_guards = acquire_disk_locks(&[file_path, cache_dir_path]).await;
44-
extract_rar(file_path, cache_dir_path).await?
45-
}
30+
"zip" => extract_zip(file_path, cache_dir_path).await?,
31+
"7z" => extract_7z(file_path, cache_dir_path).await?,
32+
"rar" => extract_rar(file_path, cache_dir_path).await?,
4633
_ => {
4734
// Not an archive => copy after space
4835
let target_name = file_name
4936
.split_once(' ')
5037
.map(|(_, s)| s)
5138
.unwrap_or(file_name);
5239
let target = cache_dir_path.join(target_name);
53-
// Acquire disk locks for file copy operation
54-
let _lock_guards = acquire_disk_locks(&[file_path, cache_dir_path]).await;
5540
fs::copy(file_path, target).await?;
5641
}
5742
}
@@ -141,8 +126,6 @@ pub async fn move_out_files_in_folder_in_cache_dir(
141126
let path = entry.path();
142127
if entry.file_type().await?.is_dir() {
143128
if name == "__MACOSX" {
144-
// Acquire disk lock for directory removal
145-
let _lock_guard = acquire_disk_lock(&path).await;
146129
fs::remove_dir_all(&path).await?;
147130
continue;
148131
}
@@ -181,8 +164,6 @@ pub async fn move_out_files_in_folder_in_cache_dir(
181164
" - Renaming inner inner dir name: {}",
182165
inner_inner.display()
183166
);
184-
// Acquire disk lock for file rename operation
185-
let _lock_guard = acquire_disk_lock(&inner_inner).await;
186167
fs::rename(&inner_inner, format!("{}-rep", inner_inner.display())).await?;
187168
}
188169
log::info!(
@@ -196,8 +177,6 @@ pub async fn move_out_files_in_folder_in_cache_dir(
196177
replace_options_from_preset(replace_preset),
197178
)
198179
.await?;
199-
// Acquire disk lock for directory removal
200-
let _lock_guard = acquire_disk_lock(&inner_path).await;
201180
fs::remove_dir(&inner_path).await.ok();
202181
}
203182
}
@@ -208,8 +187,6 @@ pub async fn move_out_files_in_folder_in_cache_dir(
208187

209188
if cache_folder_count == 0 && cache_file_count == 0 {
210189
log::info!(" !_! {}: Cache is Empty!", cache_dir_path.display());
211-
// Acquire disk lock for directory removal
212-
let _lock_guard = acquire_disk_lock(cache_dir_path).await;
213190
fs::remove_dir(cache_dir_path).await?;
214191
return Ok(false);
215192
}

0 commit comments

Comments
 (0)