mirror of
https://github.com/RubyMetric/chsrc
synced 2025-10-11 15:13:29 +08:00
改进 chsrc_overwrite_file 函数
This commit is contained in:
@@ -1781,16 +1781,26 @@ chsrc_overwrite_file (const char *str, const char *filename)
|
|||||||
char *dir = xy_parent_dir (file);
|
char *dir = xy_parent_dir (file);
|
||||||
chsrc_ensure_dir (dir);
|
chsrc_ensure_dir (dir);
|
||||||
|
|
||||||
char *cmd = NULL;
|
FILE *f = fopen (file, "w");
|
||||||
if (xy.on_windows)
|
if (NULL==f)
|
||||||
{
|
{
|
||||||
cmd = xy_strcat (4, "echo ", str, " > ", file);
|
char *msg = ENGLISH ? xy_2strcat ("Unable to open file to overwrite: ", file)
|
||||||
|
: xy_2strcat ("无法打开文件以覆盖: ", file);
|
||||||
|
chsrc_error2 (msg);
|
||||||
|
exit (Exit_UserCause);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
size_t len = strlen (str);
|
||||||
|
size_t ret = fwrite (str, len, 1, f);
|
||||||
|
if (ret != 1)
|
||||||
{
|
{
|
||||||
cmd = xy_strcat (4, "echo '", str, "' > ", file);
|
char *msg = ENGLISH ? xy_2strcat ("Write failed to ", file)
|
||||||
|
: xy_2strcat ("写入文件失败: ", file);
|
||||||
|
chsrc_error2 (msg);
|
||||||
|
exit (Exit_UserCause);
|
||||||
}
|
}
|
||||||
chsrc_run_as_a_service (cmd);
|
|
||||||
|
fclose (f);
|
||||||
|
|
||||||
log_anyway:
|
log_anyway:
|
||||||
/* 输出recipe指定的文件名 */
|
/* 输出recipe指定的文件名 */
|
||||||
|
Reference in New Issue
Block a user