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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ clap = "4.5"
clap_complete = "4.5"
dialoguer = "0.11.0"
directories-next = "2.0.0"
dunce = "1.0"
flate2 = { version = "1.0.11" }
futures = "0.3.21"
handlebars = "4.3.3"
Expand All @@ -64,9 +65,7 @@ mime_guess = "2.0.4"
num-traits = "0.2.14"
pem = "1.0.2"
proptest = "1.0.0"
reqwest = { version = "0.12.4", default-features = false, features = [
"rustls-tls",
] }
reqwest = { version = "0.12.4", default-features = false, features = ["rustls-tls"] }
ring = { version = "0.17.14", features = ["std"] }
schemars = "0.8"
sec1 = "0.3.0"
Expand Down
4 changes: 2 additions & 2 deletions src/canisters/frontend/ic-asset/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ic-asset"
version = "0.25.0" # sync with icx-asset
version = "0.25.0" # sync with icx-asset
authors.workspace = true
edition.workspace = true
repository.workspace = true
Expand All @@ -19,7 +19,7 @@ backoff.workspace = true
brotli = "6.0.0"
candid = { workspace = true }
derivative = "2.2.0"
dfx-core.workspace = true
dunce.workspace = true
flate2.workspace = true
futures.workspace = true
futures-intrusive = "0.4.0"
Expand Down
6 changes: 3 additions & 3 deletions src/canisters/frontend/ic-asset/src/asset/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ impl AssetSourceDirectoryConfiguration {
&mut self,
canonical_path: &Path,
) -> Result<AssetConfig, GetAssetConfigError> {
let parent_dir = dfx_core::fs::parent(canonical_path)?;
let parent_dir = crate::fs::parent(canonical_path)?;
Ok(self
.config_map
.get(&parent_dir)
Expand Down Expand Up @@ -243,7 +243,7 @@ impl AssetConfigTreeNode {
};
let mut rules = vec![];
if let Some(config_path) = config_path {
let content = dfx_core::fs::read_to_string(&config_path)?;
let content = crate::fs::read_to_string(&config_path)?;

let interim_rules: Vec<rule_utils::InterimAssetConfigRule> = json5::from_str(&content)
.map_err(|e| MalformedAssetConfigFile(config_path.to_path_buf(), e))?;
Expand All @@ -264,7 +264,7 @@ impl AssetConfigTreeNode {
};

configs.insert(dir.to_path_buf(), parent_ref.clone());
for f in dfx_core::fs::read_dir(dir)?
for f in crate::fs::read_dir(dir)?
.filter_map(|x| x.ok())
.filter(|x| x.file_type().map_or_else(|_e| false, |ft| ft.is_dir()))
{
Expand Down
4 changes: 2 additions & 2 deletions src/canisters/frontend/ic-asset/src/asset/content.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::asset::content_encoder::ContentEncoder;
use crate::error::fs::ReadFileError;
use brotli::CompressorWriter;
use dfx_core::error::fs::ReadFileError;
use flate2::Compression;
use flate2::write::GzEncoder;
use mime::Mime;
Expand All @@ -16,7 +16,7 @@ pub(crate) struct Content {

impl Content {
pub fn load(path: &Path) -> Result<Content, ReadFileError> {
let data = dfx_core::fs::read(path)?;
let data = crate::fs::read(path)?;

// todo: check contents if mime_guess fails https://github.com/dfinity/sdk/issues/1594
let media_type = mime_guess::from_path(path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ async fn make_project_asset(
logger: &Logger,
progress: Option<&dyn AssetSyncProgressRenderer>,
) -> Result<ProjectAsset, CreateProjectAssetError> {
let file_size = dfx_core::fs::metadata(&asset_descriptor.source)?.len();
let file_size = crate::fs::metadata(&asset_descriptor.source)?.len();
let permits = (file_size.div_ceil(1000000) as usize).clamp(1, MAX_COST_SINGLE_FILE_MB);
let _releaser = semaphores.file.acquire(permits).await;
let content = Content::load(&asset_descriptor.source)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::error::create_encoding::CreateEncodingError;
use dfx_core::error::fs::{ReadFileError, ReadMetadataError};
use crate::error::fs::{ReadFileError, ReadMetadataError};
use thiserror::Error;

/// Errors related to creating an asset found in the project in the asset canister.
Expand Down
133 changes: 133 additions & 0 deletions src/canisters/frontend/ic-asset/src/error/fs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
use std::path::PathBuf;
use thiserror::Error;

#[derive(Error, Debug)]
#[error("failed to canonicalize '{path}'")]
pub struct CanonicalizePathError {
pub path: PathBuf,
pub source: std::io::Error,
}

#[derive(Error, Debug)]
#[error("failed to copy {from} to {to}")]
pub struct CopyFileError {
pub from: PathBuf,
pub to: PathBuf,
pub source: std::io::Error,
}

#[derive(Error, Debug)]
#[error("failed to create directory {path} and parents")]
pub struct CreateDirAllError {
pub path: PathBuf,
pub source: std::io::Error,
}

#[derive(Error, Debug)]
pub enum EnsureDirExistsError {
#[error(transparent)]
CreateDirAll(#[from] CreateDirAllError),

#[error("path {0} is not a directory")]
NotADirectory(PathBuf),
}

#[derive(Error, Debug)]
pub enum EnsureParentDirExistsError {
#[error(transparent)]
EnsureDirExists(#[from] EnsureDirExistsError),

#[error(transparent)]
NoParentPath(#[from] NoParentPathError),
}

#[derive(Error, Debug)]
#[error("failed to determine parent path for '{0}'")]
pub struct NoParentPathError(pub PathBuf);

#[derive(Error, Debug)]
#[error("failed to read directory {path}")]
pub struct ReadDirError {
pub path: PathBuf,
pub source: std::io::Error,
}

#[derive(Error, Debug)]
#[error("failed to read from {path}")]
pub struct ReadFileError {
pub path: PathBuf,
pub source: std::io::Error,
}

#[derive(Error, Debug)]
#[error("failed to remove directory {path}")]
pub struct RemoveDirectoryError {
pub path: PathBuf,
pub source: std::io::Error,
}

#[derive(Error, Debug)]
#[error("failed to write to {path}")]
pub struct WriteFileError {
pub path: PathBuf,
pub source: std::io::Error,
}

#[derive(Error, Debug)]
#[error("failed to read metadata of {path}")]
pub struct ReadMetadataError {
pub path: PathBuf,
pub source: std::io::Error,
}

#[derive(Error, Debug)]
#[error("failed to read permissions of {path}")]
pub struct ReadPermissionsError {
pub path: PathBuf,
pub source: std::io::Error,
}

#[derive(Error, Debug)]
#[error("failed to read {path} as string")]
pub struct ReadToStringError {
pub path: PathBuf,
pub source: std::io::Error,
}

#[derive(Error, Debug)]
#[error("failed to remove directory {path} and its contents")]
pub struct RemoveDirectoryAndContentsError {
pub path: PathBuf,
pub source: std::io::Error,
}

#[derive(Error, Debug)]
#[error("failed to remove file {path}")]
pub struct RemoveFileError {
pub path: PathBuf,
pub source: std::io::Error,
}

#[derive(Error, Debug)]
#[error("Failed to rename {from} to {to}")]
pub struct RenameError {
pub from: PathBuf,
pub to: PathBuf,
pub source: std::io::Error,
}

#[derive(Error, Debug)]
#[error("failed to set permissions of {path}")]
pub struct SetPermissionsError {
pub path: PathBuf,
pub source: std::io::Error,
}

#[derive(Error, Debug)]
pub enum SetPermissionsReadWriteError {
#[error(transparent)]
ReadPermissions(#[from] ReadPermissionsError),

#[error(transparent)]
SetPermissions(#[from] SetPermissionsError),
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::error::fs::CanonicalizePathError;
use crate::error::get_asset_config::GetAssetConfigError;
use crate::error::load_config::AssetLoadConfigError;
use dfx_core::error::fs::CanonicalizePathError;
use std::path::PathBuf;
use thiserror::Error;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use dfx_core::error::fs::NoParentPathError;
use crate::error::fs::NoParentPathError;
use std::path::PathBuf;
use thiserror::Error;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::asset::content_encoder::ContentEncoder;
use dfx_core::error::fs::ReadFileError;
use crate::error::fs::ReadFileError;
use thiserror::Error;

/// Errors related to hashing asset content.
Expand Down
2 changes: 1 addition & 1 deletion src/canisters/frontend/ic-asset/src/error/load_config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::error::fs::{ReadDirError, ReadToStringError};
use crate::error::load_rule::LoadRuleError;
use dfx_core::error::fs::{ReadDirError, ReadToStringError};
use std::path::PathBuf;
use thiserror::Error;

Expand Down
1 change: 1 addition & 0 deletions src/canisters/frontend/ic-asset/src/error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mod create_chunk;
mod create_encoding;
mod create_project_asset;
mod downgrade_commit_batch_arguments;
pub(crate) mod fs;
mod gather_asset_descriptors;
mod get_asset_config;
mod get_asset_properties;
Expand Down
20 changes: 20 additions & 0 deletions src/canisters/frontend/ic-asset/src/fs/composite.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use crate::error::fs::EnsureDirExistsError::NotADirectory;
use crate::error::fs::{EnsureDirExistsError, EnsureParentDirExistsError};
use std::path::Path;

pub fn ensure_dir_exists(p: &Path) -> Result<(), EnsureDirExistsError> {
if !p.exists() {
crate::fs::create_dir_all(p)?;
Ok(())
} else if !p.is_dir() {
Err(NotADirectory(p.to_path_buf()))
} else {
Ok(())
}
}

pub fn ensure_parent_dir_exists(d: &Path) -> Result<(), EnsureParentDirExistsError> {
let parent = crate::fs::parent(d)?;
ensure_dir_exists(&parent)?;
Ok(())
}
Loading