ruki 2 місяців тому
батько
коміт
0bf88dfbdc

+ 6 - 0
docs/api/scripts/builtin-modules/os.md

@@ -53,6 +53,12 @@ Under 2.5.7, the parameter `{symlink = true}` is added to keep the symbolic link
 os.cp("/xxx/foo", "/xxx/bar", {symlink = true})
 ```
 
+Since v3.0.4, the parameter `{copy_if_different = true}` is added to copy files only when the source and destination file contents differ. If the file contents are the same, the copy operation will be skipped, preserving the destination file's metadata such as mtime. This helps avoid unnecessary incremental builds.
+
+```lua
+os.cp("$(scriptdir)/config.h", "$(builddir)/inc/config.h", {copy_if_different = true})
+```
+
 ## os.mv
 
 - Move to rename a file or directory

+ 6 - 0
docs/zh/api/scripts/builtin-modules/os.md

@@ -52,6 +52,12 @@ os.cp("src/**.h", "/tmp/", {rootdir = "src"})
 os.cp("/xxx/foo", "/xxx/bar", {symlink = true})
 ```
 
+v3.0.4 以上版本,新增 `{copy_if_different = true}` 参数,仅在源文件和目标文件内容不同时才执行复制操作。如果文件内容相同,则不会重新复制,这样可以保持目标文件的 mtime 等元数据不变,避免不必要的增量构建。
+
+```lua
+os.cp("$(scriptdir)/config.h", "$(builddir)/inc/config.h", {copy_if_different = true})
+```
+
 ## os.mv
 
 - 移动重命名文件或目录