浏览代码

fix(cli): Truncate BuildTask.kt before writing (#9015)

* truncate BuildTask.kt before write

* Create truncate-before-write-buildtask.md

* remove unused checks

---------

Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
i-c-b 1 年之前
父节点
当前提交
b658ded614

+ 6 - 0
.changes/truncate-before-write-buildtask.md

@@ -0,0 +1,6 @@
+---
+"tauri-cli": patch:bug
+"@tauri-apps/cli": patch:bug
+---
+
+Fixes truncation of existing BuildTask.kt when running `tauri android init`.

+ 3 - 1
tooling/cli/src/mobile/android/project.rs

@@ -211,7 +211,9 @@ fn generate_out_file(
     options.mode(0o755);
   }
 
-  if path.file_name().unwrap() == OsStr::new("BuildTask.kt") || !path.exists() {
+  if path.file_name().unwrap() == OsStr::new("BuildTask.kt") {
+    options.truncate(true).create(true).open(path).map(Some)
+  } else if !path.exists() {
     options.create(true).open(path).map(Some)
   } else {
     Ok(None)

+ 1 - 1
tooling/cli/src/mobile/ios/project.rs

@@ -155,7 +155,7 @@ pub fn gen(
       let mut options = OpenOptions::new();
       options.write(true);
 
-      if path.file_name().unwrap() == OsStr::new("BuildTask.kt") || !path.exists() {
+      if !path.exists() {
         options.create(true).open(path).map(Some)
       } else {
         Ok(None)

+ 1 - 1
tooling/cli/src/plugin/init.rs

@@ -274,7 +274,7 @@ pub fn generate_android_out_file(
     options.mode(0o755);
   }
 
-  if path.file_name().unwrap() == OsStr::new("BuildTask.kt") || !path.exists() {
+  if !path.exists() {
     options.create(true).open(path).map(Some)
   } else {
     Ok(None)