Skip to content

Commit

Permalink
♻️ Synced Soar 📦 <-- feat(install): implement install with pkg_id ⌚
Browse files Browse the repository at this point in the history
  • Loading branch information
Azathothas committed Jan 20, 2025
1 parent 906498a commit 968e5f3
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 50 deletions.
2 changes: 1 addition & 1 deletion .github/LATEST.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
937a447dcde90e1c630c54866a405d7a9613331b
f8573a1689f74b08bb87caa32a937d7fb1fb5e1d
85 changes: 61 additions & 24 deletions soar-cli/src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,37 +110,74 @@ fn resolve_packages(
let filters = query.create_filter();

let options = QueryOptions {
limit: 1,
limit: if query.name.is_none() && query.pkg_id.is_some() {
u32::MAX
} else {
1
},
filters,
..Default::default()
};

let installed_packages = get_installed_packages(core_db.clone(), options.clone())?.items;
let existing_install = if installed_packages.is_empty() {
None
} else {
Some(installed_packages.first().unwrap().clone())
};

if let Some(ref existing) = existing_install {
if existing.is_installed {
warn!(
"{} is already installed - {}",
package,
if force { "reinstalling" } else { "skipping" }
);
if !force {
continue;
if query.name.is_none() && query.pkg_id.is_some() {
for pkg in get_packages(db.clone(), options.clone())?.items {
let existing_install = installed_packages
.iter()
.find(|ip| ip.pkg_name == pkg.pkg_name)
.cloned();
if let Some(ref existing) = existing_install {
if existing.detached {
continue;
}
if existing.is_installed {
warn!(
"{} is already installed - {}",
package,
if force { "reinstalling" } else { "skipping" }
);
if !force {
continue;
}
}
}

install_targets.push(InstallTarget {
package: pkg,
existing_install,
with_pkg_id: true,
});
}
} else {
let existing_install = if installed_packages.is_empty() {
None
} else {
Some(installed_packages.first().unwrap().clone())
};

if let Some(ref existing) = existing_install {
if existing.is_installed {
warn!(
"{} is already installed - {}",
package,
if force { "reinstalling" } else { "skipping" }
);
if !force {
continue;
}
}
}
}

if let Some(package) = select_package(db.clone(), package, options, yes, &existing_install)?
{
install_targets.push(InstallTarget {
package,
existing_install,
});
if let Some(package) =
select_package(db.clone(), package, options, yes, &existing_install)?
{
install_targets.push(InstallTarget {
package,
existing_install,
with_pkg_id: false,
});
}
}
}

Expand Down Expand Up @@ -322,7 +359,7 @@ async fn install_single_package(

let install_dir = get_config().get_packages_path().unwrap().join(format!(
"{}-{}-{}",
target.package.pkg, target.package.pkg_id, rand_str
target.package.pkg_name, target.package.pkg_id, rand_str
));
let real_bin = install_dir.join(&target.package.pkg_name);
let def_bin_path = bin_dir.join(&target.package.pkg_name);
Expand All @@ -345,7 +382,7 @@ async fn install_single_package(
&install_dir,
Some(progress_callback),
core_db,
false,
target.with_pkg_id,
)
.await?;

Expand Down
17 changes: 9 additions & 8 deletions soar-cli/src/remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,17 @@ pub async fn remove_packages(packages: &[String]) -> SoarResult<()> {
continue;
}

let installed_pkg = installed_pkgs.first().unwrap();
if !installed_pkg.is_installed {
warn!("Package {} is not installed.", package);
continue;
}
for installed_pkg in installed_pkgs {
if !installed_pkg.is_installed {
warn!("Package {} is not installed.", package);
continue;
}

let remover = PackageRemover::new(installed_pkg.clone(), core_db).await;
remover.remove().await?;
let remover = PackageRemover::new(installed_pkg.clone(), core_db.clone()).await;
remover.remove().await?;

info!("Removed {}", installed_pkg.pkg_name);
info!("Removed {}", installed_pkg.pkg_name);
}
}

Ok(())
Expand Down
4 changes: 4 additions & 0 deletions soar-cli/src/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ pub async fn update_packages(packages: Option<Vec<String>>) -> SoarResult<()> {
};
let updated = get_packages(repo_db.clone(), options)?.items;
if updated.len() > 0 {
let with_pkg_id = pkg.with_pkg_id;
update_targets.push(InstallTarget {
package: updated.first().unwrap().clone(),
existing_install: Some(pkg),
with_pkg_id,
})
}
}
Expand Down Expand Up @@ -83,9 +85,11 @@ pub async fn update_packages(packages: Option<Vec<String>>) -> SoarResult<()> {
};
let updated = get_packages(repo_db.clone(), options)?.items;
if updated.len() > 0 {
let with_pkg_id = pkg.with_pkg_id;
update_targets.push(InstallTarget {
package: updated.first().unwrap().clone(),
existing_install: Some(pkg),
with_pkg_id,
})
}
}
Expand Down
4 changes: 3 additions & 1 deletion soar-core/migrations/core/V1_initial.sql
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ CREATE TABLE packages (
profile TEXT NOT NULL,
pinned BOOLEAN NOT NULL DEFAULT false,
is_installed BOOLEAN NOT NULL DEFAULT false,
installed_with_family BOOLEAN NOT NULL DEFAULT false,
with_pkg_id BOOLEAN NOT NULL DEFAULT false,
detached BOOLEAN NOT NULL DEFAULT false,
unlinked BOOLEAN NOT NULL DEFAULT false,
provides JSONB
);
4 changes: 3 additions & 1 deletion soar-core/src/database/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ pub struct InstalledPackage {
pub profile: String,
pub pinned: bool,
pub is_installed: bool,
pub installed_with_family: bool,
pub with_pkg_id: bool,
pub detached: bool,
pub unlinked: bool,
pub provides: Option<Vec<PackageProvide>>,
}

Expand Down
6 changes: 4 additions & 2 deletions soar-core/src/database/packages/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ pub fn map_installed_package(row: &Row) -> rusqlite::Result<InstalledPackage> {
let value: String = row.get(idx)?;
Ok(serde_json::from_str(&value).ok())
};
let provides = parse_provides(18)?;
let provides = parse_provides(20)?;

Ok(InstalledPackage {
id: row.get(0)?,
Expand All @@ -435,7 +435,9 @@ pub fn map_installed_package(row: &Row) -> rusqlite::Result<InstalledPackage> {
profile: row.get(14)?,
pinned: row.get(15)?,
is_installed: row.get(16)?,
installed_with_family: row.get(17)?,
with_pkg_id: row.get(17)?,
detached: row.get(18)?,
unlinked: row.get(19)?,
provides,
})
}
23 changes: 17 additions & 6 deletions soar-core/src/package/formats/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ pub async fn integrate_remote<P: AsRef<Path>>(
let desktop_url = &package.desktop;

let mut icon_output_path = package_path.join(".DirIcon");
let desktop_output_path = package_path.join(format!("{}.desktop", package.pkg));
let desktop_output_path = package_path.join(format!("{}.desktop", package.pkg_name));

let downloader = Downloader::default();

Expand All @@ -153,7 +153,7 @@ pub async fn integrate_remote<P: AsRef<Path>>(
} else {
"svg"
};
icon_output_path = package_path.join(format!("{}.{}", package.pkg, ext));
icon_output_path = package_path.join(format!("{}.{}", package.pkg_name, ext));
}

if let Some(desktop_url) = desktop_url {
Expand Down Expand Up @@ -245,16 +245,27 @@ pub async fn integrate_package<P: AsRef<Path>>(
let install_dir = install_dir.as_ref();
let bin_path = install_dir.join(&package.pkg_name);

let desktop_path = PathBuf::from(format!("{}/{}.desktop", install_dir.display(), package.pkg));
let desktop_path = PathBuf::from(format!(
"{}/{}.desktop",
install_dir.display(),
package.pkg_name
));
let mut desktop_path = if desktop_path.exists() {
Some(desktop_path)
} else {
None
};

let icon_path = PathBuf::from(format!("{}/{}.png", install_dir.display(), package.pkg));
let icon_path_fallback =
PathBuf::from(format!("{}/{}.svg", install_dir.display(), package.pkg));
let icon_path = PathBuf::from(format!(
"{}/{}.png",
install_dir.display(),
package.pkg_name
));
let icon_path_fallback = PathBuf::from(format!(
"{}/{}.svg",
install_dir.display(),
package.pkg_name
));
let mut icon_path = if icon_path.exists() {
Some(icon_path)
} else if icon_path_fallback.exists() {
Expand Down
15 changes: 8 additions & 7 deletions soar-core/src/package/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ pub struct PackageInstaller {
install_dir: PathBuf,
progress_callback: Option<Arc<dyn Fn(DownloadState) + Send + Sync>>,
db: Arc<Mutex<Connection>>,
installed_with_family: bool,
with_pkg_id: bool,
}

#[derive(Clone)]
pub struct InstallTarget {
pub package: Package,
pub existing_install: Option<InstalledPackage>,
pub with_pkg_id: bool,
}

impl PackageInstaller {
Expand All @@ -33,7 +34,7 @@ impl PackageInstaller {
install_dir: P,
progress_callback: Option<Arc<dyn Fn(DownloadState) + Send + Sync>>,
db: Arc<Mutex<Connection>>,
installed_with_family: bool,
with_pkg_id: bool,
) -> SoarResult<Self> {
let install_dir = install_dir.as_ref().to_path_buf();
let package = &target.package;
Expand All @@ -56,12 +57,12 @@ impl PackageInstaller {
conn,
"INSERT INTO packages (
repo_name, pkg, pkg_id, pkg_name, version, size, checksum,
installed_path, installed_with_family, profile
installed_path, with_pkg_id, profile
)
VALUES
(
$repo_name, $pkg, $pkg_id, $pkg_name, $version, $size, $checksum,
$installed_path, $installed_with_family, $profile
$installed_path, $with_pkg_id, $profile
)"
);
stmt.raw_execute()?;
Expand All @@ -72,7 +73,7 @@ impl PackageInstaller {
install_dir,
progress_callback,
db: db.clone(),
installed_with_family,
with_pkg_id,
})
}

Expand Down Expand Up @@ -130,7 +131,7 @@ impl PackageInstaller {
} = package;
let provides = serde_json::to_string(&package.provides).unwrap();

let installed_with_family = self.installed_with_family;
let with_pkg_id = self.with_pkg_id;
let mut stmt = prepare_and_bind!(
conn,
"UPDATE packages
Expand All @@ -142,7 +143,7 @@ impl PackageInstaller {
installed_date = datetime(),
is_installed = true,
provides = $provides,
installed_with_family = $installed_with_family
with_pkg_id = $with_pkg_id
WHERE
pkg_name = $pkg_name
AND
Expand Down

0 comments on commit 968e5f3

Please sign in to comment.