代码拉取完成,页面将自动刷新
同步操作将从 src-openEuler/iSulad 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
From 8888ca136de8f864df919f6823b357238a328488 Mon Sep 17 00:00:00 2001
From: lifeng68 <[email protected]>
Date: Tue, 10 Nov 2020 10:08:56 +0800
Subject: [PATCH 25/28] utils: add fdatasync when do atomic write file
Signed-off-by: lifeng68 <[email protected]>
---
src/utils/cutils/utils_file.c | 35 ++++++++++++++++++++++++++++++++++-
1 file changed, 34 insertions(+), 1 deletion(-)
diff --git a/src/utils/cutils/utils_file.c b/src/utils/cutils/utils_file.c
index 9f7f5fe..744b425 100644
--- a/src/utils/cutils/utils_file.c
+++ b/src/utils/cutils/utils_file.c
@@ -1403,6 +1403,39 @@ out:
return result;
}
+static int do_atomic_write_file(const char *fname, const char *content, size_t content_len, mode_t mode)
+{
+ int ret = 0;
+ int dst_fd = -1;
+ ssize_t len = 0;
+
+ dst_fd = util_open(fname, O_WRONLY | O_CREAT | O_TRUNC, mode);
+ if (dst_fd < 0) {
+ ERROR("Creat file: %s, failed: %s", fname, strerror(errno));
+ ret = -1;
+ goto free_out;
+ }
+
+ len = util_write_nointr(dst_fd, content, content_len);
+ if (len < 0 || ((size_t)len) != content_len) {
+ ret = -1;
+ ERROR("Write file failed: %s", strerror(errno));
+ goto free_out;
+ }
+
+ if (fdatasync(dst_fd) != 0) {
+ ret = -1;
+ SYSERROR("Failed to sync data of file:%s", fname);
+ goto free_out;
+ }
+
+free_out:
+ if (dst_fd >= 0) {
+ close(dst_fd);
+ }
+ return ret;
+}
+
int util_atomic_write_file(const char *fname, const char *content, size_t content_len, mode_t mode)
{
int ret = 0;
@@ -1427,7 +1460,7 @@ int util_atomic_write_file(const char *fname, const char *content, size_t conten
goto free_out;
}
- ret = util_write_file(tmp_file, content, content_len, mode);
+ ret = do_atomic_write_file(tmp_file, content, content_len, mode);
if (ret != 0) {
ERROR("Failed to write content to tmp file for %s", tmp_file);
ret = -1;
--
2.20.1
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。