From 78060575f405b874b4b6d2d1da111dfa65dbbd5b Mon Sep 17 00:00:00 2001 From: zhongning5 Date: Wed, 4 Dec 2024 16:42:24 +0800 Subject: [PATCH] enable atomicfile Signed-off-by: zhongning5 --- interfaces/kits/js/BUILD.gn | 1 + .../class_atomicFile/atomicFile_entity.h | 30 ++++++++++++ .../class_atomicFile/atomicFile_n_exporter.h | 47 +++++++++++++++++++ interfaces/kits/js/src/mod_fs/module.cpp | 4 +- interfaces/kits/ts/streamrw/src/streamrw.ts | 4 ++ 5 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 interfaces/kits/js/src/mod_fs/class_atomicFile/atomicFile_entity.h create mode 100644 interfaces/kits/js/src/mod_fs/class_atomicFile/atomicFile_n_exporter.h diff --git a/interfaces/kits/js/BUILD.gn b/interfaces/kits/js/BUILD.gn index 488ae6a96..80da9c020 100644 --- a/interfaces/kits/js/BUILD.gn +++ b/interfaces/kits/js/BUILD.gn @@ -215,6 +215,7 @@ ohos_shared_library("fs") { "${filemanagement_service_path}/distributedfiledaemon/include/ipc", ] sources += [ + "src/mod_fs/class_atomicFile/atomicFile_n_exporter.cpp", "src/mod_fs/class_randomaccessfile/randomaccessfile_n_exporter.cpp", "src/mod_fs/class_readeriterator/readeriterator_n_exporter.cpp", "src/mod_fs/class_stream/stream_n_exporter.cpp", diff --git a/interfaces/kits/js/src/mod_fs/class_atomicFile/atomicFile_entity.h b/interfaces/kits/js/src/mod_fs/class_atomicFile/atomicFile_entity.h new file mode 100644 index 000000000..14dccc140 --- /dev/null +++ b/interfaces/kits/js/src/mod_fs/class_atomicFile/atomicFile_entity.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef INTERFACES_KITS_JS_SRC_MOD_FS_CLASS_ATOMIC_FILE_ENTITY_H +#define INTERFACES_KITS_JS_SRC_MOD_FS_CLASS_ATOMIC_FILE_ENTITY_H + +namespace OHOS { +namespace FileManagement { +namespace ModuleFileIO { +struct AtomicFileEntity { + std::string baseFileName = ""; + std::string newFileName = ""; + napi_ref writeStreamObj = nullptr; +}; +} // namespace ModuleFileIO +} // namespace FileManagement +} // namespace OHOS +#endif // INTERFACES_KITS_JS_SRC_MOD_FILEIO_CLASS_ATOMIC_FILE_ENTITY_H \ No newline at end of file diff --git a/interfaces/kits/js/src/mod_fs/class_atomicFile/atomicFile_n_exporter.h b/interfaces/kits/js/src/mod_fs/class_atomicFile/atomicFile_n_exporter.h new file mode 100644 index 000000000..0c18f3cb8 --- /dev/null +++ b/interfaces/kits/js/src/mod_fs/class_atomicFile/atomicFile_n_exporter.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef INTERFACES_KITS_JS_SRC_MOD_FILEIO_CLASS_ATOMIC_FILE_N_EXPORTER_H +#define INTERFACES_KITS_JS_SRC_MOD_FILEIO_CLASS_ATOMIC_FILE_N_EXPORTER_H + +#include "filemgmt_libn.h" + +namespace OHOS { +namespace FileManagement { +namespace ModuleFileIO { +using namespace OHOS::FileManagement::LibN; +class AtomicFileNExporter final : public NExporter { +public: + inline static const std::string className_ = "AtomicFile"; + + bool Export() override; + std::string GetClassName() override; + + static napi_value Constructor(napi_env env, napi_callback_info info); + static napi_value GetBaseFile(napi_env env, napi_callback_info info); + static napi_value OpenRead(napi_env env, napi_callback_info info); + static napi_value ReadFully(napi_env env, napi_callback_info info); + static napi_value StartWrite(napi_env env, napi_callback_info info); + static napi_value FinishWrite(napi_env env, napi_callback_info info); + static napi_value FailWrite(napi_env env, napi_callback_info info); + static napi_value Delete(napi_env env, napi_callback_info info); + + AtomicFileNExporter(napi_env env, napi_value exports); + ~AtomicFileNExporter() override; +}; +} // namespace ModuleFileIO +} // namespace DistributedFS +} // namespace OHOS +#endif \ No newline at end of file diff --git a/interfaces/kits/js/src/mod_fs/module.cpp b/interfaces/kits/js/src/mod_fs/module.cpp index ad976623b..52c85bda3 100644 --- a/interfaces/kits/js/src/mod_fs/module.cpp +++ b/interfaces/kits/js/src/mod_fs/module.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -21,6 +21,7 @@ #include "class_file/file_n_exporter.h" #include "class_stat/stat_n_exporter.h" #if !defined(WIN_PLATFORM) && !defined(IOS_PLATFORM) +#include "class_atomicFile/atomicFile_n_exporter.h" #include "class_randomaccessfile/randomaccessfile_n_exporter.h" #include "class_readeriterator/readeriterator_n_exporter.h" #include "class_stream/stream_n_exporter.h" @@ -45,6 +46,7 @@ static napi_value Export(napi_env env, napi_value exports) products.emplace_back(make_unique(env, exports)); products.emplace_back(make_unique(env, exports)); #if !defined(WIN_PLATFORM) && !defined(IOS_PLATFORM) + products.emplace_back(make_unique(env, exports)); products.emplace_back(make_unique(env, exports)); products.emplace_back(make_unique(env, exports)); products.emplace_back(make_unique(env, exports)); diff --git a/interfaces/kits/ts/streamrw/src/streamrw.ts b/interfaces/kits/ts/streamrw/src/streamrw.ts index a81d5b5ff..58e8b8bb0 100644 --- a/interfaces/kits/ts/streamrw/src/streamrw.ts +++ b/interfaces/kits/ts/streamrw/src/streamrw.ts @@ -141,6 +141,10 @@ class WriteStream extends stream.Writable { this.stream?.close(); } + closeSync(): void { + this.stream?.closeSync(); + } + doInitialize(callback: Function): void { callback(); } -- Gitee