MCPcopy Create free account
hub / github.com/awslabs/llrt / write_file_sync

Function write_file_sync

modules/llrt_fs/src/write_file.rs:48–75  ·  view source on GitHub ↗
(
    ctx: Ctx<'js>,
    path: String,
    bytes: ObjectBytes<'js>,
    options: Opt<Either<String, WriteFileOptions>>,
)

Source from the content-addressed store, hash-verified

46}
47
48pub fn write_file_sync<'js>(
49 ctx: Ctx<'js>,
50 path: String,
51 bytes: ObjectBytes<'js>,
52 options: Opt<Either<String, WriteFileOptions>>,
53) -> Result<()> {
54 let write_error_message = &["Can't write file \"", &path, "\""].concat();
55 std::fs::write(&path, bytes.as_bytes(&ctx)?).or_throw_msg(&ctx, write_error_message)?;
56
57 #[cfg(unix)]
58 {
59 if let Some(Either::Right(opts)) = options.0 {
60 use std::os::unix::fs::PermissionsExt;
61
62 std::fs::set_permissions(path, PermissionsExt::from_mode(opts.mode.unwrap_or(0o666)))
63 .or_throw_msg(&ctx, write_error_message)?;
64 }
65 }
66 #[cfg(not(unix))]
67 {
68 _ = options;
69 if let Some(Either::Right(opts)) = options.0 {
70 _ = opts.mode;
71 }
72 }
73
74 Ok(())
75}
76
77pub(crate) struct WriteFileOptions {
78 pub mode: Option<u32>,

Callers

nothing calls this directly

Calls 4

concatMethod · 0.80
or_throw_msgMethod · 0.80
writeFunction · 0.50
as_bytesMethod · 0.45

Tested by

no test coverage detected