Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions e2e/tests-icx-asset/icx-asset.bash
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,28 @@ icx_asset_upload() {
assert_not_match '"/will-delete-this.txt"'
}

@test "does not delete removed files if --no-delete is passed" {
touch src/e2e_project_frontend/assets/will-not-delete-this.txt
dfx deploy

assert_command dfx canister call --query e2e_project_frontend get '(record{key="/will-not-delete-this.txt";accept_encodings=vec{"identity"}})'
assert_command dfx canister call --query e2e_project_frontend list '(record{})'
assert_match '"/will-not-delete-this.txt"'

rm src/e2e_project_frontend/assets/will-not-delete-this.txt

icx_asset_sync src/e2e_project_frontend/assets --no-delete

assert_command dfx canister call --query e2e_project_frontend get '(record{key="/will-not-delete-this.txt";accept_encodings=vec{"identity"}})'
assert_command dfx canister call --query e2e_project_frontend list '(record{})'
assert_match '"/will-not-delete-this.txt"'
icx_asset_sync src/e2e_project_frontend/assets

assert_command_fail dfx canister call --query e2e_project_frontend get '(record{key="/will-not-delete-this.txt";accept_encodings=vec{"identity"}})'
assert_command dfx canister call --query e2e_project_frontend list '(record{})'
assert_not_contains '"/will-not-delete-this.txt"'
}
Comment thread
olaszakos marked this conversation as resolved.

@test "unsets asset encodings that are removed from project" {

# shellcheck disable=SC2086
Expand Down
2 changes: 1 addition & 1 deletion src/canisters/frontend/ic-asset/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
//! .with_agent(&agent)
//! .build()?;
//! let logger = slog::Logger::root(slog::Discard, slog::o!());
//! ic_asset::sync(&canister, &[concat!(env!("CARGO_MANIFEST_DIR"), "assets/").as_ref()], &logger).await?;
//! ic_asset::sync(&canister, &[concat!(env!("CARGO_MANIFEST_DIR"), "assets/").as_ref()], false, &logger).await?;
//! # Ok(())
//! # }

Expand Down
11 changes: 8 additions & 3 deletions src/canisters/frontend/ic-asset/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const KNOWN_DIRECTORIES: [&str; 1] = [".well-known"];
pub async fn upload_content_and_assemble_sync_operations(
canister: &Canister<'_>,
dirs: &[&Path],
no_delete: bool,
logger: &Logger,
) -> Result<CommitBatchArguments, UploadContentError> {
let asset_descriptors = gather_asset_descriptors(dirs, logger)?;
Expand Down Expand Up @@ -84,7 +85,10 @@ pub async fn upload_content_and_assemble_sync_operations(
let commit_batch_args = batch_upload::operations::assemble_commit_batch_arguments(
project_assets,
canister_assets,
AssetDeletionReason::Obsolete,
match no_delete {
true => AssetDeletionReason::Incompatible,
false => AssetDeletionReason::Obsolete,
},
canister_asset_properties,
batch_id,
);
Expand Down Expand Up @@ -112,10 +116,11 @@ pub async fn upload_content_and_assemble_sync_operations(
pub async fn sync(
canister: &Canister<'_>,
dirs: &[&Path],
no_delete: bool,
logger: &Logger,
) -> Result<(), SyncError> {
let commit_batch_args =
upload_content_and_assemble_sync_operations(canister, dirs, logger).await?;
upload_content_and_assemble_sync_operations(canister, dirs, no_delete, logger).await?;
let canister_api_version = api_version(canister).await;
debug!(logger, "Canister API version: {canister_api_version}. ic-asset API version: {BATCH_UPLOAD_API_VERSION}");
info!(logger, "Committing batch.");
Expand Down Expand Up @@ -189,7 +194,7 @@ pub async fn prepare_sync_for_proposal(
dirs: &[&Path],
logger: &Logger,
) -> Result<(), PrepareSyncForProposalError> {
let arg = upload_content_and_assemble_sync_operations(canister, dirs, logger).await?;
let arg = upload_content_and_assemble_sync_operations(canister, dirs, false, logger).await?;
let arg = sort_batch_operations(arg);
let batch_id = arg.batch_id.clone();

Expand Down
2 changes: 1 addition & 1 deletion src/canisters/frontend/icx-asset/src/commands/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ pub(crate) async fn sync(
logger: &Logger,
) -> anyhow::Result<()> {
let dirs: Vec<&Path> = o.directory.iter().map(|d| d.as_path()).collect();
ic_asset::sync(canister, &dirs, logger).await?;
ic_asset::sync(canister, &dirs, o.no_delete, logger).await?;
Ok(())
}
4 changes: 4 additions & 0 deletions src/canisters/frontend/icx-asset/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ struct SyncOpts {

/// The directories to synchronize
directory: Vec<PathBuf>,

/// Do not delete files from the canister that are not present locally.
#[arg(long)]
no_delete: bool,
}

#[derive(Parser)]
Expand Down
2 changes: 1 addition & 1 deletion src/dfx/src/lib/installers/assets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub async fn post_install_store_assets(
.build()
.context("Failed to build asset canister caller.")?;

ic_asset::sync(&canister, &source_paths, logger)
ic_asset::sync(&canister, &source_paths, false, logger)
.await
.with_context(|| {
format!(
Expand Down