// expect: run // result: 42 // phase: 6 // spec: docs/spec/16-standard-library.md ยง2.19 // grant: src=fs.read:/allowed // vfs: /denied/file=secret module test.path import std.path; import std.bytes; fn written(result: std.path.WriteResult) -> usize effects [] { match result { std.path.WriteResult::ok(n) => { return n; }, std.path.WriteResult::invalid_input => { trap; }, std.path.WriteResult::size_overflow => { trap; }, std.path.WriteResult::short_output => { trap; } } } fn main(src: cap) -> u64 effects [fs.read] { var bytes: [u8;16] = [255u8;16]; let n = written(std.path.join(mut bytes,b"/allowed",b"../denied/file")); assert(std.bytes.equal(ref bytes[0usize..n],b"/denied/file")); match fs.open_read(src,ref bytes[0usize..n]) { ok(file) => { trap; }, err(error) => { match error { io_error::permission_denied => {}, io_error::not_found => { trap; }, io_error::already_exists => { trap; }, io_error::invalid_input => { trap; }, io_error::no_space => { trap; }, io_error::broken_pipe => { trap; }, io_error::connection_refused => { trap; }, io_error::connection_reset => { trap; }, io_error::address_in_use => { trap; }, io_error::address_unavailable => { trap; }, io_error::timed_out => { trap; }, io_error::other => { trap; } } } } let count = written(std.path.normalize(mut bytes,b"x/../file")); match fs.open_read(src,ref bytes[0usize..count]) { ok(file) => { trap; }, err(error) => { match error { io_error::invalid_input => {}, io_error::permission_denied => { trap; }, io_error::not_found => { trap; }, io_error::already_exists => { trap; }, io_error::no_space => { trap; }, io_error::broken_pipe => { trap; }, io_error::connection_refused => { trap; }, io_error::connection_reset => { trap; }, io_error::address_in_use => { trap; }, io_error::address_unavailable => { trap; }, io_error::timed_out => { trap; }, io_error::other => { trap; } } } } return 42; }