Skip to content

Commit

Permalink
fix: test errors(add is_symlink to NodeFsStats, use lstat for symlink…
Browse files Browse the repository at this point in the history
…_metadata)
  • Loading branch information
nilptr committed Dec 8, 2024
1 parent 2627707 commit 086d822
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions crates/node_binding/binding.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,7 @@ export interface JsTap {
export interface NodeFsStats {
isFile: boolean
isDirectory: boolean
isSymlink: boolean
atimeMs: number
mtimeMs: number
ctimeMs: number
Expand Down
3 changes: 2 additions & 1 deletion crates/rspack_fs_node/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub struct ThreadsafeNodeFS {
pub struct NodeFsStats {
pub is_file: bool,
pub is_directory: bool,
pub is_symlink: bool,
pub atime_ms: u32,
pub mtime_ms: u32,
pub ctime_ms: u32,
Expand All @@ -59,7 +60,7 @@ impl From<NodeFsStats> for FileMetadata {
Self {
is_file: value.is_file,
is_directory: value.is_directory,
is_symlink: false,
is_symlink: value.is_symlink,
atime_ms: value.atime_ms as u64,
mtime_ms: value.mtime_ms as u64,
ctime_ms: value.ctime_ms as u64,
Expand Down
9 changes: 8 additions & 1 deletion crates/rspack_fs_node/src/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,14 @@ impl ReadableFileSystem for NodeFileSystem {
}

fn symlink_metadata(&self, path: &Utf8Path) -> Result<FileMetadata> {
self.metadata(path)
let res = futures::executor::block_on(self.0.lstat.call_with_promise(path.to_string()))
.map_err(map_error_to_fs_error)?;
match res {
Either::A(stats) => Ok(stats.into()),
Either::B(_) => Err(new_fs_error(
"input file system call symlink_metadata failed",
)),
}
}

fn canonicalize(&self, path: &Utf8Path) -> Result<rspack_paths::Utf8PathBuf> {
Expand Down
1 change: 1 addition & 0 deletions packages/rspack/src/FileSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function __to_binding_stat(stat: IStats): NodeFsStats {
return {
isFile: stat.isFile(),
isDirectory: stat.isDirectory(),
isSymlink: stat.isSymbolicLink(),
atimeMs: stat.atimeMs,
mtimeMs: stat.atimeMs,
ctimeMs: stat.atimeMs,
Expand Down

0 comments on commit 086d822

Please sign in to comment.