From 0bbc2e4f97bb63571ade207669e16cf166de36c8 Mon Sep 17 00:00:00 2001 From: fengjq Date: Sat, 18 Nov 2023 18:43:54 +0800 Subject: [PATCH] =?UTF-8?q?SecurityLabel=E6=B7=BB=E5=8A=A0=E7=BB=B4?= =?UTF-8?q?=E6=B5=8B=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fengjq --- interfaces/kits/js/BUILD.gn | 1 + interfaces/kits/js/src/mod_securitylabel/security_label.h | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/interfaces/kits/js/BUILD.gn b/interfaces/kits/js/BUILD.gn index 9c3fbdd3c..ea7436a0c 100644 --- a/interfaces/kits/js/BUILD.gn +++ b/interfaces/kits/js/BUILD.gn @@ -365,6 +365,7 @@ ohos_shared_library("securitylabel") { cflags = [ "-Wno-format" ] + include_dirs = [ "${utils_path}/filemgmt_libhilog" ] sources = [ "src/mod_securitylabel/securitylabel_n_exporter.cpp", "src/mod_securitylabel/securitylabel_napi.cpp", diff --git a/interfaces/kits/js/src/mod_securitylabel/security_label.h b/interfaces/kits/js/src/mod_securitylabel/security_label.h index fbac9b310..9b78a3599 100644 --- a/interfaces/kits/js/src/mod_securitylabel/security_label.h +++ b/interfaces/kits/js/src/mod_securitylabel/security_label.h @@ -22,6 +22,8 @@ #include #include +#include "filemgmt_libhilog.h" + namespace OHOS { namespace FileManagement { namespace ModuleSecurityLabel { @@ -33,6 +35,7 @@ public: static bool SetSecurityLabel(const std::string &path, const std::string &dataLevel) { if (DATA_LEVEL.count(dataLevel) != 1) { + HILOGE("The parameter of data level is invalid."); return false; } #ifdef IOS_PLATFORM @@ -40,6 +43,7 @@ public: #else if (setxattr(path.c_str(), XATTR_KEY, dataLevel.c_str(), dataLevel.size(), 0) < 0) { #endif + HILOGE("Failed to set the extension properties, error %{public}d", errno); return false; } return true; @@ -53,6 +57,7 @@ public: auto xattrValueSize = getxattr(path.c_str(), XATTR_KEY, nullptr, 0); #endif if (xattrValueSize == -1 || errno == ENOTSUP) { + HILOGE("Failed to get the extension properties of the filesystem, error: %{public}d", errno); return ""; } if (xattrValueSize <= 0) { @@ -60,6 +65,7 @@ public: } std::unique_ptr xattrValue = std::make_unique((long)xattrValueSize + 1); if (xattrValue == nullptr) { + HILOGE("Failed to request heap memory."); return ""; } #ifdef IOS_PLATFORM @@ -68,6 +74,7 @@ public: xattrValueSize = getxattr(path.c_str(), XATTR_KEY, xattrValue.get(), xattrValueSize); #endif if (xattrValueSize == -1 || errno == ENOTSUP) { + HILOGE("Failed to get the extension properties of the file, error: %{public}d", errno); return ""; } if (xattrValueSize <= 0) { -- Gitee