rust-cached-path icon indicating copy to clipboard operation
rust-cached-path copied to clipboard

Option to preserve file extensions

Open gbin opened this issue 1 year ago • 1 comments

For example Bevy relies on file extensions to determine how to load resources:

2024-10-28T14:30:14.861250Z ERROR bevy_asset::server: Could not find an asset loader matching: Loader Name: None; Asset Type: None; Extension: None; Path: Some("/tmp/cache/cf2be431ec1de50d52a8b9cd7082ec0da11bc34685946895dffb8da215216db4#Scene0");

gbin avatar Oct 28 '24 14:10 gbin

FYI: As a workaround I did this, maybe this should be the behavior of this option?

fn create_symlink(src: &str, dst: &str) -> io::Result<()> {
    let dst_path = Path::new(dst);

    if dst_path.exists() {
        fs::remove_file(dst_path)?;
    }

    #[cfg(unix)]
    {
        std::os::unix::fs::symlink(src, dst)
    }

    #[cfg(windows)]
    {
        std::os::windows::fs::symlink_file(src, dst)
    }
}

const BASE_ASSETS_URL: &str = "https://cdn.copper-robotics.com/";
  let balance_bot_hashed = cache
        .cached_path(format!("{}{}", BASE_ASSETS_URL, BALANCEBOT).as_str())
        .expect("Failed to download and cache balancebot.glb.");
    let balance_bot_path = base_path.join(BALANCEBOT);

    create_symlink(
        balance_bot_hashed.to_str().unwrap(),
        balance_bot_path.to_str().unwrap(),
    )
    .expect("Failed to create symlink to balancebot.glb."); 

gbin avatar Oct 28 '24 15:10 gbin