mirror of
https://github.com/denoland/deno.git
synced 2025-02-02 04:38:21 -05:00
fix(runtime): do not panic on irregular dir entries (#9579)
This commit is contained in:
parent
d26bef21a5
commit
687ff2ab14
2 changed files with 29 additions and 11 deletions
|
@ -78,3 +78,23 @@ unitTest({ perms: { read: false } }, async function readDirPerm(): Promise<
|
||||||
await Deno.readDir("tests/")[Symbol.asyncIterator]().next();
|
await Deno.readDir("tests/")[Symbol.asyncIterator]().next();
|
||||||
}, Deno.errors.PermissionDenied);
|
}, Deno.errors.PermissionDenied);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
unitTest(
|
||||||
|
{ perms: { read: true }, ignore: Deno.build.os == "windows" },
|
||||||
|
async function readDirDevFd(): Promise<
|
||||||
|
void
|
||||||
|
> {
|
||||||
|
for await (const _ of Deno.readDir("/dev/fd")) {
|
||||||
|
// We don't actually care whats in here; just that we don't panic on non regular entries
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
unitTest(
|
||||||
|
{ perms: { read: true }, ignore: Deno.build.os == "windows" },
|
||||||
|
function readDirDevFdSync(): void {
|
||||||
|
for (const _ of Deno.readDirSync("/dev/fd")) {
|
||||||
|
// We don't actually care whats in here; just that we don't panic on non regular file entries
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
|
@ -1022,14 +1022,13 @@ fn op_read_dir_sync(
|
||||||
let entries: Vec<_> = std::fs::read_dir(path)?
|
let entries: Vec<_> = std::fs::read_dir(path)?
|
||||||
.filter_map(|entry| {
|
.filter_map(|entry| {
|
||||||
let entry = entry.unwrap();
|
let entry = entry.unwrap();
|
||||||
let file_type = entry.file_type().unwrap();
|
|
||||||
// Not all filenames can be encoded as UTF-8. Skip those for now.
|
// Not all filenames can be encoded as UTF-8. Skip those for now.
|
||||||
if let Ok(name) = into_string(entry.file_name()) {
|
if let Ok(name) = into_string(entry.file_name()) {
|
||||||
Some(json!({
|
Some(json!({
|
||||||
"name": name,
|
"name": name,
|
||||||
"isFile": file_type.is_file(),
|
"isFile": entry.file_type().map_or(false, |file_type| file_type.is_file()),
|
||||||
"isDirectory": file_type.is_dir(),
|
"isDirectory": entry.file_type().map_or(false, |file_type| file_type.is_dir()),
|
||||||
"isSymlink": file_type.is_symlink()
|
"isSymlink": entry.file_type().map_or(false, |file_type| file_type.is_symlink()),
|
||||||
}))
|
}))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
@ -1056,14 +1055,13 @@ async fn op_read_dir_async(
|
||||||
let entries: Vec<_> = std::fs::read_dir(path)?
|
let entries: Vec<_> = std::fs::read_dir(path)?
|
||||||
.filter_map(|entry| {
|
.filter_map(|entry| {
|
||||||
let entry = entry.unwrap();
|
let entry = entry.unwrap();
|
||||||
let file_type = entry.file_type().unwrap();
|
|
||||||
// Not all filenames can be encoded as UTF-8. Skip those for now.
|
// Not all filenames can be encoded as UTF-8. Skip those for now.
|
||||||
if let Ok(name) = into_string(entry.file_name()) {
|
if let Ok(name) = into_string(entry.file_name()) {
|
||||||
Some(json!({
|
Some(json!({
|
||||||
"name": name,
|
"name": name,
|
||||||
"isFile": file_type.is_file(),
|
"isFile": entry.file_type().map_or(false, |file_type| file_type.is_file()),
|
||||||
"isDirectory": file_type.is_dir(),
|
"isDirectory": entry.file_type().map_or(false, |file_type| file_type.is_dir()),
|
||||||
"isSymlink": file_type.is_symlink()
|
"isSymlink": entry.file_type().map_or(false, |file_type| file_type.is_symlink()),
|
||||||
}))
|
}))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
|
Loading…
Add table
Reference in a new issue