pub fn install_package(
    shared_data: &Shared<AppsSharedData>,
    from_path: &Path,
    manifest: &Manifest,
) -> Result<(), AppsActorError> {
    let data_path = {
        let shared = shared_data.lock();
        shared.config.data_path.clone()
    };

    let path = Path::new(&data_path);

    if !from_path.is_file() {
        return Err(AppsActorError::PackageMissing);
    }
    if !path.is_dir() {
        return Err(AppsActorError::InstallationDirNotFound);
    }
    let mut shared = shared_data.lock();
    let app_name = sanitize_filename::sanitize(manifest.get_name()).to_lowercase();
    let update_url = format!("https://{}.local/manifest.webapp", &app_name);
    let app_name = shared
        .registry
        .get_unique_name(&manifest.get_name(), &update_url)
        .map_err(|_| AppsActorError::InvalidAppName)?;

    let download_dir = path.join(&format!("downloading/{}", &app_name));
    let download_app = download_dir.join("application.zip");

    fs::create_dir_all(download_dir.as_path())?;
    fs::copy(from_path, download_app.as_path())?;

    let is_update = shared.registry.get_by_update_url(&update_url).is_some();
    let vhost_port = shared.registry.get_vhost_port();
    // Need create appsItem object and add to db to reflect status
    let mut apps_item = AppsItem::default(&app_name, vhost_port);
    if !manifest.get_version().is_empty() {
        apps_item.set_version(&manifest.get_version());
    }
    apps_item.set_update_url(&update_url);
    apps_item.set_install_state(AppsInstallState::Installing);
    let _ = shared
        .registry
        .apply_download(&mut apps_item, &download_dir, &manifest, &path, is_update)
        .map_err(|_| AppsActorError::WrongRegistration)?;

    if is_update {
        shared
            .registry
            .event_broadcaster
            .broadcast_app_updated(AppsObject::from(&apps_item));

        shared.vhost_api.app_updated(&app_name);
    } else {
        shared
            .registry
            .event_broadcaster
            .broadcast_app_installed(AppsObject::from(&apps_item));

        shared.vhost_api.app_installed(&app_name);
    }

    Ok(())
}
// Read valid application from from_path.
// Install it to data_dir.
// Update shared_data with manifest
Read valid application from from_path.
Install it to data_dir.
Update shared_data with manifest
Read valid application from from_path . Install it to data_dir . Update shared_data with manifest
pub fn install_package(
    shared_data: &Shared<AppsSharedData>,
    from_path: &Path,
    manifest: &Manifest,
) -> Result<(), AppsActorError> {
    let data_path = {
        let shared = shared_data.lock();
        shared.config.data_path.clone()
    };
    let path = Path::new(&data_path);
    if !from_path.is_file() {
        return Err(AppsActorError::PackageMissing);
    }
    if !path.is_dir() {
        return Err(AppsActorError::InstallationDirNotFound);
    }
    let mut shared = shared_data.lock();
    let app_name = sanitize_filename::sanitize(manifest.get_name()).to_lowercase();
    let update_url = format!("https://{}.local/manifest.webapp", &app_name);
    let app_name = shared
        .registry
        .get_unique_name(&manifest.get_name(), &update_url)
        .map_err(|_| AppsActorError::InvalidAppName)?;
    let download_dir = path.join(&format!("downloading/{}", &app_name));
    let download_app = download_dir.join("application.zip");
    fs::create_dir_all(download_dir.as_path())?;
    fs::copy(from_path, download_app.as_path())?;
    let is_update = shared.registry.get_by_update_url(&update_url).is_some();
    let vhost_port = shared.registry.get_vhost_port();
    // Need create appsItem object and add to db to reflect status
    let mut apps_item = AppsItem::default(&app_name, vhost_port);
    if !manifest.get_version().is_empty() {
        apps_item.set_version(&manifest.get_version());
    }
    apps_item.set_update_url(&update_url);
    apps_item.set_install_state(AppsInstallState::Installing);
    let _ = shared
        .registry
        .apply_download(&mut apps_item, &download_dir, &manifest, &path, is_update)
        .map_err(|_| AppsActorError::WrongRegistration)?;
    if is_update {
        shared
            .registry
            .event_broadcaster
            .broadcast_app_updated(AppsObject::from(&apps_item));
        shared.vhost_api.app_updated(&app_name);
    } else {
        shared
            .registry
            .event_broadcaster
            .broadcast_app_installed(AppsObject::from(&apps_item));
        shared.vhost_api.app_installed(&app_name);
    }
    Ok(())
}
pub fn install_package ( shared_data : & Shared < AppsSharedData > , from_path : & Path , manifest : & Manifest , ) -> Result < ( ) , AppsActorError > { let data_path = { let shared = shared_data . lock ( ) ; shared . config . data_path . clone ( ) } ; let path = Path :: new ( & data_path ) ; if ! from_path . is_file ( ) { return Err ( AppsActorError :: PackageMissing ) ; } if ! path . is_dir ( ) { return Err ( AppsActorError :: InstallationDirNotFound ) ; } let mut shared = shared_data . lock ( ) ; let app_name = sanitize_filename :: sanitize ( manifest . get_name ( ) ) . to_lowercase ( ) ; let update_url = format ! ( " " app_name ) ; let app_name = shared . registry . get_unique_name ( & manifest . get_name ( ) , & update_url ) . map_err ( | _ | AppsActorError :: InvalidAppName ) ? ; let download_dir = path . join ( & format ! ( " " app_name ) ) ; let download_app = download_dir . join ( " " ) ; fs :: create_dir_all ( download_dir . as_path ( ) ) ? ; fs :: copy ( from_path , download_app . as_path ( ) ) ? ; let is_update = shared . registry . get_by_update_url ( & update_url ) . is_some ( ) ; let vhost_port = shared . registry . get_vhost_port ( ) ; // Need create appsItem object and add to db to reflect status let mut apps_item = AppsItem :: default ( & app_name , vhost_port ) ; if ! manifest . get_version ( ) . is_empty ( ) { apps_item . set_version ( & manifest . get_version ( ) ) ; } apps_item . set_update_url ( & update_url ) ; apps_item . set_install_state ( AppsInstallState :: Installing ) ; let _ = shared . registry . apply_download ( & mut apps_item , & download_dir , & manifest , & path , is_update ) . map_err ( | _ | AppsActorError :: WrongRegistration ) ? ; if is_update { shared . registry . event_broadcaster . broadcast_app_updated ( AppsObject :: from ( & apps_item ) ) ; shared . vhost_api . app_updated ( & app_name ) ; } else { shared . registry . event_broadcaster . broadcast_app_installed ( AppsObject :: from ( & apps_item ) ) ; shared . vhost_api . app_installed ( & app_name ) ; } Ok ( ( ) ) }
Read valid application from from_path.
Read valid application from from_path .
shared_data
&Shared<AppsSharedData>
from_path
&Path
manifest
&Manifest
shared_data
&Shared<AppsSharedData>
from_path
&Path
manifest
&Manifest