From 2ce053ff467a3d0c2e415c762a62dacf3944717f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E9=91=AB?= Date: Mon, 14 Jul 2025 14:56:38 +0800 Subject: [PATCH 01/10] =?UTF-8?q?num=20to=20int=20Signed-off-by:=20?= =?UTF-8?q?=E5=91=A8=E9=91=AB=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit update interfaces/kits/js/src/mod_fs/properties/ani/listfile_ani.cpp. Signed-off-by: 周鑫 --- .../src/common/ani_helper/type_converter.cpp | 20 +++ .../js/src/common/ani_helper/type_converter.h | 1 + .../js/src/mod_fs/ani/ets/@ohos.file.fs.ets | 136 +++++++++--------- .../mod_fs/class_stream/ani/stream_ani.cpp | 12 +- .../src/mod_fs/class_stream/ani/stream_ani.h | 6 +- .../src/mod_fs/properties/ani/close_ani.cpp | 12 +- .../properties/ani/fdopen_stream_ani.cpp | 2 +- .../mod_fs/properties/ani/fdopen_stream_ani.h | 2 +- .../mod_fs/properties/ani/listfile_ani.cpp | 24 +++- 9 files changed, 129 insertions(+), 86 deletions(-) diff --git a/interfaces/kits/js/src/common/ani_helper/type_converter.cpp b/interfaces/kits/js/src/common/ani_helper/type_converter.cpp index 7b5f4ac1c..910aea89c 100644 --- a/interfaces/kits/js/src/common/ani_helper/type_converter.cpp +++ b/interfaces/kits/js/src/common/ani_helper/type_converter.cpp @@ -86,6 +86,26 @@ std::tuple> TypeConverter::ToOptionalInt64(ani_env return { false, {} }; } +tuple> TypeConverter::ToOptionalDouble(ani_env *env, const ani_object &value) +{ + if (env == nullptr) { + return { false, {} }; + } + + ani_boolean isUndefined; + env->Reference_IsUndefined(value, &isUndefined); + if (isUndefined) { + return { true, nullopt }; + } + + ani_double doubleValue; + if (ANI_OK == env->Object_CallMethodByName_Double(value, "toDouble", nullptr, &doubleValue)) { + return { true, make_optional(doubleValue) }; + } + + return { false, {} }; +} + std::tuple TypeConverter::ToAniString(ani_env *env, std::string str) { if (env == nullptr) { diff --git a/interfaces/kits/js/src/common/ani_helper/type_converter.h b/interfaces/kits/js/src/common/ani_helper/type_converter.h index 793ad367f..1c11420df 100644 --- a/interfaces/kits/js/src/common/ani_helper/type_converter.h +++ b/interfaces/kits/js/src/common/ani_helper/type_converter.h @@ -32,6 +32,7 @@ public: static std::tuple ToUTF8String(ani_env *env, const ani_string &path); static std::tuple> ToOptionalInt32(ani_env *env, const ani_object &value); static std::tuple> ToOptionalInt64(ani_env *env, const ani_object &value); + static std::tuple> ToOptionalDouble(ani_env *env, const ani_object &value); static std::tuple ToAniArrayBuffer(ani_env *env, void *buffer, size_t length); static std::tuple ToAniString(ani_env *env, std::string str); static std::tuple ToAniString(ani_env *env, std::string str, size_t size); diff --git a/interfaces/kits/js/src/mod_fs/ani/ets/@ohos.file.fs.ets b/interfaces/kits/js/src/mod_fs/ani/ets/@ohos.file.fs.ets index 610c1094f..20684b7e9 100644 --- a/interfaces/kits/js/src/mod_fs/ani/ets/@ohos.file.fs.ets +++ b/interfaces/kits/js/src/mod_fs/ani/ets/@ohos.file.fs.ets @@ -89,9 +89,9 @@ function accessSync(path: string, mode: AccessModeType, flag: AccessFlagType): b return FileIoImpl.doAccessSync(path, mode, flag); } -function close(file: number | File): Promise { +function close(file: int | File): Promise { return new Promise((resolve: (result: undefined) => void, reject: (e: BusinessError) => void): void => { - let promise = taskpool.execute((file: number | File): undefined => FileIoImpl.closeSync(file), file); + let promise = taskpool.execute((file: int | File): undefined => FileIoImpl.closeSync(file), file); promise.then((ret: NullishType): void => { resolve(undefined); }).catch((e: Error): void => { @@ -100,8 +100,8 @@ function close(file: number | File): Promise { }); } -function close(file: number | File, callback: AsyncCallback): void { - let promise = taskpool.execute((file: number | File): undefined => FileIoImpl.closeSync(file), file); +function close(file: int | File, callback: AsyncCallback): void { + let promise = taskpool.execute((file: int | File): undefined => FileIoImpl.closeSync(file), file); promise.then((ret: NullishType): void => { let e = new BusinessError(); e.code = 0; @@ -111,7 +111,7 @@ function close(file: number | File, callback: AsyncCallback): void { }); } -function closeSync(file: number | File): void { +function closeSync(file: int | File): void { return FileIoImpl.closeSync(file) } @@ -970,9 +970,9 @@ function createRandomAccessFile(file: string | File, mode?: number, }); } -function fdopenStream(fd: number, mode: string): Promise { +function fdopenStream(fd: int, mode: string): Promise { return new Promise((resolve: (result: Stream) => void, reject: (e: BusinessError) => void) => { - let promise = taskpool.execute((fd: number, mode: string): Stream => { + let promise = taskpool.execute((fd: int, mode: string): Stream => { return FileIoImpl.fdopenStreamSync(fd, mode); }, fd, mode); promise.then((ret: NullishType): void => { @@ -1031,8 +1031,8 @@ function createRandomAccessFile(file: string | File, mode: number, }); } -function fdopenStream(fd: number, mode: string, callback: AsyncCallback): void { - let promise = taskpool.execute((fd: number, mode: string): Stream => { +function fdopenStream(fd: int, mode: string, callback: AsyncCallback): void { + let promise = taskpool.execute((fd: int, mode: string): Stream => { return FileIoImpl.fdopenStreamSync(fd, mode); }, fd, mode); promise.then((ret: NullishType): void => { @@ -1046,7 +1046,7 @@ function fdopenStream(fd: number, mode: string, callback: AsyncCallback) }); } -function fdopenStreamSync(fd: number, mode: string): Stream { +function fdopenStreamSync(fd: int, mode: string): Stream { return FileIoImpl.fdopenStreamSync(fd, mode); } @@ -1235,8 +1235,8 @@ export interface Filter { suffix?: Array; displayName?: Array; mimeType?: Array; - fileSizeOver?: number; - lastModifiedAfter?: number; + fileSizeOver?: long; + lastModifiedAfter?: double; excludeMedia?: boolean; } @@ -1618,15 +1618,15 @@ export interface Stream { flush(): Promise; flush(callback: AsyncCallback): void; flushSync(): void; - write(buffer: ArrayBuffer | string, options?: WriteOptions): Promise; - write(buffer: ArrayBuffer | string, callback: AsyncCallback): void; - write(buffer: ArrayBuffer | string, options: WriteOptions, callback: AsyncCallback): void; - writeSync(buffer: ArrayBuffer | string, options?: WriteOptions): number; - read(buffer: ArrayBuffer, options?: ReadOptions): Promise; - read(buffer: ArrayBuffer, callback: AsyncCallback): void; - read(buffer: ArrayBuffer, options: ReadOptions, callback: AsyncCallback): void; - readSync(buffer: ArrayBuffer, options?: ReadOptions): number; - seek(offset: number, whence?: number): number; + write(buffer: ArrayBuffer | string, options?: WriteOptions): Promise; + write(buffer: ArrayBuffer | string, callback: AsyncCallback): void; + write(buffer: ArrayBuffer | string, options: WriteOptions, callback: AsyncCallback): void; + writeSync(buffer: ArrayBuffer | string, options?: WriteOptions): long; + read(buffer: ArrayBuffer, options?: ReadOptions): Promise; + read(buffer: ArrayBuffer, callback: AsyncCallback): void; + read(buffer: ArrayBuffer, options: ReadOptions, callback: AsyncCallback): void; + readSync(buffer: ArrayBuffer, options?: ReadOptions): long; + seek(offset: long, whence?: int): long; } export class StreamInner implements Stream { @@ -1686,13 +1686,13 @@ export class StreamInner implements Stream { native flushSync(): void; - write(buffer: ArrayBuffer | string, options?: WriteOptions): Promise { - return new Promise((resolve: (result: number) => void, reject: (e: BusinessError) => void) => { - let promise = taskpool.execute((buffer: ArrayBuffer | string, options?: WriteOptions): number => { + write(buffer: ArrayBuffer | string, options?: WriteOptions): Promise { + return new Promise((resolve: (result: long) => void, reject: (e: BusinessError) => void) => { + let promise = taskpool.execute((buffer: ArrayBuffer | string, options?: WriteOptions): long => { return this.writeSync(buffer, options); }, buffer, options); promise.then((ret: NullishType): void => { - let result = ret as number + let result = ret as long resolve(result); }).catch((e: Error): void => { reject(e as BusinessError); @@ -1700,43 +1700,43 @@ export class StreamInner implements Stream { }); } - write(buffer: ArrayBuffer | string, callback: AsyncCallback): void { - let promise = taskpool.execute((buffer: ArrayBuffer | string): number => { + write(buffer: ArrayBuffer | string, callback: AsyncCallback): void { + let promise = taskpool.execute((buffer: ArrayBuffer | string): long => { return this.writeSync(buffer); }, buffer); promise.then((ret: NullishType): void => { let e = new BusinessError(); e.code = 0; - let result = ret as number; + let result = ret as long; callback(e, result); }).catch((e: Error): void => { callback(e as BusinessError, 0); }); } - write(buffer: ArrayBuffer | string, options: WriteOptions, callback: AsyncCallback): void { - let promise = taskpool.execute((buffer: ArrayBuffer | string, options: WriteOptions): number => { + write(buffer: ArrayBuffer | string, options: WriteOptions, callback: AsyncCallback): void { + let promise = taskpool.execute((buffer: ArrayBuffer | string, options: WriteOptions): long => { return this.writeSync(buffer, options); }, buffer, options); promise.then((ret: NullishType): void => { let e = new BusinessError(); e.code = 0; - let result = ret as number; + let result = ret as long; callback(e, result); }).catch((e: Error): void => { callback(e as BusinessError, 0); }); } - native writeSync(buffer: ArrayBuffer | string, options?: WriteOptions): number; + native writeSync(buffer: ArrayBuffer | string, options?: WriteOptions): long; - read(buffer: ArrayBuffer, options?: ReadOptions): Promise { - return new Promise((resolve: (result: number) => void, reject: (e: BusinessError) => void) => { - let promise = taskpool.execute((buffer: ArrayBuffer, options?: ReadOptions): number => { + read(buffer: ArrayBuffer, options?: ReadOptions): Promise { + return new Promise((resolve: (result: long) => void, reject: (e: BusinessError) => void) => { + let promise = taskpool.execute((buffer: ArrayBuffer, options?: ReadOptions): long => { return this.readSync(buffer, options); }, buffer, options); promise.then((ret: NullishType): void => { - let result = ret as number + let result = ret as long resolve(result); }).catch((e: Error): void => { reject(e as BusinessError); @@ -1744,44 +1744,44 @@ export class StreamInner implements Stream { }); } - read(buffer: ArrayBuffer, callback: AsyncCallback): void { - let promise = taskpool.execute((buffer: ArrayBuffer): number => { + read(buffer: ArrayBuffer, callback: AsyncCallback): void { + let promise = taskpool.execute((buffer: ArrayBuffer): long => { return this.readSync(buffer); }, buffer); promise.then((ret: NullishType): void => { let e = new BusinessError(); e.code = 0; - let result = ret as number; + let result = ret as long; callback(e, result); }).catch((e: Error): void => { callback(e as BusinessError, 0); }); } - read(buffer: ArrayBuffer, options: ReadOptions, callback: AsyncCallback): void { - let promise = taskpool.execute((buffer: ArrayBuffer, options: ReadOptions): number => { + read(buffer: ArrayBuffer, options: ReadOptions, callback: AsyncCallback): void { + let promise = taskpool.execute((buffer: ArrayBuffer, options: ReadOptions): long => { return this.readSync(buffer, options); }, buffer, options); promise.then((ret: NullishType): void => { let e = new BusinessError(); e.code = 0; - let result = ret as number; + let result = ret as long; callback(e, result); }).catch((e: Error): void => { callback(e as BusinessError, 0); }); } - native readSync(buffer: ArrayBuffer, options?: ReadOptions): number; - native seek(offset: number, whence?: number): number; + native readSync(buffer: ArrayBuffer, options?: ReadOptions): long; + native seek(offset: long, whence?: int): long; } export class ReadStream extends stream.Readable { path: string; - bytesRead: number; - private offset: number; - private start?: number; - private end?: number; + bytesRead: long; + private offset: long; + private start?: long; + private end?: long; private stream?: Stream; constructor(path: string, options?: ReadStreamOptions) { @@ -1794,7 +1794,7 @@ export class ReadStream extends stream.Readable { this.offset = this.start ?? 0; } - seek(offset: number, whence?: WhenceType): number { + seek(offset: long, whence?: WhenceType): long { if (whence === undefined) { let off = this.stream?.seek(offset); if (off !== undefined) { @@ -1817,7 +1817,7 @@ export class ReadStream extends stream.Readable { callback(); } - doRead(size: number): void { + doRead(size: long): void { let readSize = size; let end = this.end if (end !== undefined) { @@ -1833,7 +1833,7 @@ export class ReadStream extends stream.Readable { const off = this.offset; this.offset += readSize; this.stream?.read(buffer, { offset: off, length: readSize }) - .then((readOut: number) => { + .then((readOut: long) => { if (readOut > 0) { this.bytesRead += readOut; this.push(new Uint8Array(buffer.slice(0, readOut))); @@ -1848,10 +1848,10 @@ export class ReadStream extends stream.Readable { export class WriteStream extends stream.Writable { path: string; - bytesWritten: number; - private offset: number; + bytesWritten: long; + private offset: long; private mode: string; - private start?: number; + private start?: long; private stream?: Stream; constructor(path: string, options?: WriteStreamOptions) { @@ -1864,7 +1864,7 @@ export class WriteStream extends stream.Writable { this.offset = this.start ?? 0; } - seek(offset: number, whence?: WhenceType): number { + seek(offset: long, whence?: WhenceType): long { if (whence === undefined) { let off = this.stream?.seek(offset); if (off !== undefined) { @@ -1893,7 +1893,7 @@ export class WriteStream extends stream.Writable { doWrite(chunk: string | ArrayBuffer, encoding: string, callback: () => void): void { this.stream?.write(chunk, { offset: this.offset }) - .then((writeIn: number) => { + .then((writeIn: long) => { this.offset += writeIn; this.bytesWritten += writeIn; callback(); @@ -1903,21 +1903,21 @@ export class WriteStream extends stream.Writable { }); } - convertOpenMode(mode?: number): string { + convertOpenMode(mode?: int): string { let modeStr = 'w'; if (mode === undefined) { return modeStr; } - if ((mode as number) & fileIo.OpenMode.WRITE_ONLY) { + if ((mode as int) & fileIo.OpenMode.WRITE_ONLY) { modeStr = 'w'; } - if ((mode as number) & fileIo.OpenMode.READ_WRITE) { + if ((mode as int) & fileIo.OpenMode.READ_WRITE) { modeStr = 'w+'; } - if (((mode as number) & fileIo.OpenMode.WRITE_ONLY) && ((mode as number) & fileIo.OpenMode.APPEND)) { + if (((mode as int) & fileIo.OpenMode.WRITE_ONLY) && ((mode as int) & fileIo.OpenMode.APPEND)) { modeStr = 'a'; } - if (((mode as number) & fileIo.OpenMode.READ_WRITE) && ((mode as number) & fileIo.OpenMode.APPEND)) { + if (((mode as int) & fileIo.OpenMode.READ_WRITE) && ((mode as int) & fileIo.OpenMode.APPEND)) { modeStr = 'a+'; } return modeStr; @@ -2059,7 +2059,7 @@ export interface RandomAccessFileOptions { export interface ListFileOptions { recursion?: boolean; - listNum?: number; + listNum?: int; filter?: Filter; } @@ -2075,14 +2075,14 @@ export interface ReadStreamOptions { export class ReadStreamOptionsInner implements ReadStreamOptions { constructor() {} - start?: number; - end?: number; + start?: long; + end?: long; } export class WriteStreamOptionsInner implements WriteStreamOptions { constructor() {} - mode?: number; - start?: number; + mode?: int; + start?: long; } export interface ReaderIteratorResult { @@ -2111,7 +2111,7 @@ export class FileIoImpl { static native doAccessSync(path: string, mode?: fileIo.AccessModeType, flag?: fileIo.AccessFlagType): boolean; - static native closeSync(file: number | fileIo.File): void; + static native closeSync(file: int | fileIo.File): void; static native copySync(srcUri: string, destUri: string, options?: fileIo.CopyOptions): void; @@ -2131,7 +2131,7 @@ export class FileIoImpl { static native createWatcherSync(path: string, events: number, listener: WatchEventListener): fileIo.Watcher; - static native fdopenStreamSync(fd: number, mode: string): fileIo.Stream; + static native fdopenStreamSync(fd: int, mode: string): fileIo.Stream; static native dup(fd: number): fileIo.File; diff --git a/interfaces/kits/js/src/mod_fs/class_stream/ani/stream_ani.cpp b/interfaces/kits/js/src/mod_fs/class_stream/ani/stream_ani.cpp index a1d694187..1748d67f5 100644 --- a/interfaces/kits/js/src/mod_fs/class_stream/ani/stream_ani.cpp +++ b/interfaces/kits/js/src/mod_fs/class_stream/ani/stream_ani.cpp @@ -170,7 +170,7 @@ void StreamAni::Flush(ani_env *env, [[maybe_unused]] ani_object object) } } -ani_double StreamAni::Write(ani_env *env, [[maybe_unused]] ani_object object, ani_object buf, ani_object options) +ani_long StreamAni::Write(ani_env *env, [[maybe_unused]] ani_object object, ani_object buf, ani_object options) { auto fsStream = Unwrap(env, object); if (fsStream == nullptr) { @@ -217,7 +217,7 @@ ani_double StreamAni::Write(ani_env *env, [[maybe_unused]] ani_object object, an ErrorHandler::Throw(env, err); return -1; } - return static_cast(ret.GetData().value()); + return ret.GetData().value(); } HILOGE("Unsupported buffer type!"); @@ -225,7 +225,7 @@ ani_double StreamAni::Write(ani_env *env, [[maybe_unused]] ani_object object, an return -1; } -ani_double StreamAni::Read(ani_env *env, [[maybe_unused]] ani_object object, ani_arraybuffer buffer, ani_object options) +ani_long StreamAni::Read(ani_env *env, [[maybe_unused]] ani_object object, ani_arraybuffer buffer, ani_object options) { auto fsStream = Unwrap(env, object); if (fsStream == nullptr) { @@ -255,10 +255,10 @@ ani_double StreamAni::Read(ani_env *env, [[maybe_unused]] ani_object object, ani ErrorHandler::Throw(env, err); return -1; } - return static_cast(ret.GetData().value()); + return ret.GetData().value(); } -ani_double StreamAni::Seek(ani_env *env, [[maybe_unused]] ani_object object, ani_double offset, ani_object whence) +ani_long StreamAni::Seek(ani_env *env, [[maybe_unused]] ani_object object, ani_long offset, ani_object whence) { auto fsStream = Unwrap(env, object); if (fsStream == nullptr) { @@ -281,7 +281,7 @@ ani_double StreamAni::Seek(ani_env *env, [[maybe_unused]] ani_object object, ani ErrorHandler::Throw(env, err); return -1; } - return static_cast(ret.GetData().value()); + return ret.GetData().value(); } } // namespace ANI diff --git a/interfaces/kits/js/src/mod_fs/class_stream/ani/stream_ani.h b/interfaces/kits/js/src/mod_fs/class_stream/ani/stream_ani.h index 91fdb9852..486788e1a 100644 --- a/interfaces/kits/js/src/mod_fs/class_stream/ani/stream_ani.h +++ b/interfaces/kits/js/src/mod_fs/class_stream/ani/stream_ani.h @@ -27,10 +27,10 @@ class StreamAni final { public: static void Close(ani_env *env, [[maybe_unused]] ani_object object); static void Flush(ani_env *env, [[maybe_unused]] ani_object object); - static ani_double Write(ani_env *env, [[maybe_unused]] ani_object object, ani_object buf, ani_object options); - static ani_double Read( + static ani_long Write(ani_env *env, [[maybe_unused]] ani_object object, ani_object buf, ani_object options); + static ani_long Read( ani_env *env, [[maybe_unused]] ani_object object, ani_arraybuffer buffer, ani_object options); - static ani_double Seek(ani_env *env, [[maybe_unused]] ani_object object, ani_double offset, ani_object whence); + static ani_long Seek(ani_env *env, [[maybe_unused]] ani_object object, ani_long offset, ani_object whence); }; } // namespace ANI } // namespace ModuleFileIO diff --git a/interfaces/kits/js/src/mod_fs/properties/ani/close_ani.cpp b/interfaces/kits/js/src/mod_fs/properties/ani/close_ani.cpp index e2f7b9464..7306e6301 100644 --- a/interfaces/kits/js/src/mod_fs/properties/ani/close_ani.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/ani/close_ani.cpp @@ -36,12 +36,12 @@ using namespace OHOS::FileManagement::ModuleFileIO::ANI::AniSignature; tuple ParseFdOrFile(ani_env *env, ani_object obj) { int32_t result = -1; - auto doubleClassDesc = BoxedTypes::Double::classDesc.c_str(); - ani_class doubleClass; - env->FindClass(doubleClassDesc, &doubleClass); - ani_boolean isDouble; - env->Object_InstanceOf(obj, doubleClass, &isDouble); - if (isDouble) { + auto intClassDesc = BoxedTypes::Int::classDesc.c_str(); + ani_class intClass; + env->FindClass(intClassDesc, &intClass); + ani_boolean isInt; + env->Object_InstanceOf(obj, intClass, &isInt); + if (isInt) { ani_int fd; if (ANI_OK != env->Object_CallMethodByName_Int(obj, "toInt", nullptr, &fd)) { HILOGE("Get fd value failed"); diff --git a/interfaces/kits/js/src/mod_fs/properties/ani/fdopen_stream_ani.cpp b/interfaces/kits/js/src/mod_fs/properties/ani/fdopen_stream_ani.cpp index bc6e8d274..ad98f46e3 100644 --- a/interfaces/kits/js/src/mod_fs/properties/ani/fdopen_stream_ani.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/ani/fdopen_stream_ani.cpp @@ -30,7 +30,7 @@ using namespace std; using namespace OHOS::FileManagement::ModuleFileIO; ani_object FdopenStreamAni::FdopenStreamSync( - ani_env *env, [[maybe_unused]] ani_class clazz, ani_double fd, ani_string mode) + ani_env *env, [[maybe_unused]] ani_class clazz, ani_int fd, ani_string mode) { auto [succMode, openMode] = TypeConverter::ToUTF8String(env, mode); if (!succMode) { diff --git a/interfaces/kits/js/src/mod_fs/properties/ani/fdopen_stream_ani.h b/interfaces/kits/js/src/mod_fs/properties/ani/fdopen_stream_ani.h index 81f0fde31..3a4a3e539 100644 --- a/interfaces/kits/js/src/mod_fs/properties/ani/fdopen_stream_ani.h +++ b/interfaces/kits/js/src/mod_fs/properties/ani/fdopen_stream_ani.h @@ -24,7 +24,7 @@ namespace ModuleFileIO { namespace ANI { class FdopenStreamAni final { public: - static ani_object FdopenStreamSync(ani_env *env, [[maybe_unused]] ani_class clazz, ani_double fd, ani_string mode); + static ani_object FdopenStreamSync(ani_env *env, [[maybe_unused]] ani_class clazz, ani_int fd, ani_string mode); }; } // namespace ANI } // namespace ModuleFileIO diff --git a/interfaces/kits/js/src/mod_fs/properties/ani/listfile_ani.cpp b/interfaces/kits/js/src/mod_fs/properties/ani/listfile_ani.cpp index ac1ec9039..cdea592d7 100644 --- a/interfaces/kits/js/src/mod_fs/properties/ani/listfile_ani.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/ani/listfile_ani.cpp @@ -51,6 +51,28 @@ tuple ParseBooleanParam(ani_env *env, ani_object obj, string tag) return { true, static_cast(boolRef_res) }; } +tuple ParseLongParam(ani_env *env, ani_object obj, string tag) +{ + int result = 0; + ani_boolean isUndefined; + ani_ref result_ref; + if (ANI_OK != env->Object_GetPropertyByName_Ref(obj, tag.c_str(), &result_ref)) { + return { false, result }; + } + env->Reference_IsUndefined(result_ref, &isUndefined); + if (isUndefined) { + return { true, result }; + } + ani_long result_ref_res; + if (ANI_OK != env->Object_CallMethodByName_Long( + static_cast(result_ref), "toLong", nullptr, &result_ref_res)) { + result = -1; + return { false, result }; + } + result = static_cast(result_ref_res); + return { true, result }; +} + tuple ParseIntParam(ani_env *env, ani_object obj, string tag) { int result = 0; @@ -133,7 +155,7 @@ tuple> ParseFilter(ani_env *env, ani_object obj) { FsFileFilter filter; - auto [succfileSizeOver, fileSizeOver] = ParseIntParam(env, obj, "fileSizeOver"); + auto [succfileSizeOver, fileSizeOver] = ParseLongParam(env, obj, "fileSizeOver"); if (!succfileSizeOver) { HILOGE("Illegal option.fileSizeOver parameter"); return { false, move(filter) }; -- Gitee From 631ff221be0db7cbada0f15ee7ba5e28790fef77 Mon Sep 17 00:00:00 2001 From: liyuke Date: Wed, 16 Jul 2025 14:57:27 +0800 Subject: [PATCH 02/10] =?UTF-8?q?fdatasync=E7=AD=89number=E8=BD=ACint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liyuke Change-Id: I43bc5b4e33268eb09937e9e5479daee70a38c82c --- .../js/src/mod_fs/ani/ets/@ohos.file.fs.ets | 80 +++++++++---------- .../mod_fs/properties/ani/fdatasync_ani.cpp | 2 +- .../src/mod_fs/properties/ani/fdatasync_ani.h | 2 +- 3 files changed, 42 insertions(+), 42 deletions(-) diff --git a/interfaces/kits/js/src/mod_fs/ani/ets/@ohos.file.fs.ets b/interfaces/kits/js/src/mod_fs/ani/ets/@ohos.file.fs.ets index 20684b7e9..f08a3a4c0 100644 --- a/interfaces/kits/js/src/mod_fs/ani/ets/@ohos.file.fs.ets +++ b/interfaces/kits/js/src/mod_fs/ani/ets/@ohos.file.fs.ets @@ -160,14 +160,14 @@ function dup(fd: number): File { return FileIoImpl.dup(fd); } -function copyDirSync(src: string, dest: string, mode?: number): void { +function copyDirSync(src: string, dest: string, mode?: int): void { return FileIoImpl.copyDirSync(src, dest, mode); } -function copyDir(src: string, dest: string, mode?: number): Promise { +function copyDir(src: string, dest: string, mode?: int): Promise { return new Promise((resolve: (result: undefined) => void, reject: (e: BusinessError>) => void): void => { - let promise = taskpool.execute((src: string, dest: string, mode?: number): undefined => + let promise = taskpool.execute((src: string, dest: string, mode?: int): undefined => FileIoImpl.copyDirSync(src, dest, mode), src, dest, mode); promise.then((ret: NullishType): void => { resolve(undefined); @@ -190,8 +190,8 @@ function copyDir(src: string, dest: string, callback: AsyncCallback>): void { - let promise = taskpool.execute((src: string, dest: string, mode: number): undefined => +function copyDir(src: string, dest: string, mode: int, callback: AsyncCallback>): void { + let promise = taskpool.execute((src: string, dest: string, mode: int): undefined => FileIoImpl.copyDirSync(src, dest, mode), src, dest, mode); promise.then((ret: NullishType): void => { let e = new BusinessError>(); @@ -206,10 +206,10 @@ function copyDir(src: string, dest: string, mode: number, callback: AsyncCallbac function copyDir(arg0: Object, arg1: Object, arg2: NullishType, arg3: NullishType): void { let src = arg0 as string; let dest = arg1 as string; - if (typeof arg2 === 'number' && typeof arg3 === 'function') { - let mode: number = 0; + if (typeof arg2 === 'int' && typeof arg3 === 'function') { + let mode: int = 0; try { - mode = arg2 as number; + mode = arg2 as int; } catch (error) { mode = (arg2 as int) + 0; } @@ -228,13 +228,13 @@ function mkdirSync(path: string): void { return FileIoImpl.mkdirSync(path) } -function fdatasyncSync(fd: number): void { +function fdatasyncSync(fd: int): void { return FileIoImpl.fdatasyncSync(fd) } -function fdatasync(fd: number): Promise { +function fdatasync(fd: int): Promise { return new Promise((resolve: (result: undefined) => void, reject: (e: BusinessError) => void): void => { - let promise = taskpool.execute((fd: number): undefined => FileIoImpl.fdatasyncSync(fd), fd); + let promise = taskpool.execute((fd: int): undefined => FileIoImpl.fdatasyncSync(fd), fd); promise.then((ret: NullishType): void => { resolve(undefined); }).catch((e: Error): void => { @@ -243,8 +243,8 @@ function fdatasync(fd: number): Promise { }); } -function fdatasync(fd: number, callback: AsyncCallback): void { - let promise = taskpool.execute((fd: number): undefined => FileIoImpl.fdatasyncSync(fd), fd); +function fdatasync(fd: int, callback: AsyncCallback): void { + let promise = taskpool.execute((fd: int): undefined => FileIoImpl.fdatasyncSync(fd), fd); promise.then((ret: NullishType): void => { let e = new BusinessError(); e.code = 0; @@ -314,14 +314,14 @@ function mkdir(path: string, recursion: boolean, callback: AsyncCallback): }); } -function moveDirSync(src: string, dest: string, mode?: number): void { +function moveDirSync(src: string, dest: string, mode?: int): void { return FileIoImpl.movedirSync(src, dest, mode) } -function moveDir(src: string, dest: string, mode?: number): Promise { +function moveDir(src: string, dest: string, mode?: int): Promise { return new Promise((resolve: (result: undefined) => void, reject: (e: BusinessError>) => void): void => { - let promise = taskpool.execute((src: string, dest: string, mode?: number): undefined => { + let promise = taskpool.execute((src: string, dest: string, mode?: int): undefined => { return FileIoImpl.movedirSync(src, dest, mode); }, src, dest, mode); promise.then((ret: NullishType): void => { @@ -346,8 +346,8 @@ function moveDir(src: string, dest: string, callback: AsyncCallback>): void { - let promise = taskpool.execute((src: string, dest: string, mode: number): undefined => { +function moveDir(src: string, dest: string, mode: int, callback: AsyncCallback>): void { + let promise = taskpool.execute((src: string, dest: string, mode: int): undefined => { return FileIoImpl.movedirSync(src, dest, mode); }, src, dest, mode); promise.then((ret: NullishType): void => { @@ -363,10 +363,10 @@ function moveDir(src: string, dest: string, mode: number, callback: AsyncCallbac function moveDir(arg0: Object, arg1: Object, arg2: NullishType, arg3: NullishType): void { let src = arg0 as string; let dest = arg1 as string; - if (typeof arg2 === 'number' && typeof arg3 === 'function') { - let mode: number = 0; + if (typeof arg2 === 'int' && typeof arg3 === 'function') { + let mode: int = 0; try { - mode = arg2 as number; + mode = arg2 as int; } catch (error) { mode = (arg2 as int) + 0; } @@ -673,13 +673,13 @@ function rmdir(path: string, callback: AsyncCallback): void { }); } -function truncateSync(file: string | number, len?: number): void { +function truncateSync(file: string | int, len?: long): void { return FileIoImpl.truncateSync(file, len) } -function truncate(file: string | number, len?: number): Promise { +function truncate(file: string | int, len?: long): Promise { return new Promise((resolve: (result: undefined) => void, reject: (e: BusinessError) => void): void => { - let promise = taskpool.execute((file: string | number, len?: number): undefined => { + let promise = taskpool.execute((file: string | int, len?: long): undefined => { return FileIoImpl.truncateSync(file, len); }, file, len); promise.then((ret: NullishType): void => { @@ -690,8 +690,8 @@ function truncate(file: string | number, len?: number): Promise { }) } -function truncate(file: string | number, callback: AsyncCallback): void { - let promise = taskpool.execute((file: string | number): undefined => { +function truncate(file: string | int, callback: AsyncCallback): void { + let promise = taskpool.execute((file: string | int): undefined => { return FileIoImpl.truncateSync(file); }, file); promise.then((ret: NullishType): void => { @@ -703,8 +703,8 @@ function truncate(file: string | number, callback: AsyncCallback): void { }); } -function truncate(file: string | number, len: number, callback: AsyncCallback): void { - let promise = taskpool.execute((file: string | number, len: number): undefined => { +function truncate(file: string | int, len: long, callback: AsyncCallback): void { + let promise = taskpool.execute((file: string | int, len: long): undefined => { return FileIoImpl.truncateSync(file, len); }, file, len); promise.then((ret: NullishType): void => { @@ -835,7 +835,7 @@ function listFileSync(path: string, options?: ListFileOptions): string[] { return FileIoImpl.listFileSync(path, options); } -function copyFileSync(src: string | number, dest: string | number, mode?: number): void { +function copyFileSync(src: string | int, dest: string | int, mode?: int): void { return FileIoImpl.copyFileSync(src, dest, mode) } @@ -1155,9 +1155,9 @@ function lstat(path: string, callback: AsyncCallback): void { callback(e as BusinessError, new StatInner(0)); }); } -function copyFile(src: string | number, dest: string | number, mode?: number): Promise { +function copyFile(src: string | int, dest: string | int, mode?: int): Promise { return new Promise((resolve: (result: undefined) => void, reject: (e: BusinessError) => void): void => { - let promise = taskpool.execute((src: string | number, dest: string | number, mode?: number): undefined => + let promise = taskpool.execute((src: string | int, dest: string | int, mode?: int): undefined => FileIoImpl.copyFileSync(src, dest, mode), src, dest, mode); promise.then((ret: NullishType): void => { resolve(undefined); @@ -1179,8 +1179,8 @@ function copy(srcUri: string, destUri: string, options?: CopyOptions): Promise): void { - let promise = taskpool.execute((src: string | number, dest: string | number, mode: number): undefined => +function copyFile(src: string | int, dest: string | int, mode: int, callback: AsyncCallback): void { + let promise = taskpool.execute((src: string | int, dest: string | int, mode: int): undefined => FileIoImpl.copyFileSync(src, dest, mode), src, dest, mode); promise.then((ret: NullishType): void => { let e = new BusinessError(); @@ -1203,8 +1203,8 @@ function copy(srcUri: string, destUri: string, options: CopyOptions, callback: A }); } -function copyFile(src: string | number, dest: string | number, callback: AsyncCallback): void { - let promise = taskpool.execute((src: string | number, dest: string | number): undefined => +function copyFile(src: string | int, dest: string | int, callback: AsyncCallback): void { + let promise = taskpool.execute((src: string | int, dest: string | int): undefined => FileIoImpl.copyFileSync(src, dest), src, dest); promise.then((ret: NullishType): void => { let e = new BusinessError(); @@ -2117,13 +2117,13 @@ export class FileIoImpl { static native connectDfs(networkId: string, listeners: DfsListeners): void; - static native copyDirSync(src: string, dest: string, mode?: number): void; + static native copyDirSync(src: string, dest: string, mode?: int): void; - static native copyFileSync(src: string | number, dest: string | number, mode?: number): void; + static native copyFileSync(src: string | int, dest: string | int, mode?: int): void; static native disConnectDfs(networkId: string): void; - static native fdatasyncSync(fd: number): void; + static native fdatasyncSync(fd: int): void; static native getxattrSync(path: string, key: string): string; @@ -2145,7 +2145,7 @@ export class FileIoImpl { static native mkdirSync(path: string, recursion: boolean): void; - static native movedirSync(src: string, dest: string, mode?: number): void; + static native movedirSync(src: string, dest: string, mode?: int): void; static native mkdtempSync(prefix: string): string; @@ -2165,7 +2165,7 @@ export class FileIoImpl { static native statSync(file: string | number): fileIo.Stat; - static native truncateSync(file: string | number, len?: number): void; + static native truncateSync(file: string | int, len?: long): void; static native unlinkSync(path: string): void; diff --git a/interfaces/kits/js/src/mod_fs/properties/ani/fdatasync_ani.cpp b/interfaces/kits/js/src/mod_fs/properties/ani/fdatasync_ani.cpp index 7ce4a8bfc..16991917d 100644 --- a/interfaces/kits/js/src/mod_fs/properties/ani/fdatasync_ani.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/ani/fdatasync_ani.cpp @@ -27,7 +27,7 @@ namespace FileManagement { namespace ModuleFileIO { namespace ANI { -void FDataSyncAni::FDataSyncSync(ani_env *env, [[maybe_unused]] ani_class clazz, ani_double fd) +void FDataSyncAni::FDataSyncSync(ani_env *env, [[maybe_unused]] ani_class clazz, ani_int fd) { auto ret = FDataSyncCore::DoFDataSync(static_cast(fd)); if (!ret.IsSuccess()) { diff --git a/interfaces/kits/js/src/mod_fs/properties/ani/fdatasync_ani.h b/interfaces/kits/js/src/mod_fs/properties/ani/fdatasync_ani.h index ce0b83261..05dc43cc7 100644 --- a/interfaces/kits/js/src/mod_fs/properties/ani/fdatasync_ani.h +++ b/interfaces/kits/js/src/mod_fs/properties/ani/fdatasync_ani.h @@ -25,7 +25,7 @@ namespace ANI { class FDataSyncAni final { public: - static void FDataSyncSync(ani_env *env, [[maybe_unused]] ani_class clazz, ani_double fd); + static void FDataSyncSync(ani_env *env, [[maybe_unused]] ani_class clazz, ani_int fd); }; } // namespace ANI -- Gitee From 398b3fe693fbdfd1737b27020043942ee5896042 Mon Sep 17 00:00:00 2001 From: yangbiao59 Date: Fri, 18 Jul 2025 11:05:05 +0800 Subject: [PATCH 03/10] number Signed-off-by: yangbiao59 --- .../js/src/mod_fs/ani/ets/@ohos.file.fs.ets | 66 +++++++++---------- .../js/src/mod_fs/properties/ani/dup_ani.cpp | 4 +- .../js/src/mod_fs/properties/ani/dup_ani.h | 2 +- .../src/mod_fs/properties/ani/lseek_ani.cpp | 8 +-- .../js/src/mod_fs/properties/ani/lseek_ani.h | 4 +- .../js/src/mod_fs/properties/ani/read_ani.cpp | 8 +-- .../js/src/mod_fs/properties/ani/read_ani.h | 4 +- 7 files changed, 48 insertions(+), 48 deletions(-) diff --git a/interfaces/kits/js/src/mod_fs/ani/ets/@ohos.file.fs.ets b/interfaces/kits/js/src/mod_fs/ani/ets/@ohos.file.fs.ets index f08a3a4c0..9505296fe 100644 --- a/interfaces/kits/js/src/mod_fs/ani/ets/@ohos.file.fs.ets +++ b/interfaces/kits/js/src/mod_fs/ani/ets/@ohos.file.fs.ets @@ -156,7 +156,7 @@ function getxattr(path: string, key: string): Promise { }); } -function dup(fd: number): File { +function dup(fd: int): File { return FileIoImpl.dup(fd); } @@ -551,17 +551,17 @@ function write(fd: number, buffer: string | ArrayBuffer, callback: AsyncCallback }); } -function readSync(fd: number, buffer: ArrayBuffer, options?: ReadOptions): number { +function readSync(fd: int, buffer: ArrayBuffer, options?: ReadOptions): long { return FileIoImpl.readSync(fd, buffer, options) } -function read(fd: number, buffer: ArrayBuffer, options?: ReadOptions): Promise { - return new Promise((resolve: (result: number) => void, reject: (e: BusinessError) => void) => { - let promise = taskpool.execute((fd: number, buffer: ArrayBuffer, options?: ReadOptions): number => { +function read(fd: int, buffer: ArrayBuffer, options?: ReadOptions): Promise { + return new Promise((resolve: (result: long) => void, reject: (e: BusinessError) => void) => { + let promise = taskpool.execute((fd: int, buffer: ArrayBuffer, options?: ReadOptions): long => { return FileIoImpl.readSync(fd, buffer, options) }, fd, buffer, options); promise.then((ret: NullishType) => { - let result = ret as number; + let result = ret as long; resolve(result); }).catch((e: Error): void => { reject(e as BusinessError); @@ -569,28 +569,28 @@ function read(fd: number, buffer: ArrayBuffer, options?: ReadOptions): Promise): void { - let promise = taskpool.execute((fd: number, buffer: ArrayBuffer): number => { +function read(fd: int, buffer: ArrayBuffer, callback: AsyncCallback): void { + let promise = taskpool.execute((fd: int, buffer: ArrayBuffer): long => { return FileIoImpl.readSync(fd, buffer); }, fd, buffer); promise.then((ret: NullishType): void => { let e = new BusinessError(); e.code = 0; - let result = ret as number; + let result = ret as long; callback(e, result); }).catch((e: Error): void => { callback(e as BusinessError, 0); }); } -function read(fd: number, buffer: ArrayBuffer, options: ReadOptions, callback: AsyncCallback): void { - let promise = taskpool.execute((fd: number, buffer: ArrayBuffer, options: ReadOptions): number => { +function read(fd: int, buffer: ArrayBuffer, options: ReadOptions, callback: AsyncCallback): void { + let promise = taskpool.execute((fd: int, buffer: ArrayBuffer, options: ReadOptions): long => { return FileIoImpl.readSync(fd, buffer, options); }, fd, buffer, options); promise.then((ret: NullishType): void => { let e = new BusinessError(); e.code = 0; - let result = ret as number; + let result = ret as long; callback(e, result); }).catch((e: Error): void => { callback(e as BusinessError, 0); @@ -839,13 +839,13 @@ function copyFileSync(src: string | int, dest: string | int, mode?: int): void { return FileIoImpl.copyFileSync(src, dest, mode) } -function statSync(file: string | number): Stat { +function statSync(file: string | int): Stat { return FileIoImpl.statSync(file) } -function stat(file: string | number): Promise { +function stat(file: string | int): Promise { return new Promise((resolve: (result: Stat) => void, reject: (e: BusinessError) => void) => { - let promise = taskpool.execute((file: string | number): Stat => { + let promise = taskpool.execute((file: string | int): Stat => { return FileIoImpl.statSync(file); }, file); promise.then((ret: NullishType): void => { @@ -857,8 +857,8 @@ function stat(file: string | number): Promise { }); } -function stat(file: string | number, callback: AsyncCallback): void { - let p = taskpool.execute((file: string | number): Stat => { +function stat(file: string | int, callback: AsyncCallback): void { + let p = taskpool.execute((file: string | int): Stat => { return FileIoImpl.statSync(file); }, file); p.then((ret: NullishType): void => { @@ -1108,7 +1108,7 @@ function symlink(target: string, srcPath: string, callback: AsyncCallback) }); } -function utimes(path: string, mtime: number): void { +function utimes(path: string, mtime: double): void { return FileIoImpl.utimes(path, mtime); } @@ -1227,7 +1227,7 @@ function copy(srcUri: string, destUri: string, callback: AsyncCallback): v }); } -function lseek(fd: number, offset: number, whence?: WhenceType): number { +function lseek(fd: int, offset: long, whence?: WhenceType): long { return FileIoImpl.lseekSync(fd, offset, whence); } @@ -1241,8 +1241,8 @@ export interface Filter { } export interface Progress { - processedSize: number; - totalSize: number; + processedSize: long; + totalSize: long; } export interface DfsListeners { @@ -1559,13 +1559,13 @@ export class ReaderIteratorInner implements ReaderIterator { export interface Stat { ino: bigint; - mode: number; - uid: number; - gid: number; - size: number; - atime: number; - mtime: number; - ctime: number; + mode: int; + uid: int; + gid: int; + size: long; + atime: long; + mtime: long; + ctime: long; atimeNs: bigint; mtimeNs: bigint; ctimeNs: bigint; @@ -2133,13 +2133,13 @@ export class FileIoImpl { static native fdopenStreamSync(fd: int, mode: string): fileIo.Stream; - static native dup(fd: number): fileIo.File; + static native dup(fd: int): fileIo.File; static native listFileSync(path: string, options?: ListFileOptions): string[]; static native lstatSync(path: string): fileIo.Stat; - static native lseekSync(fd: number, offset: number, whence?: fileIo.WhenceType): number; + static native lseekSync(fd: int, offset: long, whence?: fileIo.WhenceType): long; static native mkdirSync(path: string): void; @@ -2155,7 +2155,7 @@ export class FileIoImpl { static native readlinesSync(filePath: string, options?: Options): fileIo.ReaderIterator; - static native readSync(fd: number, buffer: ArrayBuffer, options?: ReadOptions): number; + static native readSync(fd: int, buffer: ArrayBuffer, options?: ReadOptions): long; static native readTextSync(filePath: string, options?: ReadTextOptions): string; @@ -2163,7 +2163,7 @@ export class FileIoImpl { static native setxattrSync(path: string, key: string, value: string): void; - static native statSync(file: string | number): fileIo.Stat; + static native statSync(file: string | int): fileIo.Stat; static native truncateSync(file: string | int, len?: long): void; @@ -2180,5 +2180,5 @@ export class FileIoImpl { static native symlinkSync(target: string, srcPath: string): void; - static native utimes(path: string, mtime: number): void; + static native utimes(path: string, mtime: double): void; } diff --git a/interfaces/kits/js/src/mod_fs/properties/ani/dup_ani.cpp b/interfaces/kits/js/src/mod_fs/properties/ani/dup_ani.cpp index 22c002243..0ddd81887 100644 --- a/interfaces/kits/js/src/mod_fs/properties/ani/dup_ani.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/ani/dup_ani.cpp @@ -28,9 +28,9 @@ namespace ModuleFileIO { namespace ANI { using namespace OHOS::FileManagement::ModuleFileIO; -ani_object DupAni::Dup(ani_env *env, [[maybe_unused]] ani_class clazz, ani_double fd) +ani_object DupAni::Dup(ani_env *env, [[maybe_unused]] ani_class clazz, ani_int fd) { - FsResult ret = DupCore::DoDup(static_cast(fd)); + FsResult ret = DupCore::DoDup(fd); if (!ret.IsSuccess()) { HILOGE("Dup file failed"); const auto &err = ret.GetError(); diff --git a/interfaces/kits/js/src/mod_fs/properties/ani/dup_ani.h b/interfaces/kits/js/src/mod_fs/properties/ani/dup_ani.h index c0e4a02c7..9df7bde3a 100644 --- a/interfaces/kits/js/src/mod_fs/properties/ani/dup_ani.h +++ b/interfaces/kits/js/src/mod_fs/properties/ani/dup_ani.h @@ -25,7 +25,7 @@ namespace ANI { class DupAni final { public: - static ani_object Dup(ani_env *env, [[maybe_unused]] ani_class clazz, ani_double fd); + static ani_object Dup(ani_env *env, [[maybe_unused]] ani_class clazz, ani_int fd); }; } // namespace ANI } // namespace ModuleFileIO diff --git a/interfaces/kits/js/src/mod_fs/properties/ani/lseek_ani.cpp b/interfaces/kits/js/src/mod_fs/properties/ani/lseek_ani.cpp index 1d689c696..cc1fde998 100644 --- a/interfaces/kits/js/src/mod_fs/properties/ani/lseek_ani.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/ani/lseek_ani.cpp @@ -35,8 +35,8 @@ optional ParseSeekPos(const optional &whence) return make_optional(static_cast(move(whence.value()))); } -ani_double LseekAni::LseekSync( - ani_env *env, [[maybe_unused]] ani_class clazz, ani_double fd, ani_double offset, ani_enum_item whence) +ani_long LseekAni::LseekSync( + ani_env *env, [[maybe_unused]] ani_class clazz, ani_int fd, ani_long offset, ani_enum_item whence) { auto [succWhence, whenceOp] = TypeConverter::EnumToInt32(env, whence); if (!succWhence) { @@ -46,7 +46,7 @@ ani_double LseekAni::LseekSync( } auto pos = ParseSeekPos(whenceOp); - auto ret = LseekCore::DoLseek(static_cast(fd), static_cast(offset), pos); + auto ret = LseekCore::DoLseek(fd, offset, pos); if (!ret.IsSuccess()) { HILOGE("DoLseek failed!"); const FsError &err = ret.GetError(); @@ -54,7 +54,7 @@ ani_double LseekAni::LseekSync( return -1; } - return ani_double(static_cast(ret.GetData().value())); + return ret.GetData().value(); } } // namespace ANI diff --git a/interfaces/kits/js/src/mod_fs/properties/ani/lseek_ani.h b/interfaces/kits/js/src/mod_fs/properties/ani/lseek_ani.h index 5a7995d79..5c1084fa7 100644 --- a/interfaces/kits/js/src/mod_fs/properties/ani/lseek_ani.h +++ b/interfaces/kits/js/src/mod_fs/properties/ani/lseek_ani.h @@ -24,8 +24,8 @@ namespace ModuleFileIO { namespace ANI { class LseekAni final { public: - static ani_double LseekSync( - ani_env *env, [[maybe_unused]] ani_class clazz, ani_double fd, ani_double offset, ani_enum_item whence); + static ani_long LseekSync( + ani_env *env, [[maybe_unused]] ani_class clazz, ani_int fd, ani_long offset, ani_enum_item whence); }; } // namespace ANI } // namespace ModuleFileIO diff --git a/interfaces/kits/js/src/mod_fs/properties/ani/read_ani.cpp b/interfaces/kits/js/src/mod_fs/properties/ani/read_ani.cpp index fa5ce2334..36bcd2040 100644 --- a/interfaces/kits/js/src/mod_fs/properties/ani/read_ani.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/ani/read_ani.cpp @@ -52,8 +52,8 @@ static tuple> ToReadOptions(ani_env *env, ani_object return { true, make_optional(move(options)) }; } -ani_double ReadAni::ReadSync( - ani_env *env, [[maybe_unused]] ani_class clazz, ani_double fd, ani_arraybuffer buffer, ani_object options) +ani_long ReadAni::ReadSync( + ani_env *env, [[maybe_unused]] ani_class clazz, ani_int fd, ani_arraybuffer buffer, ani_object options) { auto [succBuf, arrayBuffer] = TypeConverter::ToArrayBuffer(env, buffer); if (!succBuf) { @@ -69,13 +69,13 @@ ani_double ReadAni::ReadSync( return -1; } - auto ret = ReadCore::DoRead(static_cast(fd), arrayBuffer, op); + auto ret = ReadCore::DoRead(fd, arrayBuffer, op); if (!ret.IsSuccess()) { HILOGE("Read file content failed!"); const auto &err = ret.GetError(); ErrorHandler::Throw(env, err); return -1; } - return static_cast(ret.GetData().value()); + return ret.GetData().value(); } } // namespace OHOS::FileManagement::ModuleFileIO::ANI \ No newline at end of file diff --git a/interfaces/kits/js/src/mod_fs/properties/ani/read_ani.h b/interfaces/kits/js/src/mod_fs/properties/ani/read_ani.h index 2f18a20f3..7292576b4 100644 --- a/interfaces/kits/js/src/mod_fs/properties/ani/read_ani.h +++ b/interfaces/kits/js/src/mod_fs/properties/ani/read_ani.h @@ -22,8 +22,8 @@ namespace OHOS::FileManagement::ModuleFileIO::ANI { class ReadAni final { public: - static ani_double ReadSync( - ani_env *env, [[maybe_unused]] ani_class clazz, ani_double fd, ani_arraybuffer buffer, ani_object options); + static ani_long ReadSync( + ani_env *env, [[maybe_unused]] ani_class clazz, ani_int fd, ani_arraybuffer buffer, ani_object options); }; } // namespace OHOS::FileManagement::ModuleFileIO::ANI -- Gitee From e1005f57f79e1b1ee844339b5c96a83625f34443 Mon Sep 17 00:00:00 2001 From: tianp Date: Fri, 18 Jul 2025 14:27:05 +0800 Subject: [PATCH 04/10] number to int Signed-off-by: tianp Change-Id: I4cf4a7efc00e15bac3b4414fd6b8b43224555737 --- .../js/src/mod_fs/ani/ets/@ohos.file.fs.ets | 164 +++++++++--------- .../ani/randomaccessfile_ani.cpp | 12 +- .../ani/randomaccessfile_ani.h | 6 +- .../src/mod_fs/properties/ani/fsync_ani.cpp | 2 +- .../js/src/mod_fs/properties/ani/fsync_ani.h | 2 +- .../src/mod_fs/properties/ani/write_ani.cpp | 8 +- .../js/src/mod_fs/properties/ani/write_ani.h | 4 +- .../ani/ets/@ohos.file.statvfs.ets | 28 +-- .../js/src/mod_statvfs/ani/statvfs_ani.cpp | 8 +- .../kits/js/src/mod_statvfs/ani/statvfs_ani.h | 4 +- 10 files changed, 119 insertions(+), 119 deletions(-) diff --git a/interfaces/kits/js/src/mod_fs/ani/ets/@ohos.file.fs.ets b/interfaces/kits/js/src/mod_fs/ani/ets/@ohos.file.fs.ets index 9505296fe..fd1094ad6 100644 --- a/interfaces/kits/js/src/mod_fs/ani/ets/@ohos.file.fs.ets +++ b/interfaces/kits/js/src/mod_fs/ani/ets/@ohos.file.fs.ets @@ -413,13 +413,13 @@ function mkdtemp(prefix: string, callback: AsyncCallback): void { }); } -function moveFileSync(src: string, dest: string, mode?: number): void { +function moveFileSync(src: string, dest: string, mode?: int): void { return FileIoImpl.moveFileSync(src, dest, mode); } -function moveFile(src: string, dest: string, mode?: number): Promise { +function moveFile(src: string, dest: string, mode?: int): Promise { return new Promise((resolve: (result: undefined) => void, reject: (e: BusinessError) => void): void => { - let promise = taskpool.execute((src: string, dest: string, mode?: number): undefined => { + let promise = taskpool.execute((src: string, dest: string, mode?: int): undefined => { return FileIoImpl.moveFileSync(src, dest, mode); }, src, dest, mode); promise.then((ret: NullishType): void => { @@ -430,8 +430,8 @@ function moveFile(src: string, dest: string, mode?: number): Promise { }); } -function moveFile(src: string, dest: string, mode: number, callback: AsyncCallback): void { - let promise = taskpool.execute((src: string, dest: string, mode: number): undefined => { +function moveFile(src: string, dest: string, mode: int, callback: AsyncCallback): void { + let promise = taskpool.execute((src: string, dest: string, mode: int): undefined => { return FileIoImpl.moveFileSync(src, dest, mode); }, src, dest, mode); promise.then((ret: NullishType): void => { @@ -456,13 +456,13 @@ function moveFile(src: string, dest: string, callback: AsyncCallback): voi }); } -function openSync(path: string, mode?: number): File { +function openSync(path: string, mode?: int): File { return FileIoImpl.openSync(path, mode); } -function open(path: String, mode?: number): Promise { +function open(path: String, mode?: int): Promise { return new Promise((resolve: (result: File) => void, reject: (e: BusinessError) => void) => { - let promise = taskpool.execute((path: String, mode?: number): File => { + let promise = taskpool.execute((path: String, mode?: int): File => { return FileIoImpl.openSync(path, mode); },path, mode); promise.then((ret: NullishType): void => { @@ -474,8 +474,8 @@ function open(path: String, mode?: number): Promise { }); } -function open(path: String, mode: number, callback: AsyncCallback): void { - let promise = taskpool.execute((path: String, mode: number): File => { +function open(path: String, mode: int, callback: AsyncCallback): void { + let promise = taskpool.execute((path: String, mode: int): File => { return FileIoImpl.openSync(path, mode); }, path, mode); promise.then((ret: NullishType): void => { @@ -504,17 +504,17 @@ function open(path: String, callback: AsyncCallback): void { }); } -function writeSync(fd: number, buffer: string | ArrayBuffer, options?: WriteOptions): number { +function writeSync(fd: int, buffer: string | ArrayBuffer, options?: WriteOptions): long { return FileIoImpl.writeSync(fd, buffer, options); } -function write(fd: number, buffer: string | ArrayBuffer, options?: WriteOptions): Promise { - return new Promise((resolve: (result: number) => void, reject: (e: BusinessError) => void) => { - let promise = taskpool.execute((fd: number, buffer: string | ArrayBuffer, options?: WriteOptions): number => { +function write(fd: int, buffer: string | ArrayBuffer, options?: WriteOptions): Promise { + return new Promise((resolve: (result: long) => void, reject: (e: BusinessError) => void) => { + let promise = taskpool.execute((fd: int, buffer: string | ArrayBuffer, options?: WriteOptions): long => { return FileIoImpl.writeSync(fd, buffer, options); }, fd, buffer, options); promise.then((ret: NullishType): void => { - let result = ret as number + let result = ret as long resolve(result); }).catch((e: Error): void => { reject(e as BusinessError); @@ -522,29 +522,29 @@ function write(fd: number, buffer: string | ArrayBuffer, options?: WriteOptions) }); } -function write(fd: number, buffer: string | ArrayBuffer, options: WriteOptions, - callback: AsyncCallback): void { - let promise = taskpool.execute((fd: number, buffer: string | ArrayBuffer, options: WriteOptions): number => { +function write(fd: int, buffer: string | ArrayBuffer, options: WriteOptions, + callback: AsyncCallback): void { + let promise = taskpool.execute((fd: int, buffer: string | ArrayBuffer, options: WriteOptions): long => { return FileIoImpl.writeSync(fd, buffer, options); }, fd, buffer, options); promise.then((ret: NullishType): void => { let e = new BusinessError(); e.code = 0; - let result = ret as number; + let result = ret as long; callback(e, result); }).catch((e: Error): void => { callback(e as BusinessError, 0); }); } -function write(fd: number, buffer: string | ArrayBuffer, callback: AsyncCallback): void { - let promise = taskpool.execute((fd: number, buffer: string | ArrayBuffer): number => { +function write(fd: int, buffer: string | ArrayBuffer, callback: AsyncCallback): void { + let promise = taskpool.execute((fd: int, buffer: string | ArrayBuffer): long => { return FileIoImpl.writeSync(fd, buffer); }, fd, buffer); promise.then((ret: NullishType): void => { let e = new BusinessError(); e.code = 0; - let result = ret as number; + let result = ret as long; callback(e, result); }).catch((e: Error): void => { callback(e as BusinessError, 0); @@ -871,13 +871,13 @@ function stat(file: string | int, callback: AsyncCallback): void { }); } -function fsyncSync(fd: number): void { +function fsyncSync(fd: int): void { return FileIoImpl.fsyncSync(fd); } -function fsync(fd: number): Promise { +function fsync(fd: int): Promise { return new Promise((resolve: (result: undefined) => void, reject: (e: BusinessError) => void): void => { - let promise = taskpool.execute((fd: number): undefined => { + let promise = taskpool.execute((fd: int): undefined => { return FileIoImpl.fsyncSync(fd); }, fd); promise.then((ret: NullishType): void => { @@ -888,8 +888,8 @@ function fsync(fd: number): Promise { }); } -function fsync(fd: number, callback: AsyncCallback): void { - let promise = taskpool.execute((fd: number): undefined => { +function fsync(fd: int, callback: AsyncCallback): void { + let promise = taskpool.execute((fd: int): undefined => { return FileIoImpl.fsyncSync(fd); }, fd); promise.then((ret: NullishType): void => { @@ -948,16 +948,16 @@ function rename(oldPath: string, newPath: string, callback: AsyncCallback) }); } -function createRandomAccessFileSync(file: string | File, mode?: number, +function createRandomAccessFileSync(file: string | File, mode?: int, options?: RandomAccessFileOptions): RandomAccessFile { return FileIoImpl.createRandomAccessFileSync(file, mode, options); } -function createRandomAccessFile(file: string | File, mode?: number, +function createRandomAccessFile(file: string | File, mode?: int, options?: RandomAccessFileOptions): Promise { return new Promise((resolve: (result: RandomAccessFile) => void, reject: (e: BusinessError) => void) => { - let promise = taskpool.execute((file: string | File, mode?: number, + let promise = taskpool.execute((file: string | File, mode?: int, options?: RandomAccessFileOptions): RandomAccessFile => { return FileIoImpl.createRandomAccessFileSync(file, mode, options); }, file, mode, options); @@ -1015,9 +1015,9 @@ function createRandomAccessFile(file: string | File, callback: AsyncCallback): void { - let promise = taskpool.execute((file: string | File, mode: number): RandomAccessFile => { + let promise = taskpool.execute((file: string | File, mode: int): RandomAccessFile => { return FileIoImpl.createRandomAccessFileSync(file, mode); }, file, mode); promise.then((ret: NullishType): void => { @@ -1307,26 +1307,26 @@ export enum AccessFlagType { } export interface RandomAccessFile { - fd: number; - filePointer: number; + fd: int; + filePointer: long; - setFilePointer(filePointer: number): void; + setFilePointer(filePointer: long): void; close(): void; - write(buffer: ArrayBuffer | string, options?: WriteOptions): Promise; - write(buffer: ArrayBuffer | string, callback: AsyncCallback): void; - write(buffer: ArrayBuffer | string, options: WriteOptions, callback: AsyncCallback): void; - writeSync(buffer: ArrayBuffer | string, options?: WriteOptions): number; - read(buffer: ArrayBuffer, options?: ReadOptions): Promise; - read(buffer: ArrayBuffer, callback: AsyncCallback): void; - read(buffer: ArrayBuffer, options: ReadOptions, callback: AsyncCallback): void; - readSync(buffer: ArrayBuffer, options?: ReadOptions): number; + write(buffer: ArrayBuffer | string, options?: WriteOptions): Promise; + write(buffer: ArrayBuffer | string, callback: AsyncCallback): void; + write(buffer: ArrayBuffer | string, options: WriteOptions, callback: AsyncCallback): void; + writeSync(buffer: ArrayBuffer | string, options?: WriteOptions): long; + read(buffer: ArrayBuffer, options?: ReadOptions): Promise; + read(buffer: ArrayBuffer, callback: AsyncCallback): void; + read(buffer: ArrayBuffer, options: ReadOptions, callback: AsyncCallback): void; + readSync(buffer: ArrayBuffer, options?: ReadOptions): long; getReadStream(): ReadStream; getWriteStream(): WriteStream; } export class RandomAccessFileInner implements RandomAccessFile { - fd: number = -1; - filePointer: number = -1; + fd: int = -1; + filePointer: long = -1; private nativePtr: long = 0; @@ -1336,30 +1336,30 @@ export class RandomAccessFileInner implements RandomAccessFile { } } - setFilePointer(filePointer: number): void { + setFilePointer(filePointer: long): void { this.setFilePointer0(filePointer); this.filePointer = filePointer; } - native setFilePointer0(filePointer: number): void; + native setFilePointer0(filePointer: long): void; native close(): void; - writeSync(buffer: ArrayBuffer | string, options?: WriteOptions): number { + writeSync(buffer: ArrayBuffer | string, options?: WriteOptions): long { let length = options ? this.writeSync0(buffer, options) : this.writeSync0(buffer); this.filePointer += (options?.offset?? 0) + length; return length; } - native writeSync0(buffer: ArrayBuffer | string, options?: WriteOptions): number; + native writeSync0(buffer: ArrayBuffer | string, options?: WriteOptions): long; - write(buffer: ArrayBuffer | string, options?: WriteOptions): Promise { - return new Promise((resolve: (result: number) => void, reject: (e: BusinessError) => void) => { - let promise = taskpool.execute((buffer: ArrayBuffer | string, options?: WriteOptions): number => { + write(buffer: ArrayBuffer | string, options?: WriteOptions): Promise { + return new Promise((resolve: (result: long) => void, reject: (e: BusinessError) => void) => { + let promise = taskpool.execute((buffer: ArrayBuffer | string, options?: WriteOptions): long => { return this.writeSync(buffer, options); }, buffer, options); promise.then((ret: NullishType): void => { - let result = ret as number + let result = ret as long resolve(result); }).catch((e: Error): void => { reject(e as BusinessError); @@ -1367,49 +1367,49 @@ export class RandomAccessFileInner implements RandomAccessFile { }); } - write(buffer: ArrayBuffer | string, options: WriteOptions, callback: AsyncCallback): void { - let promise = taskpool.execute((buffer: ArrayBuffer | string, options: WriteOptions): number => { + write(buffer: ArrayBuffer | string, options: WriteOptions, callback: AsyncCallback): void { + let promise = taskpool.execute((buffer: ArrayBuffer | string, options: WriteOptions): long => { return this.writeSync(buffer, options); }, buffer, options); promise.then((ret: NullishType): void => { let e = new BusinessError(); e.code = 0; - let result = ret as number; + let result = ret as long; callback(e, result); }).catch((e: Error): void => { callback(e as BusinessError, 0); }); } - write(buffer: ArrayBuffer | string, callback: AsyncCallback): void { - let promise = taskpool.execute((buffer: ArrayBuffer | string): number => { + write(buffer: ArrayBuffer | string, callback: AsyncCallback): void { + let promise = taskpool.execute((buffer: ArrayBuffer | string): long => { return this.writeSync(buffer); }, buffer); promise.then((ret: NullishType): void => { let e = new BusinessError(); e.code = 0; - let result = ret as number; + let result = ret as long; callback(e, result); }).catch((e: Error): void => { callback(e as BusinessError, 0); }); } - readSync(buffer: ArrayBuffer, options?: ReadOptions): number { + readSync(buffer: ArrayBuffer, options?: ReadOptions): long { const length = options ? this.readSync0(buffer, options) : this.readSync0(buffer); this.filePointer += (options?.offset?? 0) + length; return length; } - native readSync0(buffer: ArrayBuffer, options?: ReadOptions): number; + native readSync0(buffer: ArrayBuffer, options?: ReadOptions): long; - read(buffer: ArrayBuffer, options?: ReadOptions): Promise { - return new Promise((resolve: (result: number) => void, reject: (e: BusinessError) => void) => { - let promise = taskpool.execute((buffer: ArrayBuffer, options?: ReadOptions): number => { + read(buffer: ArrayBuffer, options?: ReadOptions): Promise { + return new Promise((resolve: (result: long) => void, reject: (e: BusinessError) => void) => { + let promise = taskpool.execute((buffer: ArrayBuffer, options?: ReadOptions): long => { return this.readSync(buffer, options); }, buffer, options); promise.then((ret: NullishType): void => { - let result = ret as number; + let result = ret as long; resolve(result); }).catch((e: Error): void => { reject(e as BusinessError); @@ -1417,28 +1417,28 @@ export class RandomAccessFileInner implements RandomAccessFile { }); } - read(buffer: ArrayBuffer, options: ReadOptions, callback: AsyncCallback): void { - let promise = taskpool.execute((buffer: ArrayBuffer, options: ReadOptions): number => { + read(buffer: ArrayBuffer, options: ReadOptions, callback: AsyncCallback): void { + let promise = taskpool.execute((buffer: ArrayBuffer, options: ReadOptions): long => { return this.readSync(buffer, options); }, buffer, options); promise.then((ret: NullishType): void => { let e = new BusinessError(); e.code = 0; - let result = ret as number; + let result = ret as long; callback(e, result); }).catch((e: Error): void => { callback(e as BusinessError, 0); }); } - read(buffer: ArrayBuffer, callback: AsyncCallback): void { - let promise = taskpool.execute((buffer: ArrayBuffer): number => { + read(buffer: ArrayBuffer, callback: AsyncCallback): void { + let promise = taskpool.execute((buffer: ArrayBuffer): long => { return this.readSync(buffer); }, buffer); promise.then((ret: NullishType): void => { let e = new BusinessError(); e.code = 0; - let result = ret as number; + let result = ret as long; callback(e, result); }).catch((e: Error): void => { callback(e as BusinessError, 0); @@ -1450,7 +1450,7 @@ export class RandomAccessFileInner implements RandomAccessFile { } export interface File { - fd: number; + fd: int; path: String; name: String; @@ -1463,7 +1463,7 @@ export interface File { } export class FileInner implements File { - fd: number = -1; + fd: int = -1; path: String = ""; name: String = ""; @@ -2048,13 +2048,13 @@ export interface ReadTextOptions extends ReadOptions { } export interface WriteOptions extends Options { - offset?: number; - length?: number; + offset?: long; + length?: long; } export interface RandomAccessFileOptions { - start?: number; - end?: number; + start?: long; + end?: long; } export interface ListFileOptions { @@ -2149,9 +2149,9 @@ export class FileIoImpl { static native mkdtempSync(prefix: string): string; - static native moveFileSync(src: String, dest: String, mode?: number): void; + static native moveFileSync(src: String, dest: String, mode?: int): void; - static native openSync(path: String, mode?: number): fileIo.File; + static native openSync(path: String, mode?: int): fileIo.File; static native readlinesSync(filePath: string, options?: Options): fileIo.ReaderIterator; @@ -2169,13 +2169,13 @@ export class FileIoImpl { static native unlinkSync(path: string): void; - static native writeSync(fd: number, buffer: string | ArrayBuffer, options?: WriteOptions): number; + static native writeSync(fd: int, buffer: string | ArrayBuffer, options?: WriteOptions): long; - static native fsyncSync(fd: number): void; + static native fsyncSync(fd: int): void; static native renameSync(oldPath: string, newPath: string): void; - static native createRandomAccessFileSync(file: string | fileIo.File, mode?: number, + static native createRandomAccessFileSync(file: string | fileIo.File, mode?: int, options?: RandomAccessFileOptions): fileIo.RandomAccessFile; static native symlinkSync(target: string, srcPath: string): void; diff --git a/interfaces/kits/js/src/mod_fs/class_randomaccessfile/ani/randomaccessfile_ani.cpp b/interfaces/kits/js/src/mod_fs/class_randomaccessfile/ani/randomaccessfile_ani.cpp index 604835791..f3172480b 100644 --- a/interfaces/kits/js/src/mod_fs/class_randomaccessfile/ani/randomaccessfile_ani.cpp +++ b/interfaces/kits/js/src/mod_fs/class_randomaccessfile/ani/randomaccessfile_ani.cpp @@ -134,7 +134,7 @@ static tuple ParseArrayBuffer(ani_env *env, const ani_obj return { true, move(result) }; } -void RandomAccessFileAni::SetFilePointer(ani_env *env, [[maybe_unused]] ani_object object, ani_double fp) +void RandomAccessFileAni::SetFilePointer(ani_env *env, [[maybe_unused]] ani_object object, ani_long fp) { auto rafFile = Unwrap(env, object); if (rafFile == nullptr) { @@ -168,7 +168,7 @@ void RandomAccessFileAni::Close(ani_env *env, [[maybe_unused]] ani_object object } } -ani_double RandomAccessFileAni::WriteSync( +ani_long RandomAccessFileAni::WriteSync( ani_env *env, [[maybe_unused]] ani_object object, ani_object buf, ani_object options) { auto rafFile = Unwrap(env, object); @@ -199,7 +199,7 @@ ani_double RandomAccessFileAni::WriteSync( ErrorHandler::Throw(env, ret.GetError()); return -1; } - return static_cast(ret.GetData().value()); + return static_cast(ret.GetData().value()); } auto [isArrayBuffer, arrayBuffer] = ParseArrayBuffer(env, buf); @@ -216,14 +216,14 @@ ani_double RandomAccessFileAni::WriteSync( ErrorHandler::Throw(env, ret.GetError()); return -1; } - return static_cast(ret.GetData().value()); + return static_cast(ret.GetData().value()); } HILOGE("Unsupported buffer type!"); ErrorHandler::Throw(env, EINVAL); return -1; } -ani_double RandomAccessFileAni::ReadSync( +ani_long RandomAccessFileAni::ReadSync( ani_env *env, [[maybe_unused]] ani_object object, ani_arraybuffer buf, ani_object options) { auto rafFile = Unwrap(env, object); @@ -254,7 +254,7 @@ ani_double RandomAccessFileAni::ReadSync( ErrorHandler::Throw(env, err); return -1; } - return static_cast(ret.GetData().value()); + return static_cast(ret.GetData().value()); } static ani_string GetFilePath(ani_env *env, const int fd) diff --git a/interfaces/kits/js/src/mod_fs/class_randomaccessfile/ani/randomaccessfile_ani.h b/interfaces/kits/js/src/mod_fs/class_randomaccessfile/ani/randomaccessfile_ani.h index d1a29d8ec..f47ee7098 100644 --- a/interfaces/kits/js/src/mod_fs/class_randomaccessfile/ani/randomaccessfile_ani.h +++ b/interfaces/kits/js/src/mod_fs/class_randomaccessfile/ani/randomaccessfile_ani.h @@ -25,10 +25,10 @@ namespace ANI { class RandomAccessFileAni final { public: - static void SetFilePointer(ani_env *env, [[maybe_unused]] ani_object object, ani_double fp); + static void SetFilePointer(ani_env *env, [[maybe_unused]] ani_object object, ani_long fp); static void Close(ani_env *env, [[maybe_unused]] ani_object object); - static ani_double WriteSync(ani_env *env, [[maybe_unused]] ani_object object, ani_object buf, ani_object options); - static ani_double ReadSync( + static ani_long WriteSync(ani_env *env, [[maybe_unused]] ani_object object, ani_object buf, ani_object options); + static ani_long ReadSync( ani_env *env, [[maybe_unused]] ani_object object, ani_arraybuffer buf, ani_object options); static ani_object GetReadStream(ani_env *env, [[maybe_unused]] ani_object object); static ani_object GetWriteStream(ani_env *env, [[maybe_unused]] ani_object object); diff --git a/interfaces/kits/js/src/mod_fs/properties/ani/fsync_ani.cpp b/interfaces/kits/js/src/mod_fs/properties/ani/fsync_ani.cpp index f2680914f..339e2fea4 100644 --- a/interfaces/kits/js/src/mod_fs/properties/ani/fsync_ani.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/ani/fsync_ani.cpp @@ -25,7 +25,7 @@ namespace ModuleFileIO { namespace ANI { using namespace OHOS::FileManagement::ModuleFileIO; -void FsyncAni::FsyncSync(ani_env *env, [[maybe_unused]] ani_class clazz, ani_double fd) +void FsyncAni::FsyncSync(ani_env *env, [[maybe_unused]] ani_class clazz, ani_int fd) { auto ret = FsyncCore::DoFsync(static_cast(fd)); if (!ret.IsSuccess()) { diff --git a/interfaces/kits/js/src/mod_fs/properties/ani/fsync_ani.h b/interfaces/kits/js/src/mod_fs/properties/ani/fsync_ani.h index ad9d936fe..33da8bf63 100644 --- a/interfaces/kits/js/src/mod_fs/properties/ani/fsync_ani.h +++ b/interfaces/kits/js/src/mod_fs/properties/ani/fsync_ani.h @@ -25,7 +25,7 @@ namespace ANI { class FsyncAni final { public: - static void FsyncSync(ani_env *env, [[maybe_unused]] ani_class clazz, ani_double fd); + static void FsyncSync(ani_env *env, [[maybe_unused]] ani_class clazz, ani_int fd); }; } // namespace ANI } // namespace ModuleFileIO diff --git a/interfaces/kits/js/src/mod_fs/properties/ani/write_ani.cpp b/interfaces/kits/js/src/mod_fs/properties/ani/write_ani.cpp index 6c718e079..99954aacf 100644 --- a/interfaces/kits/js/src/mod_fs/properties/ani/write_ani.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/ani/write_ani.cpp @@ -94,8 +94,8 @@ static std::tuple ParseArrayBuffer(ani_env *env, const an return { true, std::move(result) }; } -ani_double WriteAni::WriteSync( - ani_env *env, [[maybe_unused]] ani_class clazz, ani_double fd, ani_object buf, ani_object options) +ani_long WriteAni::WriteSync( + ani_env *env, [[maybe_unused]] ani_class clazz, ani_int fd, ani_object buf, ani_object options) { auto [succOp, op] = ToWriteOptions(env, options); if (!succOp) { @@ -119,7 +119,7 @@ ani_double WriteAni::WriteSync( ErrorHandler::Throw(env, err); return -1; } - return static_cast(ret.GetData().value()); + return static_cast(ret.GetData().value()); } auto [isArrayBuffer, arrayBuffer] = ParseArrayBuffer(env, buf); @@ -137,7 +137,7 @@ ani_double WriteAni::WriteSync( ErrorHandler::Throw(env, err); return -1; } - return static_cast(ret.GetData().value()); + return static_cast(ret.GetData().value()); } HILOGE("Unsupported buffer type!"); ErrorHandler::Throw(env, EINVAL); diff --git a/interfaces/kits/js/src/mod_fs/properties/ani/write_ani.h b/interfaces/kits/js/src/mod_fs/properties/ani/write_ani.h index 2ac1c8d70..3d28f711e 100644 --- a/interfaces/kits/js/src/mod_fs/properties/ani/write_ani.h +++ b/interfaces/kits/js/src/mod_fs/properties/ani/write_ani.h @@ -25,8 +25,8 @@ namespace ANI { class WriteAni final { public: - static ani_double WriteSync( - ani_env *env, [[maybe_unused]] ani_class clazz, ani_double fd, ani_object buf, ani_object options); + static ani_long WriteSync( + ani_env *env, [[maybe_unused]] ani_class clazz, ani_int fd, ani_object buf, ani_object options); }; } // namespace ANI diff --git a/interfaces/kits/js/src/mod_statvfs/ani/ets/@ohos.file.statvfs.ets b/interfaces/kits/js/src/mod_statvfs/ani/ets/@ohos.file.statvfs.ets index f3c569c80..64d8e7284 100644 --- a/interfaces/kits/js/src/mod_statvfs/ani/ets/@ohos.file.statvfs.ets +++ b/interfaces/kits/js/src/mod_statvfs/ani/ets/@ohos.file.statvfs.ets @@ -16,15 +16,15 @@ import { BusinessError, AsyncCallback } from '@ohos.base'; namespace statfs { - export function getFreeSizeSync(path: string): number { + export function getFreeSizeSync(path: string): long { return StatvfsImpl.getFreeSizeSync(path); } - export function getFreeSize(path: string): Promise { - return new Promise((resolve: (result: number) => void, reject: (e: BusinessError) => void): void => { + export function getFreeSize(path: string): Promise { + return new Promise((resolve: (result: long) => void, reject: (e: BusinessError) => void): void => { let promise = taskpool.execute(StatvfsImpl.getFreeSizeSync, path); promise.then((ret: NullishType): void => { - let result = ret as number + let result = ret as long resolve(result); }).catch((e: Error): void => { reject(e as BusinessError); @@ -32,27 +32,27 @@ namespace statfs { }); } - export function getFreeSize(path: string, callback: AsyncCallback): void { + export function getFreeSize(path: string, callback: AsyncCallback): void { let promise = taskpool.execute(StatvfsImpl.getFreeSizeSync, path); promise.then((ret: NullishType): void => { let e = new BusinessError(); e.code = 0; - let result = ret as number; + let result = ret as long; callback(e, result); }).catch((e: Error): void => { callback(e as BusinessError, 0); }); } - export function getTotalSizeSync(path: string): number { + export function getTotalSizeSync(path: string): long { return StatvfsImpl.getTotalSizeSync(path); } - export function getTotalSize(path: string): Promise { - return new Promise((resolve: (result: number) => void, reject: (e: BusinessError) => void): void => { + export function getTotalSize(path: string): Promise { + return new Promise((resolve: (result: long) => void, reject: (e: BusinessError) => void): void => { let promise = taskpool.execute(StatvfsImpl.getTotalSizeSync, path); promise.then((ret: NullishType): void => { - let result = ret as number + let result = ret as long resolve(result); }).catch((e: Error): void => { reject(e as BusinessError); @@ -60,12 +60,12 @@ namespace statfs { }); } - export function getTotalSize(path: string, callback: AsyncCallback): void { + export function getTotalSize(path: string, callback: AsyncCallback): void { let promise = taskpool.execute(StatvfsImpl.getTotalSizeSync, path); promise.then((ret: NullishType): void => { let e = new BusinessError(); e.code = 0; - let result = ret as number; + let result = ret as long; callback(e, result); }).catch((e: Error): void => { callback(e as BusinessError, 0); @@ -81,6 +81,6 @@ class StatvfsImpl { loadLibrary("ani_file_statvfs"); } - static native getFreeSizeSync(path: string): number; - static native getTotalSizeSync(path: string): number; + static native getFreeSizeSync(path: string): long; + static native getTotalSizeSync(path: string): long; } diff --git a/interfaces/kits/js/src/mod_statvfs/ani/statvfs_ani.cpp b/interfaces/kits/js/src/mod_statvfs/ani/statvfs_ani.cpp index 337b78f84..0617b43db 100644 --- a/interfaces/kits/js/src/mod_statvfs/ani/statvfs_ani.cpp +++ b/interfaces/kits/js/src/mod_statvfs/ani/statvfs_ani.cpp @@ -29,7 +29,7 @@ using namespace std; using namespace OHOS::FileManagement::ModuleFileIO; using namespace OHOS::FileManagement::ModuleStatvfs; -ani_double StatvfsAni::GetFreeSizeSync(ani_env *env, [[maybe_unused]] ani_class clazz, ani_string path) +ani_long StatvfsAni::GetFreeSizeSync(ani_env *env, [[maybe_unused]] ani_class clazz, ani_string path) { auto [succPath, srcPath] = TypeConverter::ToUTF8String(env, path); if (!succPath) { @@ -46,10 +46,10 @@ ani_double StatvfsAni::GetFreeSizeSync(ani_env *env, [[maybe_unused]] ani_class return 0; } - return static_cast(ret.GetData().value()); + return static_cast(ret.GetData().value()); } -ani_double StatvfsAni::GetTotalSizeSync(ani_env *env, [[maybe_unused]] ani_class clazz, ani_string path) +ani_long StatvfsAni::GetTotalSizeSync(ani_env *env, [[maybe_unused]] ani_class clazz, ani_string path) { auto [succPath, srcPath] = TypeConverter::ToUTF8String(env, path); if (!succPath) { @@ -66,7 +66,7 @@ ani_double StatvfsAni::GetTotalSizeSync(ani_env *env, [[maybe_unused]] ani_class return 0; } - return static_cast(ret.GetData().value()); + return static_cast(ret.GetData().value()); } } // namespace ANI diff --git a/interfaces/kits/js/src/mod_statvfs/ani/statvfs_ani.h b/interfaces/kits/js/src/mod_statvfs/ani/statvfs_ani.h index 1eaf5081f..feb2854a6 100644 --- a/interfaces/kits/js/src/mod_statvfs/ani/statvfs_ani.h +++ b/interfaces/kits/js/src/mod_statvfs/ani/statvfs_ani.h @@ -25,8 +25,8 @@ namespace ANI { class StatvfsAni final { public: - static ani_double GetFreeSizeSync(ani_env *env, [[maybe_unused]] ani_class clazz, ani_string path); - static ani_double GetTotalSizeSync(ani_env *env, [[maybe_unused]] ani_class clazz, ani_string path); + static ani_long GetFreeSizeSync(ani_env *env, [[maybe_unused]] ani_class clazz, ani_string path); + static ani_long GetTotalSizeSync(ani_env *env, [[maybe_unused]] ani_class clazz, ani_string path); }; } // namespace ANI -- Gitee From d7a816ed4da7f3e9c91ee98aeb72e48e3636a53a Mon Sep 17 00:00:00 2001 From: liyuke Date: Sun, 20 Jul 2025 20:43:58 +0800 Subject: [PATCH 05/10] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liyuke Change-Id: Ie34887ebd312e96274892653887da44bb6c2a72e --- .../js/src/mod_fs/ani/ets/@ohos.file.fs.ets | 59 ++++++++----------- .../mod_fs/class_file/ani/file_wrapper.cpp | 2 +- .../mod_fs/class_stat/ani/stat_wrapper.cpp | 45 +++++++++++--- .../class_watcher/ani/watch_event_wrapper.cpp | 4 +- 4 files changed, 64 insertions(+), 46 deletions(-) diff --git a/interfaces/kits/js/src/mod_fs/ani/ets/@ohos.file.fs.ets b/interfaces/kits/js/src/mod_fs/ani/ets/@ohos.file.fs.ets index fd1094ad6..28f522c36 100644 --- a/interfaces/kits/js/src/mod_fs/ani/ets/@ohos.file.fs.ets +++ b/interfaces/kits/js/src/mod_fs/ani/ets/@ohos.file.fs.ets @@ -1091,7 +1091,7 @@ function createWriteStream(path: string, options?: WriteStreamOptions): WriteStr return new WriteStream(path, options); } -function createWatcher(path: string, events: number, listener: WatchEventListener): Watcher { +function createWatcher(path: string, events: int, listener: WatchEventListener): Watcher { return FileIoImpl.createWatcherSync(path, events, listener); } @@ -1250,10 +1250,10 @@ export interface DfsListeners { } export class ProgressInner implements Progress { - processedSize: number; - totalSize: number; + processedSize: long; + totalSize: long; - constructor(pSize: number, tSize: number) { + constructor(pSize: long, tSize: long) { this.processedSize = pSize; this.totalSize = tSize; } @@ -1560,8 +1560,8 @@ export class ReaderIteratorInner implements ReaderIterator { export interface Stat { ino: bigint; mode: int; - uid: int; - gid: int; + uid: long; + gid: long; size: long; atime: long; mtime: long; @@ -1582,13 +1582,13 @@ export interface Stat { export class StatInner implements Stat { ino: bigint = 0n; - mode: number; - uid: number; - gid: number; - size: number; - atime: number; - mtime: number; - ctime: number; + mode: int; + uid: long; + gid: long; + size: long; + atime: long; + mtime: long; + ctime: long; atimeNs: bigint = 0n; mtimeNs: bigint = 0n; ctimeNs: bigint = 0n; @@ -2015,16 +2015,16 @@ class ConflictFilesInner implements ConflictFiles { export interface WatchEvent { fileName: string; - event: number; - cookie: number; + event: int; + cookie: int; } class WatchEventInner implements WatchEvent { fileName: string = ''; - event: number; - cookie: number; + event: int; + cookie: int; - constructor(fileName: string, event: number, cookie: number) { + constructor(fileName: string, event: int, cookie: int) { this.fileName = fileName; this.event = event; this.cookie = cookie; @@ -2039,8 +2039,8 @@ export interface Options { } export interface ReadOptions { - offset?: number; - length?: number; + offset?: long; + length?: long; } export interface ReadTextOptions extends ReadOptions { @@ -2064,13 +2064,13 @@ export interface ListFileOptions { } export interface WriteStreamOptions { - mode?: number; - start?: number; + mode?: int; + start?: long; } export interface ReadStreamOptions { - start?: number; - end?: number; + start?: long; + end?: long; } export class ReadStreamOptionsInner implements ReadStreamOptions { @@ -2090,15 +2090,6 @@ export interface ReaderIteratorResult { value: string; } -export interface Filter { - suffix?: Array; - displayName?: Array; - mimeType?: Array; - fileSizeOver?: number; - lastModifiedAfter?: number; - excludeMedia?: boolean; -} - type TaskSignal = fileIo.TaskSignal; type DfsListeners = fileIo.DfsListeners; @@ -2129,7 +2120,7 @@ export class FileIoImpl { static native createStreamSync(path: string, mode: string): fileIo.Stream; - static native createWatcherSync(path: string, events: number, listener: WatchEventListener): fileIo.Watcher; + static native createWatcherSync(path: string, events: int, listener: WatchEventListener): fileIo.Watcher; static native fdopenStreamSync(fd: int, mode: string): fileIo.Stream; diff --git a/interfaces/kits/js/src/mod_fs/class_file/ani/file_wrapper.cpp b/interfaces/kits/js/src/mod_fs/class_file/ani/file_wrapper.cpp index fcbf8aab9..b314615db 100644 --- a/interfaces/kits/js/src/mod_fs/class_file/ani/file_wrapper.cpp +++ b/interfaces/kits/js/src/mod_fs/class_file/ani/file_wrapper.cpp @@ -51,7 +51,7 @@ static bool SetFileProperties(ani_env *env, ani_class cls, ani_object obj, const } const auto &fd = fdRet.GetData().value(); - if (ANI_OK != AniHelper::SetPropertyValue(env, cls, obj, "fd", static_cast(fd))) { + if (ANI_OK != AniHelper::SetPropertyValue(env, cls, obj, "fd", fd)) { HILOGE("Set fd field value failed!"); return false; } diff --git a/interfaces/kits/js/src/mod_fs/class_stat/ani/stat_wrapper.cpp b/interfaces/kits/js/src/mod_fs/class_stat/ani/stat_wrapper.cpp index 94aae30c1..9b0139334 100644 --- a/interfaces/kits/js/src/mod_fs/class_stat/ani/stat_wrapper.cpp +++ b/interfaces/kits/js/src/mod_fs/class_stat/ani/stat_wrapper.cpp @@ -32,8 +32,24 @@ using namespace std; using namespace OHOS::FileManagement::ModuleFileIO; using namespace OHOS::FileManagement::ModuleFileIO::ANI::AniSignature; +concept AniNumType = std::is_same_v || std::is_same_v || std::is_same_v + +template +static ani_status SetNumberProperty( + ani_env *env, const ani_class &cls, ani_object &object, const char *name, T &value) +{ + ani_method setter; + ani_status ret; + if ((ret = env->Class_FindMethod(cls, name, nullptr, &setter)) != ANI_OK) { + HILOGE("Class_FindMethod Fail %{private}s, err: %{private}d", name, ret); + return ret; + } + + return env->Object_CallMethod_Void(object, setter, value); +} + static ani_status SetNumProperty( - ani_env *env, const ani_class &cls, ani_object &object, const char *name, ani_double &value) + ani_env *env, const ani_class &cls, ani_object &object, const char *name, ani_long &value) { ani_method setter; ani_status ret; @@ -136,15 +152,26 @@ const static string LOCATION_SETTER = Builder::BuildSetterName("location"); static ani_status SetProperties(ani_env *env, const ani_class &cls, ani_object &statObject, FsStat *fsStat) { ani_status ret; + vector> intProperties = { + { MODE_SETTER, fsStat->GetMode() }, + }; + for (auto iter : intProperties) { + auto key = iter.first.data(); + auto value = iter.second; + ret = SetNumberProperty(env, cls, statObject, key, value); + if (ret != ANI_OK) { + HILOGE("Object_CallMethod_Void Fail %{private}s, err: %{private}d", key, ret); + return ret; + } + } - vector> numProperties = { - { MODE_SETTER, ani_double(static_cast(fsStat->GetMode())) }, - { UID_SETTER, ani_double(static_cast(fsStat->GetUid())) }, - { GID_SETTER, ani_double(static_cast(fsStat->GetGid())) }, - { SIZE_SETTER, ani_double(static_cast(fsStat->GetSize())) }, - { ATIME_SETTER, ani_double(static_cast(fsStat->GetAtime())) }, - { MTIME_SETTER, ani_double(static_cast(fsStat->GetMtime())) }, - { CTIME_SETTER, ani_double(static_cast(fsStat->GetCtime())) }, + vector> numProperties = { + { UID_SETTER, fsStat->GetUid() }, + { GID_SETTER, fsStat->GetGid() }, + { SIZE_SETTER, fsStat->GetSize() }, + { ATIME_SETTER, fsStat->GetAtime() }, + { MTIME_SETTER, fsStat->GetMtime() }, + { CTIME_SETTER, fsStat->GetCtime() }, }; for (auto iter : numProperties) { auto key = iter.first.data(); diff --git a/interfaces/kits/js/src/mod_fs/class_watcher/ani/watch_event_wrapper.cpp b/interfaces/kits/js/src/mod_fs/class_watcher/ani/watch_event_wrapper.cpp index 1712f7f1f..3bb74f40c 100644 --- a/interfaces/kits/js/src/mod_fs/class_watcher/ani/watch_event_wrapper.cpp +++ b/interfaces/kits/js/src/mod_fs/class_watcher/ani/watch_event_wrapper.cpp @@ -49,8 +49,8 @@ ani_object WatchEventWrapper::Wrap(ani_env *env, const WatchEvent &evt) return nullptr; } - auto event = static_cast(evt.event); - auto cookie = static_cast(evt.cookie); + auto event = evt.event; + auto cookie = evt.cookie; ani_object obj; if (ANI_OK != env->Object_New(cls, ctor, &obj, fileName, event, cookie)) { -- Gitee From a3c6c551dd65b640944b9a8d3e8f6f8455633f94 Mon Sep 17 00:00:00 2001 From: wuchengjun Date: Tue, 22 Jul 2025 11:22:39 +0800 Subject: [PATCH 06/10] =?UTF-8?q?=20=20number=E8=BD=ACint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wuchengjun Change-Id: Ic6ccfb41dab2b50d97d0f47e095a6d94cdef0063 --- .../js/src/common/ani_helper/ani_signature.cpp | 2 +- .../js/src/mod_fs/ani/ets/@ohos.file.fs.ets | 18 +++++++++--------- .../src/mod_fs/class_stat/ani/stat_wrapper.cpp | 10 ++++------ .../class_watcher/ani/watch_event_wrapper.cpp | 5 +---- .../ani/create_randomaccessfile_ani.cpp | 4 ++-- .../src/mod_fs/properties/ani/watcher_ani.cpp | 4 ++-- .../js/src/mod_fs/properties/ani/watcher_ani.h | 2 +- 7 files changed, 20 insertions(+), 25 deletions(-) diff --git a/interfaces/kits/js/src/common/ani_helper/ani_signature.cpp b/interfaces/kits/js/src/common/ani_helper/ani_signature.cpp index f8a2a92de..c4cb14137 100644 --- a/interfaces/kits/js/src/common/ani_helper/ani_signature.cpp +++ b/interfaces/kits/js/src/common/ani_helper/ani_signature.cpp @@ -115,7 +115,7 @@ const string FS::WatcherInner::ctorSig = Builder::BuildSignatureDescriptor({ Bas const Type FS::WatchEventInner::classType = Builder::BuildClass("@ohos.file.fs.WatchEventInner"); const string FS::WatchEventInner::classDesc = FS::WatchEventInner::classType.Descriptor(); const string FS::WatchEventInner::ctorSig = - Builder::BuildSignatureDescriptor({ BuiltInTypes::stringType, BasicTypes::doubleType, BasicTypes::doubleType }); + Builder::BuildSignatureDescriptor({ BuiltInTypes::stringType, BasicTypes::intType, BasicTypes::intType }); // FS::ReadStream const Type FS::ReadStream::classType = Builder::BuildClass("@ohos.file.fs.fileIo.ReadStream"); const string FS::ReadStream::classDesc = FS::ReadStream::classType.Descriptor(); diff --git a/interfaces/kits/js/src/mod_fs/ani/ets/@ohos.file.fs.ets b/interfaces/kits/js/src/mod_fs/ani/ets/@ohos.file.fs.ets index 28f522c36..ee01f67f9 100644 --- a/interfaces/kits/js/src/mod_fs/ani/ets/@ohos.file.fs.ets +++ b/interfaces/kits/js/src/mod_fs/ani/ets/@ohos.file.fs.ets @@ -1231,15 +1231,6 @@ function lseek(fd: int, offset: long, whence?: WhenceType): long { return FileIoImpl.lseekSync(fd, offset, whence); } -export interface Filter { - suffix?: Array; - displayName?: Array; - mimeType?: Array; - fileSizeOver?: long; - lastModifiedAfter?: double; - excludeMedia?: boolean; -} - export interface Progress { processedSize: long; totalSize: long; @@ -2090,6 +2081,15 @@ export interface ReaderIteratorResult { value: string; } +export interface Filter { + suffix?: Array; + displayName?: Array; + mimeType?: Array; + fileSizeOver?: long; + lastModifiedAfter?: double; + excludeMedia?: boolean; +} + type TaskSignal = fileIo.TaskSignal; type DfsListeners = fileIo.DfsListeners; diff --git a/interfaces/kits/js/src/mod_fs/class_stat/ani/stat_wrapper.cpp b/interfaces/kits/js/src/mod_fs/class_stat/ani/stat_wrapper.cpp index 9b0139334..09cd422be 100644 --- a/interfaces/kits/js/src/mod_fs/class_stat/ani/stat_wrapper.cpp +++ b/interfaces/kits/js/src/mod_fs/class_stat/ani/stat_wrapper.cpp @@ -32,11 +32,8 @@ using namespace std; using namespace OHOS::FileManagement::ModuleFileIO; using namespace OHOS::FileManagement::ModuleFileIO::ANI::AniSignature; -concept AniNumType = std::is_same_v || std::is_same_v || std::is_same_v - -template -static ani_status SetNumberProperty( - ani_env *env, const ani_class &cls, ani_object &object, const char *name, T &value) +static ani_status SetIntProperty( + ani_env *env, const ani_class &cls, ani_object &object, const char *name, ani_int &value) { ani_method setter; ani_status ret; @@ -152,13 +149,14 @@ const static string LOCATION_SETTER = Builder::BuildSetterName("location"); static ani_status SetProperties(ani_env *env, const ani_class &cls, ani_object &statObject, FsStat *fsStat) { ani_status ret; + vector> intProperties = { { MODE_SETTER, fsStat->GetMode() }, }; for (auto iter : intProperties) { auto key = iter.first.data(); auto value = iter.second; - ret = SetNumberProperty(env, cls, statObject, key, value); + ret = SetIntProperty(env, cls, statObject, key, value); if (ret != ANI_OK) { HILOGE("Object_CallMethod_Void Fail %{private}s, err: %{private}d", key, ret); return ret; diff --git a/interfaces/kits/js/src/mod_fs/class_watcher/ani/watch_event_wrapper.cpp b/interfaces/kits/js/src/mod_fs/class_watcher/ani/watch_event_wrapper.cpp index 3bb74f40c..f2338b44f 100644 --- a/interfaces/kits/js/src/mod_fs/class_watcher/ani/watch_event_wrapper.cpp +++ b/interfaces/kits/js/src/mod_fs/class_watcher/ani/watch_event_wrapper.cpp @@ -49,11 +49,8 @@ ani_object WatchEventWrapper::Wrap(ani_env *env, const WatchEvent &evt) return nullptr; } - auto event = evt.event; - auto cookie = evt.cookie; - ani_object obj; - if (ANI_OK != env->Object_New(cls, ctor, &obj, fileName, event, cookie)) { + if (ANI_OK != env->Object_New(cls, ctor, &obj, fileName, evt.event, evt.cookie)) { HILOGE("Create %s obj failed!", classDesc); return nullptr; } diff --git a/interfaces/kits/js/src/mod_fs/properties/ani/create_randomaccessfile_ani.cpp b/interfaces/kits/js/src/mod_fs/properties/ani/create_randomaccessfile_ani.cpp index 17fe296a3..b4f1023eb 100644 --- a/interfaces/kits/js/src/mod_fs/properties/ani/create_randomaccessfile_ani.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/ani/create_randomaccessfile_ani.cpp @@ -66,7 +66,7 @@ static ani_object Wrap(ani_env *env, const FsRandomAccessFile *rafFile) } const auto &fd = fdRet.GetData().value(); - if (ANI_OK != AniHelper::SetPropertyValue(env, cls, obj, "fd", static_cast(fd))) { + if (ANI_OK != AniHelper::SetPropertyValue(env, cls, obj, "fd", fd)) { HILOGE("Set fd field value failed!"); return nullptr; } @@ -78,7 +78,7 @@ static ani_object Wrap(ani_env *env, const FsRandomAccessFile *rafFile) } const auto &fp = fpRet.GetData().value(); - if (ANI_OK != AniHelper::SetPropertyValue(env, cls, obj, "filePointer", static_cast(fp))) { + if (ANI_OK != AniHelper::SetPropertyValue(env, cls, obj, "filePointer", fd)) { HILOGE("Set fp field value failed!"); return nullptr; } diff --git a/interfaces/kits/js/src/mod_fs/properties/ani/watcher_ani.cpp b/interfaces/kits/js/src/mod_fs/properties/ani/watcher_ani.cpp index f0641c93f..241764e04 100644 --- a/interfaces/kits/js/src/mod_fs/properties/ani/watcher_ani.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/ani/watcher_ani.cpp @@ -31,7 +31,7 @@ namespace ANI { using namespace OHOS::FileManagement::ModuleFileIO; ani_object WatcherAni::CreateWatcherSync( - ani_env *env, [[maybe_unused]] ani_class clazz, ani_string path, ani_double events, ani_ref listener) + ani_env *env, [[maybe_unused]] ani_class clazz, ani_string path, ani_int events, ani_ref listener) { auto [succPath, filePath] = TypeConverter::ToUTF8String(env, path); if (!succPath) { @@ -56,7 +56,7 @@ ani_object WatcherAni::CreateWatcherSync( } FsResult ret = - WatcherCore::DoCreateWatcher(filePath, static_cast(events), move(eventListener)); + WatcherCore::DoCreateWatcher(filePath, events, move(eventListener)); if (!ret.IsSuccess()) { HILOGE("Create watcher failed"); const auto &err = ret.GetError(); diff --git a/interfaces/kits/js/src/mod_fs/properties/ani/watcher_ani.h b/interfaces/kits/js/src/mod_fs/properties/ani/watcher_ani.h index 1175c2f6f..a4d0adb4f 100644 --- a/interfaces/kits/js/src/mod_fs/properties/ani/watcher_ani.h +++ b/interfaces/kits/js/src/mod_fs/properties/ani/watcher_ani.h @@ -26,7 +26,7 @@ namespace ANI { class WatcherAni final { public: static ani_object CreateWatcherSync( - ani_env *env, [[maybe_unused]] ani_class clazz, ani_string path, ani_double events, ani_ref listener); + ani_env *env, [[maybe_unused]] ani_class clazz, ani_string path, ani_int events, ani_ref listener); }; } // namespace ANI } // namespace ModuleFileIO -- Gitee From bf87e21e34dc59793d3127d07907528effa9b516 Mon Sep 17 00:00:00 2001 From: tianp Date: Wed, 23 Jul 2025 01:16:27 +0000 Subject: [PATCH 07/10] !1 listfile&stat_fix Signed-off-by: tianp Change-Id: I51825afc85e8b7f42e8bf91a2f4c51f3e63ab7f5 --- .../js/src/mod_fs/ani/ets/@ohos.file.fs.ets | 6 ++--- .../mod_fs/class_stat/ani/stat_wrapper.cpp | 27 +------------------ .../mod_fs/properties/ani/listfile_ani.cpp | 8 +++--- 3 files changed, 8 insertions(+), 33 deletions(-) diff --git a/interfaces/kits/js/src/mod_fs/ani/ets/@ohos.file.fs.ets b/interfaces/kits/js/src/mod_fs/ani/ets/@ohos.file.fs.ets index ee01f67f9..a15f351e0 100644 --- a/interfaces/kits/js/src/mod_fs/ani/ets/@ohos.file.fs.ets +++ b/interfaces/kits/js/src/mod_fs/ani/ets/@ohos.file.fs.ets @@ -1550,7 +1550,7 @@ export class ReaderIteratorInner implements ReaderIterator { export interface Stat { ino: bigint; - mode: int; + mode: long; uid: long; gid: long; size: long; @@ -1573,7 +1573,7 @@ export interface Stat { export class StatInner implements Stat { ino: bigint = 0n; - mode: int; + mode: long; uid: long; gid: long; size: long; @@ -2050,7 +2050,7 @@ export interface RandomAccessFileOptions { export interface ListFileOptions { recursion?: boolean; - listNum?: int; + listNum?: long; filter?: Filter; } diff --git a/interfaces/kits/js/src/mod_fs/class_stat/ani/stat_wrapper.cpp b/interfaces/kits/js/src/mod_fs/class_stat/ani/stat_wrapper.cpp index 09cd422be..656e8e861 100644 --- a/interfaces/kits/js/src/mod_fs/class_stat/ani/stat_wrapper.cpp +++ b/interfaces/kits/js/src/mod_fs/class_stat/ani/stat_wrapper.cpp @@ -32,19 +32,6 @@ using namespace std; using namespace OHOS::FileManagement::ModuleFileIO; using namespace OHOS::FileManagement::ModuleFileIO::ANI::AniSignature; -static ani_status SetIntProperty( - ani_env *env, const ani_class &cls, ani_object &object, const char *name, ani_int &value) -{ - ani_method setter; - ani_status ret; - if ((ret = env->Class_FindMethod(cls, name, nullptr, &setter)) != ANI_OK) { - HILOGE("Class_FindMethod Fail %{private}s, err: %{private}d", name, ret); - return ret; - } - - return env->Object_CallMethod_Void(object, setter, value); -} - static ani_status SetNumProperty( ani_env *env, const ani_class &cls, ani_object &object, const char *name, ani_long &value) { @@ -150,20 +137,8 @@ static ani_status SetProperties(ani_env *env, const ani_class &cls, ani_object & { ani_status ret; - vector> intProperties = { - { MODE_SETTER, fsStat->GetMode() }, - }; - for (auto iter : intProperties) { - auto key = iter.first.data(); - auto value = iter.second; - ret = SetIntProperty(env, cls, statObject, key, value); - if (ret != ANI_OK) { - HILOGE("Object_CallMethod_Void Fail %{private}s, err: %{private}d", key, ret); - return ret; - } - } - vector> numProperties = { + { MODE_SETTER, fsStat->GetMode() }, { UID_SETTER, fsStat->GetUid() }, { GID_SETTER, fsStat->GetGid() }, { SIZE_SETTER, fsStat->GetSize() }, diff --git a/interfaces/kits/js/src/mod_fs/properties/ani/listfile_ani.cpp b/interfaces/kits/js/src/mod_fs/properties/ani/listfile_ani.cpp index cdea592d7..79a94260d 100644 --- a/interfaces/kits/js/src/mod_fs/properties/ani/listfile_ani.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/ani/listfile_ani.cpp @@ -51,9 +51,9 @@ tuple ParseBooleanParam(ani_env *env, ani_object obj, string tag) return { true, static_cast(boolRef_res) }; } -tuple ParseLongParam(ani_env *env, ani_object obj, string tag) +tuple ParseLongParam(ani_env *env, ani_object obj, string tag) { - int result = 0; + long result = 0; ani_boolean isUndefined; ani_ref result_ref; if (ANI_OK != env->Object_GetPropertyByName_Ref(obj, tag.c_str(), &result_ref)) { @@ -202,12 +202,12 @@ tuple> ParseArgs(ani_env *env, ani_object obj) } result.recursion = recursion; - auto [succlistNum, listNumRes] = ParseIntParam(env, obj, "listNum"); + auto [succlistNum, listNumRes] = ParseLongParam(env, obj, "listNum"); if (!succlistNum) { HILOGE("Invalid listNum"); return { false, nullopt }; } - result.listNum = (int)listNumRes; + result.listNum = listNumRes; ani_ref filterRef; if (ANI_OK != env->Object_GetPropertyByName_Ref(obj, "filter", &filterRef)) { -- Gitee From 671c339950149ccd3cd18ed50aa4d68b31655edb Mon Sep 17 00:00:00 2001 From: wcj Date: Wed, 23 Jul 2025 14:17:40 +0800 Subject: [PATCH 08/10] correct the erro: fd->fp Signed-off-by: wuchengjun Change-Id: I3aec1c623eab71c10fb8753c9968210d1f1a3eae --- .../src/mod_fs/properties/ani/create_randomaccessfile_ani.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/kits/js/src/mod_fs/properties/ani/create_randomaccessfile_ani.cpp b/interfaces/kits/js/src/mod_fs/properties/ani/create_randomaccessfile_ani.cpp index b4f1023eb..d7936360b 100644 --- a/interfaces/kits/js/src/mod_fs/properties/ani/create_randomaccessfile_ani.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/ani/create_randomaccessfile_ani.cpp @@ -78,7 +78,7 @@ static ani_object Wrap(ani_env *env, const FsRandomAccessFile *rafFile) } const auto &fp = fpRet.GetData().value(); - if (ANI_OK != AniHelper::SetPropertyValue(env, cls, obj, "filePointer", fd)) { + if (ANI_OK != AniHelper::SetPropertyValue(env, cls, obj, "filePointer", fp)) { HILOGE("Set fp field value failed!"); return nullptr; } -- Gitee From 8599ff426f259d039d9057749155e07aa946603e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E9=91=AB?= Date: Wed, 23 Jul 2025 15:07:50 +0800 Subject: [PATCH 09/10] =?UTF-8?q?stream=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 周鑫 Change-Id: Ibf1359bb7fca94874f68f4df5f29c808a30a46b2 --- .../js/src/mod_fs/ani/ets/@ohos.file.fs.ets | 22 ++++++++++++------- .../src/mod_hash/ani/ets/@ohos.file.hash.ets | 12 +++++----- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/interfaces/kits/js/src/mod_fs/ani/ets/@ohos.file.fs.ets b/interfaces/kits/js/src/mod_fs/ani/ets/@ohos.file.fs.ets index a15f351e0..b0495cc33 100644 --- a/interfaces/kits/js/src/mod_fs/ani/ets/@ohos.file.fs.ets +++ b/interfaces/kits/js/src/mod_fs/ani/ets/@ohos.file.fs.ets @@ -1804,11 +1804,11 @@ export class ReadStream extends stream.Readable { this.stream?.close(); } - doInitialize(callback: () => void): void { - callback(); + doInitialize(callback: Function): void { + callback.unsafeCall(); } - doRead(size: long): void { + doRead(size: int): void { let readSize = size; let end = this.end if (end !== undefined) { @@ -1817,7 +1817,7 @@ export class ReadStream extends stream.Readable { return; } if (this.offset + readSize > end) { - readSize = end - this.offset; + readSize = (end - this.offset).toInt(); } } let buffer = new ArrayBuffer(readSize); @@ -1878,16 +1878,22 @@ export class WriteStream extends stream.Writable { this.stream?.closeSync(); } - doInitialize(callback: () => void): void { - callback(); + doInitialize(callback: Function): void { + callback.unsafeCall(); } - doWrite(chunk: string | ArrayBuffer, encoding: string, callback: () => void): void { + doWrite(chunk: string | Uint8Array, encoding: string, callback: Function): void { + let buf: string | ArrayBuffer; + if (chunk instanceof Uint8Array) { + buf = chunk.buffer; + } else { + buf = chunk; + } this.stream?.write(chunk, { offset: this.offset }) .then((writeIn: long) => { this.offset += writeIn; this.bytesWritten += writeIn; - callback(); + callback.unsafeCall(); }) .finally(() => { this.stream?.flush(); diff --git a/interfaces/kits/js/src/mod_hash/ani/ets/@ohos.file.hash.ets b/interfaces/kits/js/src/mod_hash/ani/ets/@ohos.file.hash.ets index c9b4d5840..ce7030387 100644 --- a/interfaces/kits/js/src/mod_hash/ani/ets/@ohos.file.hash.ets +++ b/interfaces/kits/js/src/mod_hash/ani/ets/@ohos.file.hash.ets @@ -62,7 +62,7 @@ export default namespace hash { this.hs.update(data); } - doTransform(chunk: string, encoding: string, callback: () => void): void { + doTransform(chunk: string, encoding: string, callback: Function): void { let charCodes: number[] = []; for (let i = 0; i < chunk.length; i++) { charCodes = [...charCodes, chunk.charCodeAt(i)]; @@ -70,15 +70,15 @@ export default namespace hash { const buf = new Uint8Array(charCodes).buffer; this.hs.update((buf as ArrayBuffer)); this.push(chunk); - callback(); + callback.unsafeCall(); } - doWrite(chunk: string | Uint8Array, encoding: string, callback: () => void): void { - callback(); + doWrite(chunk: string | Uint8Array, encoding: string, callback: Function): void { + callback.unsafeCall(); } - doFlush(callback: () => void): void { - callback(); + doFlush(callback: Function): void { + callback.unsafeCall(); } } } -- Gitee From 62b337a039e882e01008447aa7b774c896bae444 Mon Sep 17 00:00:00 2001 From: wcj Date: Thu, 24 Jul 2025 09:30:50 +0800 Subject: [PATCH 10/10] doWrite fix Signed-off-by: wuchengjun Change-Id: I1bc179c27639a0b0575da4d648cacfdd83719c0f --- interfaces/kits/js/src/mod_fs/ani/ets/@ohos.file.fs.ets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/kits/js/src/mod_fs/ani/ets/@ohos.file.fs.ets b/interfaces/kits/js/src/mod_fs/ani/ets/@ohos.file.fs.ets index b0495cc33..295644fd2 100644 --- a/interfaces/kits/js/src/mod_fs/ani/ets/@ohos.file.fs.ets +++ b/interfaces/kits/js/src/mod_fs/ani/ets/@ohos.file.fs.ets @@ -1889,7 +1889,7 @@ export class WriteStream extends stream.Writable { } else { buf = chunk; } - this.stream?.write(chunk, { offset: this.offset }) + this.stream?.write(buf, { offset: this.offset }) .then((writeIn: long) => { this.offset += writeIn; this.bytesWritten += writeIn; -- Gitee