From 434156b4d7e1db923b747dfbe27db21ff47b0978 Mon Sep 17 00:00:00 2001 From: zhuhongtao66 Date: Fri, 10 Mar 2023 12:05:50 +0800 Subject: [PATCH] Modified listFile interface Signed-off-by: zhuhongtao66 --- .../js/src/mod_fs/class_stream/stream_n_exporter.cpp | 4 ++-- .../kits/js/src/mod_fs/properties/listfile.cpp | 12 +++++------- interfaces/kits/js/src/mod_fs/properties/open.cpp | 2 +- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/interfaces/kits/js/src/mod_fs/class_stream/stream_n_exporter.cpp b/interfaces/kits/js/src/mod_fs/class_stream/stream_n_exporter.cpp index 4ed5f43e1..5d2fc15ec 100644 --- a/interfaces/kits/js/src/mod_fs/class_stream/stream_n_exporter.cpp +++ b/interfaces/kits/js/src/mod_fs/class_stream/stream_n_exporter.cpp @@ -130,7 +130,7 @@ napi_value StreamNExporter::WriteSync(napi_env env, napi_callback_info cbInfo) } size_t writeLen = fwrite(buf, 1, len, filp); - if (writeLen == 0 && writeLen != len) { + if (writeLen == 0 && writeLen != static_cast(len)) { HILOGE("Failed to fwrite stream"); NError(EIO).ThrowErr(env); return nullptr; @@ -187,7 +187,7 @@ napi_value StreamNExporter::Write(napi_env env, napi_callback_info cbInfo) return NError(errno); } arg->actLen = fwrite(buf, 1, len, filp); - if (arg->actLen == 0 && arg->actLen != len) { + if (arg->actLen == 0 && arg->actLen != static_cast(len)) { HILOGE("Failed to fwrite stream"); return NError(EIO); } diff --git a/interfaces/kits/js/src/mod_fs/properties/listfile.cpp b/interfaces/kits/js/src/mod_fs/properties/listfile.cpp index 6bde0f86d..375b0e4cc 100755 --- a/interfaces/kits/js/src/mod_fs/properties/listfile.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/listfile.cpp @@ -151,11 +151,9 @@ static bool GetOptionArg(napi_env env, const NFuncArg &funcArg, OptionArgs &opti static bool FilterSuffix(const vector& suffixs, const struct dirent& filename) { - for (auto iter = suffixs.begin(); iter != suffixs.end(); iter++) { - string_view sv1(*iter); - string_view sv2((string(filename.d_name)).substr((string(filename.d_name)).find('.'), - (string(filename.d_name)).length() - 1)); - if (sv1 != sv2) { + for (const auto &iter : suffixs) { + string suffixStr = string(filename.d_name).substr((string(filename.d_name)).rfind('.')); + if (iter != suffixStr) { return true; } } @@ -164,8 +162,8 @@ static bool FilterSuffix(const vector& suffixs, const struct dirent& fil static bool FilterDisplayname(const vector& displaynames, const struct dirent& filename) { - for (auto iter = displaynames.begin(); iter != displaynames.end(); iter++) { - int ret = fnmatch((*iter).c_str(), filename.d_name, FNM_PATHNAME | FNM_PERIOD); + for (const auto &iter : displaynames) { + int ret = fnmatch(iter.c_str(), filename.d_name, FNM_PATHNAME | FNM_PERIOD); if (ret == 0) { return true; } diff --git a/interfaces/kits/js/src/mod_fs/properties/open.cpp b/interfaces/kits/js/src/mod_fs/properties/open.cpp index 65f0701f8..1bb4350f0 100644 --- a/interfaces/kits/js/src/mod_fs/properties/open.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/open.cpp @@ -72,7 +72,7 @@ static NVal InstantiateFile(napi_env env, int fd, string pathOrUri, bool isUri) NError(EIO).ThrowErr(env); return NVal(); } - auto fdg = make_unique(fd, false); + auto fdg = make_unique(fd, true); fileEntity->fd_.swap(fdg); if (isUri) { fileEntity->path_ = ""; -- Gitee