mirror of
https://github.com/denoland/deno.git
synced 2025-09-26 12:19:12 +00:00
refactor: Use PathBuf for paths in flag parsing and whitelists (#3955)
* Use PathBuf for DenoSubcommand::Bundle's out_file * Use PathBuf for DenoSubcommand::Format's files * Use PathBuf for DenoSubcommand::Install's dir * Use PathBuf for read/write whitelists
This commit is contained in:
parent
79b3bc05d6
commit
701ce9b334
7 changed files with 69 additions and 67 deletions
|
@ -102,9 +102,9 @@ impl Default for PermissionState {
|
|||
pub struct DenoPermissions {
|
||||
// Keep in sync with cli/js/permissions.ts
|
||||
pub allow_read: PermissionState,
|
||||
pub read_whitelist: HashSet<String>,
|
||||
pub read_whitelist: HashSet<PathBuf>,
|
||||
pub allow_write: PermissionState,
|
||||
pub write_whitelist: HashSet<String>,
|
||||
pub write_whitelist: HashSet<PathBuf>,
|
||||
pub allow_net: PermissionState,
|
||||
pub net_whitelist: HashSet<String>,
|
||||
pub allow_env: PermissionState,
|
||||
|
@ -349,10 +349,10 @@ fn log_perm_access(message: &str) {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_path_white_list(path: &Path, white_list: &HashSet<String>) -> bool {
|
||||
fn check_path_white_list(path: &Path, white_list: &HashSet<PathBuf>) -> bool {
|
||||
let mut path_buf = PathBuf::from(path);
|
||||
loop {
|
||||
if white_list.contains(path_buf.to_str().unwrap()) {
|
||||
if white_list.contains(&path_buf) {
|
||||
return true;
|
||||
}
|
||||
if !path_buf.pop() {
|
||||
|
@ -383,7 +383,11 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn check_paths() {
|
||||
let whitelist = svec!["/a/specific/dir/name", "/a/specific", "/b/c"];
|
||||
let whitelist = vec![
|
||||
PathBuf::from("/a/specific/dir/name"),
|
||||
PathBuf::from("/a/specific"),
|
||||
PathBuf::from("/b/c"),
|
||||
];
|
||||
|
||||
let perms = DenoPermissions::from_flags(&DenoFlags {
|
||||
read_whitelist: whitelist.clone(),
|
||||
|
@ -530,7 +534,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_permissions_request_read() {
|
||||
let whitelist = svec!["/foo/bar"];
|
||||
let whitelist = vec![PathBuf::from("/foo/bar")];
|
||||
let mut perms0 = DenoPermissions::from_flags(&DenoFlags {
|
||||
read_whitelist: whitelist.clone(),
|
||||
..Default::default()
|
||||
|
@ -566,7 +570,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_permissions_request_write() {
|
||||
let whitelist = svec!["/foo/bar"];
|
||||
let whitelist = vec![PathBuf::from("/foo/bar")];
|
||||
let mut perms0 = DenoPermissions::from_flags(&DenoFlags {
|
||||
write_whitelist: whitelist.clone(),
|
||||
..Default::default()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue