Skip to content

Commit 8448830

Browse files
committed
Warn if a component file mount is likely to lead to tears
Signed-off-by: itowlson <[email protected]>
1 parent 255ed67 commit 8448830

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/loader/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ spin-locked-app = { path = "../locked-app" }
2121
spin-manifest = { path = "../manifest" }
2222
spin-serde = { path = "../serde" }
2323
tempfile = { workspace = true }
24+
terminal = { path = "../terminal" }
2425
tokio = { workspace = true }
2526
toml = { workspace = true }
2627
tracing = { workspace = true }

crates/loader/src/local.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,20 @@ impl LocalLoader {
485485
dest_root: &Path,
486486
exclude_files: &[String],
487487
) -> Result<()> {
488+
if glob_or_path == ".." || glob_or_path.ends_with("/..") {
489+
bail!("A file pattern can't end in a parent directory path (..)\nIf you want to include a directory, use source-destination form, or a glob pattern ending in **/*.\nLearn more: https://spinframework.dev/writing-apps#including-files-with-components");
490+
}
491+
if glob_or_path == "." || glob_or_path.ends_with("/.") {
492+
bail!("A file pattern can't end in a current directory path (.)\nIf you want to include a directory, use source-destination form, or a glob pattern ending in **/*.\nLearn more: https://spinframework.dev/writing-apps#including-files-with-components");
493+
}
494+
495+
if glob_or_path == "*" {
496+
terminal::warn!("A component is including the entire application directory as asset files. This is unlikely to be what you want.\nIf this is what you want, use the pattern \"./*\" to avoid this warning.\nLearn more: https://spinframework.dev/writing-apps#including-files-with-components\n");
497+
}
498+
if glob_or_path == "**/*" {
499+
terminal::warn!("A component is including the entire application directory tree as asset files. This is unlikely to be what you want.\nIf this is what you want, use the pattern \"./**/*\" to avoid this warning.\nLearn more: https://spinframework.dev/writing-apps#including-files-with-components\n");
500+
}
501+
488502
let path = self.app_root.join(glob_or_path);
489503
if path.exists() {
490504
let dest = dest_root.join(glob_or_path);

0 commit comments

Comments
 (0)