From 455cd63f20fb812e065dcc6e1d75122d993b4d91 Mon Sep 17 00:00:00 2001 From: Eric Swanson <64809312+ericswanson-dfinity@users.noreply.github.com> Date: Fri, 24 Jan 2025 13:29:25 -0800 Subject: [PATCH] fix: custom canisters with a read-only wasm no longer fail to build with a permissions error (#4066) Fixes: https://dfinity.atlassian.net/browse/SDK-1848 --- CHANGELOG.md | 2 ++ e2e/tests-dfx/build.bash | 14 ++++++++++++++ src/dfx/src/lib/models/canister.rs | 1 + 3 files changed, 17 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index dee626999a..c2c1010885 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -88,6 +88,8 @@ This affects the following commands: Canisters with Motoko's Enhanced Orthogonal Persistence feature require `wasm_memory_persistence = Keep` when they get installed. Previously, when `dfx` attempted to install canisters with EOP enabled to a playground it didn't set `wasm_memory_persistence` properly. +### fix: custom canisters with a read-only wasm no longer fail to build with a permissions error + ### chore: improve `dfx deploy` messages. If users run `dfx deploy` without enough cycles, show additional messages to indicate what to do next. diff --git a/e2e/tests-dfx/build.bash b/e2e/tests-dfx/build.bash index 50948c1462..67bb5fa506 100644 --- a/e2e/tests-dfx/build.bash +++ b/e2e/tests-dfx/build.bash @@ -15,6 +15,20 @@ teardown() { standard_teardown } +@test "build custom canister succeeds even if input wasm is read-only" { + install_asset custom_canister + install_asset wasm/identity + chmod u-w main.wasm + + dfx_start + dfx canister create --all + assert_command dfx build custom + + jq '.canisters.custom.shrink=true' dfx.json | sponge dfx.json + jq '.canisters.custom.gzip=false' dfx.json | sponge dfx.json + assert_command dfx build custom +} + @test "can build a custom canister with wasm and/or candid from a url" { install_asset wasm/identity mkdir -p www/wasm diff --git a/src/dfx/src/lib/models/canister.rs b/src/dfx/src/lib/models/canister.rs index 77667e95e3..87b13b42ad 100644 --- a/src/dfx/src/lib/models/canister.rs +++ b/src/dfx/src/lib/models/canister.rs @@ -288,6 +288,7 @@ impl Canister { // If not modified and not set "gzip" explicitly, copy the wasm file directly so that hash match. if !modified && !info.get_gzip() { dfx_core::fs::copy(build_output_wasm_path, &wasm_path)?; + dfx_core::fs::set_permissions_readwrite(&wasm_path)?; return Ok(()); }