diff --git a/registry/src/endpoints/publish_version.rs b/registry/src/endpoints/publish_version.rs index 2e025d7..262f8f6 100644 --- a/registry/src/endpoints/publish_version.rs +++ b/registry/src/endpoints/publish_version.rs @@ -18,6 +18,7 @@ use pesde::{ pesde::{IndexFile, IndexFileEntry, ScopeInfo, SCOPE_INFO_FILE}, specifiers::DependencySpecifiers, version_id::VersionId, + IGNORED_DIRS, IGNORED_FILES, }, DEFAULT_INDEX_NAME, MANIFEST_FILE_NAME, }; @@ -53,8 +54,7 @@ fn get_refspec(repo: &Repository, remote: &mut Remote) -> Result, @@ -85,17 +85,22 @@ pub async fn publish_package( for entry in entries { let mut entry = entry?; let path = entry.path()?; - let path = path.to_str().ok_or(Error::InvalidArchive)?; if entry.header().entry_type().is_dir() { - if FORBIDDEN_DIRECTORIES.contains(&path) { + if path.components().next().is_some_and(|ct| { + ct.as_os_str() + .to_str() + .map_or(true, |s| IGNORED_DIRS.contains(&s)) + }) { return Err(Error::InvalidArchive); } continue; } - if FORBIDDEN_FILES.contains(&path) { + let path = path.to_str().ok_or(Error::InvalidArchive)?; + + if IGNORED_FILES.contains(&path) || ADDITIONAL_FORBIDDEN_FILES.contains(&path) { return Err(Error::InvalidArchive); } diff --git a/src/cli/commands/publish.rs b/src/cli/commands/publish.rs index 7128086..13ce475 100644 --- a/src/cli/commands/publish.rs +++ b/src/cli/commands/publish.rs @@ -12,7 +12,10 @@ use tempfile::tempfile; use pesde::{ manifest::target::Target, scripts::ScriptName, - source::{pesde::PesdePackageSource, specifiers::DependencySpecifiers, traits::PackageSource}, + source::{ + pesde::PesdePackageSource, specifiers::DependencySpecifiers, traits::PackageSource, + IGNORED_DIRS, IGNORED_FILES, + }, Project, DEFAULT_INDEX_NAME, MANIFEST_FILE_NAME, }; @@ -98,6 +101,19 @@ impl PublishCommand { ); } + for ignored_path in IGNORED_FILES.iter().chain(IGNORED_DIRS.iter()) { + if manifest.includes.remove(*ignored_path) { + println!( + r#"{}: {ignored_path} was in includes, removing it. +{}: if this was a toolchain manager's manifest file, do not include it due to it possibly messing with user scripts +{}: otherwise, the file was deemed unnecessary, if you don't understand why, please contact the maintainers"#, + "warn".yellow().bold(), + "info".blue().bold(), + "info".blue().bold() + ); + } + } + for (name, path) in [("lib path", lib_path), ("bin path", bin_path)] { let Some(export_path) = path else { continue }; diff --git a/src/source/git/mod.rs b/src/source/git/mod.rs index 108c40b..96e999a 100644 --- a/src/source/git/mod.rs +++ b/src/source/git/mod.rs @@ -10,7 +10,7 @@ use crate::{ fs::{store_in_cas, FSEntry, PackageFS}, git::{pkg_ref::GitPackageRef, specifier::GitDependencySpecifier}, git_index::GitBasedSource, - PackageSource, ResolveResult, VersionId, + PackageSource, ResolveResult, VersionId, IGNORED_DIRS, IGNORED_FILES, }, util::hash, Project, MANIFEST_FILE_NAME, @@ -282,11 +282,23 @@ impl PackageSource for GitPackageSource { })?; if matches!(object.kind, gix::object::Kind::Tree) { + if path + .components() + .next() + .is_some_and(|ct| IGNORED_DIRS.contains(&ct.as_str())) + { + continue; + } + entries.insert(path, FSEntry::Directory); continue; } + if IGNORED_FILES.contains(&path.as_str()) { + continue; + } + let data = object.into_blob().data.clone(); let hash = store_in_cas(project.cas_dir(), &data)?.0; diff --git a/src/source/mod.rs b/src/source/mod.rs index f1ad362..9a3105e 100644 --- a/src/source/mod.rs +++ b/src/source/mod.rs @@ -30,6 +30,12 @@ pub mod version_id; #[cfg(feature = "wally-compat")] pub mod wally; +/// Files that will not be stored when downloading a package. These are only files which break pesde's functionality, or are meaningless and possibly heavy (e.g. `.DS_Store`) +pub const IGNORED_FILES: &[&str] = &["foreman.toml", "aftman.toml", "rokit.toml", ".DS_Store"]; + +/// Directories that will not be stored when downloading a package. These are only directories which break pesde's functionality, or are meaningless and possibly heavy +pub const IGNORED_DIRS: &[&str] = &[".git"]; + /// The result of resolving a package pub type ResolveResult = (PackageNames, BTreeMap); diff --git a/src/source/pesde/mod.rs b/src/source/pesde/mod.rs index d7e7e51..e5cd2d7 100644 --- a/src/source/pesde/mod.rs +++ b/src/source/pesde/mod.rs @@ -1,3 +1,18 @@ +use std::{ + collections::{BTreeMap, BTreeSet}, + fmt::Debug, + hash::Hash, + path::PathBuf, +}; + +use gix::Url; +use relative_path::RelativePathBuf; +use reqwest::header::ACCEPT; +use serde::{Deserialize, Serialize}; + +use pkg_ref::PesdePackageRef; +use specifier::PesdeDependencySpecifier; + use crate::{ manifest::{ target::{Target, TargetKind}, @@ -7,23 +22,11 @@ use crate::{ source::{ fs::{store_reader_in_cas, FSEntry, PackageFS}, git_index::GitBasedSource, - DependencySpecifiers, PackageSource, ResolveResult, VersionId, + DependencySpecifiers, PackageSource, ResolveResult, VersionId, IGNORED_DIRS, IGNORED_FILES, }, util::hash, Project, }; -use gix::Url; -use pkg_ref::PesdePackageRef; -use relative_path::RelativePathBuf; -use reqwest::header::ACCEPT; -use serde::{Deserialize, Serialize}; -use specifier::PesdeDependencySpecifier; -use std::{ - collections::{BTreeMap, BTreeSet}, - fmt::Debug, - hash::Hash, - path::PathBuf, -}; /// The pesde package reference pub mod pkg_ref; @@ -292,11 +295,23 @@ impl PackageSource for PesdePackageSource { let path = RelativePathBuf::from_path(entry.path()?).unwrap(); if entry.header().entry_type().is_dir() { + if path + .components() + .next() + .is_some_and(|ct| IGNORED_DIRS.contains(&ct.as_str())) + { + continue; + } + entries.insert(path, FSEntry::Directory); continue; } + if IGNORED_FILES.contains(&path.as_str()) { + continue; + } + let hash = store_reader_in_cas(project.cas_dir(), &mut entry)?; entries.insert(path, FSEntry::File(hash)); } @@ -385,9 +400,10 @@ pub type IndexFile = BTreeMap; pub mod errors { use std::path::PathBuf; - use crate::source::git_index::errors::{ReadFile, TreeError}; use thiserror::Error; + use crate::source::git_index::errors::{ReadFile, TreeError}; + /// Errors that can occur when resolving a package from a pesde package source #[derive(Debug, Error)] #[non_exhaustive] diff --git a/src/source/wally/mod.rs b/src/source/wally/mod.rs index d0019d0..6f23e68 100644 --- a/src/source/wally/mod.rs +++ b/src/source/wally/mod.rs @@ -17,6 +17,7 @@ use crate::{ traits::PackageSource, version_id::VersionId, wally::{compat_util::get_target, manifest::WallyManifest, pkg_ref::WallyPackageRef}, + IGNORED_DIRS, IGNORED_FILES, }, util::hash, Project, @@ -202,17 +203,21 @@ impl PackageSource for WallyPackageSource { let path = RelativePathBuf::from_path(entry.path().strip_prefix(tempdir.path())?).unwrap(); - if path == ".git" { - continue; - } - if entry.file_type()?.is_dir() { + if IGNORED_DIRS.contains(&path.as_str()) { + continue; + } + entries.insert(path, FSEntry::Directory); dir_entries.extend(std::fs::read_dir(entry.path())?); continue; } + if IGNORED_FILES.contains(&path.as_str()) { + continue; + } + let mut file = std::fs::File::open(entry.path())?; let hash = store_reader_in_cas(project.cas_dir(), &mut file)?; entries.insert(path, FSEntry::File(hash));