浏览代码

Fix: Asset Cache On Windows & Asset Status (#3525)

* fix: asset caching on windows
* fix: asset status
Miles Murgaw 5 月之前
父节点
当前提交
a3812d66da

+ 2 - 0
Cargo.lock

@@ -3479,6 +3479,7 @@ dependencies = [
  "dioxus-rsx-hotreload",
  "dioxus-rsx-rosetta",
  "dirs",
+ "dunce",
  "env_logger 0.11.5",
  "escargot",
  "flate2",
@@ -7767,6 +7768,7 @@ dependencies = [
 name = "manganis-macro"
 version = "0.6.1"
 dependencies = [
+ "dunce",
  "manganis",
  "manganis-core",
  "proc-macro2",

+ 1 - 1
Cargo.toml

@@ -230,7 +230,7 @@ wry = { version = "0.45.0", default-features = false }
 tao = { version = "0.30.8", features = ["rwh_05"] }
 webbrowser = "1.0.1"
 infer = "0.16.0"
-dunce = "1.0.2"
+dunce = "1.0.5"
 urlencoding = "2.1.2"
 global-hotkey = "0.6.0"
 rfd = { version = "0.14", default-features = false }

+ 1 - 0
packages/cli/Cargo.toml

@@ -61,6 +61,7 @@ syn = { workspace = true, features = ["full", "extra-traits", "visit", "visit-mu
 
 headers = "0.4.0"
 walkdir = "2"
+dunce = { workspace = true }
 
 # tools download
 dirs = { workspace = true }

+ 9 - 7
packages/cli/src/build/bundle.rs

@@ -10,6 +10,7 @@ use std::collections::HashSet;
 use std::future::Future;
 use std::path::{Path, PathBuf};
 use std::pin::Pin;
+use std::sync::atomic::Ordering;
 use std::{sync::atomic::AtomicUsize, time::Duration};
 use tokio::process::Command;
 
@@ -394,7 +395,8 @@ impl AppBundle {
         ) -> Pin<Box<dyn Future<Output = std::io::Result<()>> + Send + 'a>> {
             Box::pin(async move {
                 // If this asset is in the manifest, we don't need to remove it
-                if bundled_output_paths.contains(path.canonicalize()?.as_path()) {
+                let canon_path = dunce::canonicalize(path)?;
+                if bundled_output_paths.contains(canon_path.as_path()) {
                     return Ok(());
                 }
                 // Otherwise, if it is a directory, we need to walk it and remove child files
@@ -438,7 +440,8 @@ impl AppBundle {
         }
 
         let asset_count = assets_to_transfer.len();
-        let current_asset = AtomicUsize::new(0);
+        let started_processing = AtomicUsize::new(0);
+        let copied = AtomicUsize::new(0);
 
         // Parallel Copy over the assets and keep track of progress with an atomic counter
         let progress = self.build.progress.clone();
@@ -447,19 +450,18 @@ impl AppBundle {
             assets_to_transfer
                 .par_iter()
                 .try_for_each(|(from, to, options)| {
-                    let current = current_asset.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
-
-                    tracing::trace!("Starting asset copy {current}/{asset_count} from {from:?}");
+                    let processing = started_processing.fetch_add(1, Ordering::SeqCst);
+                    tracing::trace!("Starting asset copy {processing}/{asset_count} from {from:?}");
 
                     let res = process_file_to(options, from, to);
-
                     if let Err(err) = res.as_ref() {
                         tracing::error!("Failed to copy asset {from:?}: {err}");
                     }
 
+                    let finished = copied.fetch_add(1, Ordering::SeqCst);
                     BuildRequest::status_copied_asset(
                         &progress,
-                        current,
+                        finished,
                         asset_count,
                         from.to_path_buf(),
                     );

+ 1 - 2
packages/cli/src/serve/handle.rs

@@ -2,7 +2,6 @@ use crate::{AppBundle, Platform, Result};
 use anyhow::Context;
 use dioxus_cli_opt::process_file_to;
 use std::{
-    fs,
     net::SocketAddr,
     path::{Path, PathBuf},
     process::Stdio,
@@ -190,7 +189,7 @@ impl AppHandle {
         }
 
         // Canonicalize the path as Windows may use long-form paths "\\\\?\\C:\\".
-        let changed_file = fs::canonicalize(changed_file)
+        let changed_file = dunce::canonicalize(changed_file)
             .inspect_err(|e| tracing::debug!("Failed to canonicalize hotreloaded asset: {e}"))
             .ok()?;
 

+ 1 - 1
packages/desktop/Cargo.toml

@@ -45,7 +45,7 @@ tokio = { workspace = true, features = [
 ], optional = true }
 webbrowser = "0.8.0"
 infer = "0.11.0"
-dunce = "1.0.2"
+dunce = { workspace = true }
 slab = { workspace = true }
 rustc-hash = { workspace = true }
 dioxus-hooks = { workspace = true }

+ 1 - 0
packages/manganis/manganis-macro/Cargo.toml

@@ -19,6 +19,7 @@ proc-macro2 = { workspace = true }
 quote = { workspace = true }
 syn = { workspace = true, features = ["full", "extra-traits"] }
 manganis-core = { workspace = true }
+dunce = { workspace = true }
 
 [features]
 default = []

+ 7 - 6
packages/manganis/manganis-macro/src/asset.rs

@@ -17,11 +17,12 @@ fn resolve_path(raw: &str) -> Result<PathBuf, AssetParseError> {
     // /users/dioxus/dev/app/
     // is the root of
     // /users/dioxus/dev/app/assets/blah.css
-    let manifest_dir = std::env::var("CARGO_MANIFEST_DIR")
-        .map(PathBuf::from)
-        .unwrap()
-        .canonicalize()
-        .unwrap();
+    let manifest_dir = dunce::canonicalize(
+        std::env::var("CARGO_MANIFEST_DIR")
+            .map(PathBuf::from)
+            .unwrap(),
+    )
+    .unwrap();
 
     // 1. the input file should be a pathbuf
     let input = PathBuf::from(raw);
@@ -34,7 +35,7 @@ fn resolve_path(raw: &str) -> Result<PathBuf, AssetParseError> {
     };
 
     // 3. Ensure the path exists
-    let Ok(path) = path.canonicalize() else {
+    let Ok(path) = dunce::canonicalize(path) else {
         return Err(AssetParseError::AssetDoesntExist {
             path: input.clone(),
         });