diff --git a/Cargo.lock b/Cargo.lock index ec62f72b..feeca702 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -543,7 +543,6 @@ dependencies = [ "flate2 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)", "fs_extra 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "git2 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", - "globset 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", "hex 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "ignore 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", "nextcloud_appinfo 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index d3b74eaa..f084a248 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,6 @@ flate2 = "1.0" hex = "0.4" ignore = "0.4.11" git2 = "0.11" -globset = "0.4.4" nextcloud_appinfo = "0.5.0" nextcloud_appsignature = "0.4.0" nextcloud_appstore = "0.6.0" diff --git a/src/config/app.rs b/src/config/app.rs index c30196ca..373d7994 100644 --- a/src/config/app.rs +++ b/src/config/app.rs @@ -55,23 +55,18 @@ impl Into for ParsedAppConfig { #[derive(Debug)] pub struct PackageConfig { before_cmds: Vec, - exclude: Vec, } impl PackageConfig { pub fn before_cmds(&self) -> &Vec { &self.before_cmds } - pub fn exclude(&self) -> &Vec { - &self.exclude - } } impl Into for ParsedPackageConfig { fn into(self) -> PackageConfig { PackageConfig { before_cmds: self.before_cmds.unwrap_or(vec![]), - exclude: self.exclude.unwrap_or(vec![]), } } } @@ -80,12 +75,6 @@ impl Default for PackageConfig { fn default() -> Self { PackageConfig { before_cmds: vec![], - exclude: vec![ - ".git".to_owned(), - ".gitignore".to_owned(), - "build".to_owned(), - "tests".to_owned(), - ], } } } diff --git a/src/packaging/exclude.rs b/src/packaging/exclude.rs deleted file mode 100644 index e586d7ff..00000000 --- a/src/packaging/exclude.rs +++ /dev/null @@ -1,64 +0,0 @@ -use std::path::Path; -use std::vec::Vec; - -use failure::Error; -use globset; -use pathdiff::diff_paths; - -pub struct ExcludedFiles { - glob: globset::GlobSet, -} - -impl ExcludedFiles { - pub fn new(excludes: &Vec) -> Result { - let mut builder = globset::GlobSetBuilder::new(); - for excl in excludes { - let glob = globset::GlobBuilder::new(excl) - .literal_separator(true) - .build() - .map_err(|_| format_err!("could not build exclude for {}", excl))?; - builder.add(glob); - } - let set = builder - .build() - .map_err(|e| format_err!("could not build glob set: {}", e))?; - - Ok(ExcludedFiles { glob: set }) - } - - pub fn is_excluded(&self, path: &Path, base: &Path) -> bool { - diff_paths(path, base) - .map(|normalized| !self.glob.matches(&normalized).is_empty()) - .unwrap_or(false) - } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_build_glob() { - let rules = vec![".git".to_string()]; - - let excludes = ExcludedFiles::new(&rules); - - assert!(excludes.is_ok()); - } - - #[test] - fn test_path_separator() { - let rules = vec!["js/*.js".to_string()]; - - let excludes = ExcludedFiles::new(&rules).unwrap(); - - assert!(!excludes.is_excluded( - &Path::new("build/artefacts/app/js/build/build.js"), - &Path::new("build/artefacts/app") - )); - assert!(excludes.is_excluded( - &Path::new("build/artefacts/app/js/init.js"), - &Path::new("build/artefacts/app") - )); - } -} diff --git a/src/packaging/mod.rs b/src/packaging/mod.rs index 334320bc..ccf1e64b 100644 --- a/src/packaging/mod.rs +++ b/src/packaging/mod.rs @@ -6,7 +6,6 @@ use failure::Error; mod archive; mod artifacts; mod commands; -mod exclude; mod pipeline; use crate::packaging::pipeline::App; diff --git a/src/packaging/pipeline.rs b/src/packaging/pipeline.rs index 423bc8e9..1c175109 100644 --- a/src/packaging/pipeline.rs +++ b/src/packaging/pipeline.rs @@ -11,7 +11,7 @@ use tempdir::TempDir; use crate::config; use crate::packaging::commands::{self, PackageCommands}; -use crate::packaging::{archive, artifacts, exclude}; +use crate::packaging::{archive, artifacts}; fn tmp_app_path(base: &Path, app_id: &str) -> PathBuf { let mut buf = base.to_path_buf(); @@ -91,6 +91,9 @@ impl AppWithDependencies { Some(config) => (config, false), None => (config::app::AppConfig::default(), true), }; + if !default && !config.package().before_cmds().is_empty() { + bail!("The exclude array in krankerl.toml was removed in 0.12. Use a .nextcloudignore instead.") + } let cmds = commands::CommandList::from(config.package()); cmds.execute(&tmp_app_path(&self.tmp_dir.path(), self.app_info.id()))?; @@ -99,30 +102,26 @@ impl AppWithDependencies { } else { println!("App built"); } - Ok(BuiltApp::new(self, config)) + Ok(BuiltApp::new(self)) } } pub struct BuiltApp { app: App, app_info: AppInfo, - config: config::app::AppConfig, tmp_dir: TempDir, } impl BuiltApp { - pub fn new(with_deps: AppWithDependencies, config: config::app::AppConfig) -> Self { + pub fn new(with_deps: AppWithDependencies) -> Self { BuiltApp { app: with_deps.app, app_info: with_deps.app_info, - config: config, tmp_dir: with_deps.tmp_dir, } } pub fn into_archive(self) -> Result { - let excludes = exclude::ExcludedFiles::new(self.config.package().exclude())?; - let mut compressed_archive_path = self.app.source_path.to_path_buf(); compressed_archive_path.push("build"); compressed_archive_path.push("artifacts"); @@ -138,7 +137,7 @@ impl BuiltApp { { let base = Path::new(self.app_info.id()); - let file_list = build_file_list(&app_path, &excludes); + let file_list = build_file_list(&app_path); let encoder = archive::build_app_archive(&base, &app_path, file_list, encoder)?; encoder.finish()?; } @@ -158,8 +157,7 @@ impl BuiltApp { let app_path = tmp_app_path(self.tmp_dir.path(), self.app_info.id()); { - let excludes = exclude::ExcludedFiles::new(self.config.package().exclude())?; - for entry in build_file_list(&app_path, &excludes) { + for entry in build_file_list(&app_path) { if !entry.metadata().unwrap().is_dir() { let entry_path = entry.path(); if let Some(normalized) = diff_paths(&entry_path, &app_path) { @@ -179,16 +177,12 @@ impl BuiltApp { } } -fn build_file_list(build_path: &Path, excludes: &exclude::ExcludedFiles) -> Vec { +fn build_file_list(build_path: &Path) -> Vec { WalkBuilder::new(build_path) .standard_filters(false) .add_custom_ignore_filename(".nextcloudignore") .build() .into_iter() - .filter(|e| match e { - Ok(entry) => !excludes.is_excluded(entry.path(), build_path), - Err(_) => false, - }) .map(|e| e.unwrap()) .collect() }