(
ctx: Ctx<'js>,
path: String,
bytes: ObjectBytes<'js>,
options: Opt<Either<String, WriteFileOptions>>,
)
| 46 | } |
| 47 | |
| 48 | pub 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 | |
| 77 | pub(crate) struct WriteFileOptions { |
| 78 | pub mode: Option<u32>, |
nothing calls this directly
no test coverage detected