From 49159dc0aa143e6d4e1197af9f04f330a145935a Mon Sep 17 00:00:00 2001 From: 18721213663 Date: Tue, 5 Dec 2023 09:56:23 +0800 Subject: [PATCH 1/2] fs_adapt_pc Signed-off-by: 18721213663 --- interfaces/kits/js/src/mod_fs/common_func.cpp | 14 ++++++++++++++ interfaces/kits/js/src/mod_fs/common_func.h | 5 ++++- interfaces/kits/js/src/mod_fs/module.cpp | 4 ++++ .../js/src/mod_fs/properties/prop_n_exporter.cpp | 2 +- .../js/src/mod_fs/properties/prop_n_exporter.h | 2 +- 5 files changed, 24 insertions(+), 3 deletions(-) diff --git a/interfaces/kits/js/src/mod_fs/common_func.cpp b/interfaces/kits/js/src/mod_fs/common_func.cpp index 4118a6f1f..5054b99d4 100644 --- a/interfaces/kits/js/src/mod_fs/common_func.cpp +++ b/interfaces/kits/js/src/mod_fs/common_func.cpp @@ -30,6 +30,7 @@ #include "class_file/file_n_exporter.h" #include "class_stream/stream_entity.h" #include "class_stream/stream_n_exporter.h" +#include "parameter.h" #endif #include "filemgmt_libhilog.h" #include "filemgmt_libn.h" @@ -106,6 +107,19 @@ void InitWhenceType(napi_env env, napi_value exports) } } +#if !defined(WIN_PLATFORM) && !defined(IOS_PLATFORM) +string GetDeviceType() +{ + char deviceType[BUFFER_1K]; + int32_t ret = GetParameter("const.product.devicetype", "0", deviceType, BUFFER_1K); + if (ret < 0) { + HILOG_ERROR("Get deviceType fail. %{public}d", ret); + return ""; + } + return string(deviceType, ret); +} +#endif + static tuple GetActualLen(napi_env env, size_t bufLen, size_t bufOff, NVal op) { bool succ = false; diff --git a/interfaces/kits/js/src/mod_fs/common_func.h b/interfaces/kits/js/src/mod_fs/common_func.h index e9afb302b..fffcf75e5 100644 --- a/interfaces/kits/js/src/mod_fs/common_func.h +++ b/interfaces/kits/js/src/mod_fs/common_func.h @@ -51,6 +51,7 @@ constexpr unsigned int USR_SYNC = 04010000; const double NS = 1e9; const double MS = 1e3; +const int BUFFER_1K = 1024; struct FileInfo { bool isPath = false; @@ -60,7 +61,9 @@ struct FileInfo { void InitOpenMode(napi_env env, napi_value exports); void InitWhenceType(napi_env env, napi_value exports); - +#if !defined(WIN_PLATFORM) && !defined(IOS_PLATFORM) +std::string GetDeviceType(); +#endif struct CommonFunc { static unsigned int ConvertJsFlags(unsigned int &flags); static LibN::NVal InstantiateStat(napi_env env, const uv_stat_t &buf); diff --git a/interfaces/kits/js/src/mod_fs/module.cpp b/interfaces/kits/js/src/mod_fs/module.cpp index 16795efec..4448c18a2 100644 --- a/interfaces/kits/js/src/mod_fs/module.cpp +++ b/interfaces/kits/js/src/mod_fs/module.cpp @@ -25,6 +25,7 @@ #include "class_readeriterator/readeriterator_n_exporter.h" #include "class_stream/stream_n_exporter.h" #include "class_watcher/watcher_n_exporter.h" +#include "parameter.h" #endif #include "filemgmt_libhilog.h" #include "properties/prop_n_exporter.h" @@ -47,6 +48,9 @@ static napi_value Export(napi_env env, napi_value exports) products.emplace_back(make_unique(env, exports)); products.emplace_back(make_unique(env, exports)); products.emplace_back(make_unique(env, exports)); + if (GetDeviceType() == "2in1") { + PropNExporter::dirPermission_ = 0771; + } #endif for (auto &&product : products) { #ifdef WIN_PLATFORM diff --git a/interfaces/kits/js/src/mod_fs/properties/prop_n_exporter.cpp b/interfaces/kits/js/src/mod_fs/properties/prop_n_exporter.cpp index b631e7814..92f918e5f 100644 --- a/interfaces/kits/js/src/mod_fs/properties/prop_n_exporter.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/prop_n_exporter.cpp @@ -240,7 +240,7 @@ static int MkdirCore(const string &path) HILOGE("Failed to request heap memory."); return ENOMEM; } - return uv_fs_mkdir(nullptr, mkdir_req.get(), path.c_str(), DIR_DEFAULT_PERM, nullptr); + return uv_fs_mkdir(nullptr, mkdir_req.get(), path.c_str(), PropNExporter::dirPermission_, nullptr); } static NError MkdirExec(const string &path, bool recursion, bool hasOption) diff --git a/interfaces/kits/js/src/mod_fs/properties/prop_n_exporter.h b/interfaces/kits/js/src/mod_fs/properties/prop_n_exporter.h index 7333185a4..a3567fe5e 100755 --- a/interfaces/kits/js/src/mod_fs/properties/prop_n_exporter.h +++ b/interfaces/kits/js/src/mod_fs/properties/prop_n_exporter.h @@ -48,6 +48,7 @@ struct AsyncIOReadArg { class PropNExporter final : public NExporter { public: inline static const std::string className_ = "__properities__"; + inline static int dirPermission_ = 0770; static napi_value AccessSync(napi_env env, napi_callback_info info); static napi_value MkdirSync(napi_env env, napi_callback_info info); @@ -70,7 +71,6 @@ public: ~PropNExporter() override; }; -constexpr int DIR_DEFAULT_PERM = 0770; const std::string PROCEDURE_ACCESS_NAME = "FileIOAccess"; const std::string PROCEDURE_UNLINK_NAME = "FileIOUnlink"; const std::string PROCEDURE_MKDIR_NAME = "FileIOMkdir"; -- Gitee From ddfc0597badf19e86d74acb790befaf0dea5588d Mon Sep 17 00:00:00 2001 From: 18721213663 Date: Tue, 5 Dec 2023 15:43:44 +0800 Subject: [PATCH 2/2] fs_adapt_pc Signed-off-by: 18721213663 --- interfaces/kits/js/src/mod_fs/common_func.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/kits/js/src/mod_fs/common_func.cpp b/interfaces/kits/js/src/mod_fs/common_func.cpp index 5054b99d4..5c1dd83d1 100644 --- a/interfaces/kits/js/src/mod_fs/common_func.cpp +++ b/interfaces/kits/js/src/mod_fs/common_func.cpp @@ -113,7 +113,7 @@ string GetDeviceType() char deviceType[BUFFER_1K]; int32_t ret = GetParameter("const.product.devicetype", "0", deviceType, BUFFER_1K); if (ret < 0) { - HILOG_ERROR("Get deviceType fail. %{public}d", ret); + HILOGE("Get deviceType fail. %{public}d", ret); return ""; } return string(deviceType, ret); -- Gitee