From 87b0380d582f66191923f6592a510940c58da2b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9C=E9=99=B6=E9=87=91=E6=B2=9B=E2=80=9D?= Date: Thu, 17 Jul 2025 09:22:29 +0800 Subject: [PATCH] truncate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: “陶金沛” --- interfaces/kits/js/src/mod_fs/properties/truncate.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/interfaces/kits/js/src/mod_fs/properties/truncate.cpp b/interfaces/kits/js/src/mod_fs/properties/truncate.cpp index 4691f446b..1fafa81d0 100644 --- a/interfaces/kits/js/src/mod_fs/properties/truncate.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/truncate.cpp @@ -26,6 +26,7 @@ namespace OHOS::FileManagement::ModuleFileIO { using namespace std; using namespace OHOS::FileManagement::LibN; +using namespace OHOS::DistributedFS; static tuple ParseJsFile(napi_env env, napi_value pathOrFdFromJsArg) { @@ -63,13 +64,14 @@ static NError TruncateCore(napi_env env, FileInfo &fileInfo, int64_t truncateLen HILOGE("Failed to open by libuv ret %{public}d", ret); return NError(ret); } + FDGuard fd(ret); std::unique_ptr ftruncate_req = { new uv_fs_t, CommonFunc::fs_req_cleanup }; if (!ftruncate_req) { HILOGE("Failed to request heap memory."); return NError(ENOMEM); } - ret = uv_fs_ftruncate(nullptr, ftruncate_req.get(), ret, truncateLen, nullptr); + ret = uv_fs_ftruncate(nullptr, ftruncate_req.get(), fd.GetFD(), truncateLen, nullptr); if (ret < 0) { HILOGE("Failed to truncate file by path ret %{public}d", ret); return NError(ret); -- Gitee