mirror of
https://github.com/lune-org/lune.git
synced 2025-05-04 10:43:57 +01:00
Migrate lune-std-fs to use async-fs instead of tokio
This commit is contained in:
parent
43f11cd9f5
commit
0a3b57697d
4 changed files with 12 additions and 9 deletions
3
Cargo.lock
generated
3
Cargo.lock
generated
|
@ -1768,11 +1768,12 @@ dependencies = [
|
||||||
name = "lune-std-fs"
|
name = "lune-std-fs"
|
||||||
version = "0.1.2"
|
version = "0.1.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"async-fs",
|
||||||
"bstr",
|
"bstr",
|
||||||
|
"futures-lite",
|
||||||
"lune-std-datetime",
|
"lune-std-datetime",
|
||||||
"lune-utils",
|
"lune-utils",
|
||||||
"mlua",
|
"mlua",
|
||||||
"tokio",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
@ -15,9 +15,9 @@ workspace = true
|
||||||
[dependencies]
|
[dependencies]
|
||||||
mlua = { version = "0.10.3", features = ["luau"] }
|
mlua = { version = "0.10.3", features = ["luau"] }
|
||||||
|
|
||||||
|
async-fs = "2.1"
|
||||||
bstr = "1.9"
|
bstr = "1.9"
|
||||||
|
futures-lite = "2.6"
|
||||||
tokio = { version = "1", default-features = false, features = ["fs"] }
|
|
||||||
|
|
||||||
lune-utils = { version = "0.1.3", path = "../lune-utils" }
|
lune-utils = { version = "0.1.3", path = "../lune-utils" }
|
||||||
lune-std-datetime = { version = "0.1.2", path = "../lune-std-datetime" }
|
lune-std-datetime = { version = "0.1.2", path = "../lune-std-datetime" }
|
||||||
|
|
|
@ -2,8 +2,9 @@ use std::collections::VecDeque;
|
||||||
use std::io::ErrorKind;
|
use std::io::ErrorKind;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
|
use async_fs as fs;
|
||||||
|
use futures_lite::prelude::*;
|
||||||
use mlua::prelude::*;
|
use mlua::prelude::*;
|
||||||
use tokio::fs;
|
|
||||||
|
|
||||||
use super::options::FsWriteOptions;
|
use super::options::FsWriteOptions;
|
||||||
|
|
||||||
|
@ -24,8 +25,8 @@ async fn get_contents_at(root: PathBuf, _: FsWriteOptions) -> LuaResult<CopyCont
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
// Push initial children of the root path into the queue
|
// Push initial children of the root path into the queue
|
||||||
let mut entries = fs::read_dir(&normalized_root).await?;
|
let mut reader = fs::read_dir(&normalized_root).await?;
|
||||||
while let Some(entry) = entries.next_entry().await? {
|
while let Some(entry) = reader.try_next().await? {
|
||||||
queue.push_back((1, entry.path()));
|
queue.push_back((1, entry.path()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,7 +43,7 @@ async fn get_contents_at(root: PathBuf, _: FsWriteOptions) -> LuaResult<CopyCont
|
||||||
} else if meta.is_dir() {
|
} else if meta.is_dir() {
|
||||||
// FUTURE: Add an option in FsWriteOptions for max depth and limit it here
|
// FUTURE: Add an option in FsWriteOptions for max depth and limit it here
|
||||||
let mut entries = fs::read_dir(¤t_path).await?;
|
let mut entries = fs::read_dir(¤t_path).await?;
|
||||||
while let Some(entry) = entries.next_entry().await? {
|
while let Some(entry) = entries.try_next().await? {
|
||||||
queue.push_back((current_depth + 1, entry.path()));
|
queue.push_back((current_depth + 1, entry.path()));
|
||||||
}
|
}
|
||||||
dirs.push((current_depth, current_path));
|
dirs.push((current_depth, current_path));
|
||||||
|
|
|
@ -3,9 +3,10 @@
|
||||||
use std::io::ErrorKind as IoErrorKind;
|
use std::io::ErrorKind as IoErrorKind;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
use async_fs as fs;
|
||||||
use bstr::{BString, ByteSlice};
|
use bstr::{BString, ByteSlice};
|
||||||
|
use futures_lite::prelude::*;
|
||||||
use mlua::prelude::*;
|
use mlua::prelude::*;
|
||||||
use tokio::fs;
|
|
||||||
|
|
||||||
use lune_utils::TableBuilder;
|
use lune_utils::TableBuilder;
|
||||||
|
|
||||||
|
@ -59,7 +60,7 @@ async fn fs_read_file(lua: Lua, path: String) -> LuaResult<LuaString> {
|
||||||
async fn fs_read_dir(_: Lua, path: String) -> LuaResult<Vec<String>> {
|
async fn fs_read_dir(_: Lua, path: String) -> LuaResult<Vec<String>> {
|
||||||
let mut dir_strings = Vec::new();
|
let mut dir_strings = Vec::new();
|
||||||
let mut dir = fs::read_dir(&path).await.into_lua_err()?;
|
let mut dir = fs::read_dir(&path).await.into_lua_err()?;
|
||||||
while let Some(dir_entry) = dir.next_entry().await.into_lua_err()? {
|
while let Some(dir_entry) = dir.try_next().await.into_lua_err()? {
|
||||||
if let Some(dir_name_str) = dir_entry.file_name().to_str() {
|
if let Some(dir_name_str) = dir_entry.file_name().to_str() {
|
||||||
dir_strings.push(dir_name_str.to_owned());
|
dir_strings.push(dir_name_str.to_owned());
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Reference in a new issue