Przeglądaj źródła

【修复】软件包递归添加文件夹内文件时无法解析路径

PJ568 1 rok temu
rodzic
commit
b5ce7a6fd7
3 zmienionych plików z 25 dodań i 7 usunięć
  1. 1 1
      Cargo.lock
  2. 1 1
      Cargo.toml
  3. 23 5
      src/fsxg.rs

+ 1 - 1
Cargo.lock

@@ -891,7 +891,7 @@ checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d"
 
 [[package]]
 name = "pageos-pkgr"
-version = "2.0.2"
+version = "2.0.3"
 dependencies = [
  "anyhow",
  "clap",

+ 1 - 1
Cargo.toml

@@ -1,6 +1,6 @@
 [package]
 name = "pageos-pkgr"
-version = "2.0.2"
+version = "2.0.3"
 authors = ["PJ568 <[email protected]>"]
 edition = "2024"
 license = "MPL-2.0"

+ 23 - 5
src/fsxg.rs

@@ -138,7 +138,16 @@ pub fn get_directory_files<P: AsRef<Path>>(path: P, recursive: bool) -> Result<V
             .filter_map(|e| e.ok())
         {
             if entry.file_type().is_file() {
-                files.push(entry.into_path());
+                let file_path = entry.into_path();
+                // 确保返回绝对路径
+                let abs_path = if file_path.is_absolute() {
+                    file_path
+                } else {
+                    // 将相对路径转换为绝对路径
+                    std::fs::canonicalize(&file_path)
+                        .with_context(|| format!("无法解析路径: {:?}", file_path))?
+                };
+                files.push(abs_path);
             }
         }
     } else {
@@ -147,10 +156,19 @@ pub fn get_directory_files<P: AsRef<Path>>(path: P, recursive: bool) -> Result<V
             fs::read_dir(path).with_context(|| format!("无法读取目录: {}", path.display()))?
         {
             let entry = entry.with_context(|| format!("无法读取目录条目: {}", path.display()))?;
-            let path = entry.path();
-
-            if path.is_file() {
-                files.push(path);
+            let entry_path = entry.path();
+            // 确保返回绝对路径
+            let abs_path = if entry_path.is_absolute() {
+                entry_path
+            } else {
+                let full_path = path.join(&entry_path);
+                // 将相对路径转换为绝对路径
+                std::fs::canonicalize(&full_path)
+                    .with_context(|| format!("无法解析路径: {:?}", full_path))?
+            };
+
+            if abs_path.is_file() {
+                files.push(abs_path);
             }
         }
     }