Skip to content

Commit

Permalink
Auto apply some suggestions from code review (do the rest by hand)
Browse files Browse the repository at this point in the history
Co-authored-by: Wez Furlong <wez@wezfurlong.org>
  • Loading branch information
Danielkonge and wez authored Sep 24, 2023
1 parent 5647310 commit 0274c41
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions lua-api-crates/filesystem/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ async fn read_dir<'lua>(_: &'lua Lua, path: String) -> mlua::Result<Vec<String>>

// similar (but not equal) to the shell command basename
async fn basename<'lua>(_: &'lua Lua, path: String) -> mlua::Result<String> {
// to check if the path actually exists, we can use:
/* let path = smol::fs::canonicalize(path)
.await
.map_err(mlua::Error::external)?; */
let path = Path::new(&path);
if let Some(basename) = path.file_name() {
if let Some(utf8) = basename.to_str() {
Expand All @@ -50,7 +46,8 @@ async fn basename<'lua>(_: &'lua Lua, path: String) -> mlua::Result<String> {
)));
}
} else {
// file_name returns None if the path name ends in ..
// file_name returns None if the path name ends in `..`
// but the unix utility return `..` in that case, so we do too
Ok("..".to_string())
}
}
Expand Down Expand Up @@ -79,7 +76,7 @@ async fn dirname<'lua>(_: &'lua Lua, path: String) -> mlua::Result<String> {
async fn canonical_path<'lua>(_: &'lua Lua, path: String) -> mlua::Result<String> {
let path = smol::fs::canonicalize(&path)
.await
.map_err(mlua::Error::external)?;
.map_err(|err| format!(mlua::Error::external("canonical_path('{path}'): {err:#}")))?;
if let Some(utf8) = &path.to_str() {
Ok(utf8.to_string())
} else {
Expand Down

0 comments on commit 0274c41

Please sign in to comment.