Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Asset directory mounts do not work on Windows #2111

Closed
itowlson opened this issue Nov 24, 2023 · 2 comments · Fixed by #2161
Closed

Asset directory mounts do not work on Windows #2111

itowlson opened this issue Nov 24, 2023 · 2 comments · Fixed by #2161
Assignees
Milestone

Comments

@itowlson
Copy link
Contributor

The was reported by freaky.ashes on Discord - thanks to them for flagging it.

To reproduce:

  • Create a Spin app with an asset directory mount (e.g. files = [{ source = "assets", destination = "/" }])
  • Run it on Windows
  • You get a "couldn't resolve \assets<component>" error for the component asset directory, because the assets directory didn't get created

This happens because of a conflict between canonicalisation and the glob crate: when a glob is prefixed with a canonical (UNC) path, it does not match any files. (And asset directories get created only when files exist to be copied into them.) To reproduce this, create this Rust app:

use std::path::PathBuf;

fn main() {
    println!("Using plain dir");
    let bp = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
    let paths = glob::glob(bp.join("src/**/*").to_str().unwrap()).unwrap();
    for path in paths {
        println!("{path:?}");
    }

    println!("Using canonicalised dir");
    let bp = PathBuf::from(env!("CARGO_MANIFEST_DIR")).canonicalize().unwrap();
    let paths = glob::glob(bp.join("src/**/*").to_str().unwrap()).unwrap();
    for path in paths {
        println!("{path:?}");
    }
}

It prints something like

Using plain dir
Ok("D:\\Code Experiments\\globtest\\src\\main.rs")
Using canonicalised dir

This breaks directory mounts on Spin 2 because we canonicalise the source path, and use <source-path>/**/* to implement directory copying. I assume it also breaks glob mounts too but have not tested that case.

This is a known bug in the upstream glob crate: rust-lang/glob#132. The issue suggests a workaround which, although unsafe for general use, should be fine for us. Alternatively it might suffice to absolutise rather than canonicalise. The issue is 6 months old and there's no movement on it so we should not expect a fix from upstream.

@itowlson
Copy link
Contributor Author

Also, this implies we're not testing asset loading on Windows. It would be good to cover that gap - I thought those tests ran across all platforms.

@itowlson
Copy link
Contributor Author

This also affects wildcard globs, but not single-file patterns. If you have a mix that contains a single-file pattern, the app runs but the files from wildcards and directory mounts are not there, only the single files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants