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 c2ec3ebc5f90649b8685e2cbed1d929284b9ed30..1dfa89cc2a43d1b297c86371377a7699fd390871 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 @@ -207,7 +207,7 @@ class StatInner implements Stat { } type FdOrFile = int | File; -type PathOrFd = string | int; +type PathOrFd = string | number; type BufferType = string | ArrayBuffer; class fileIo { @@ -724,38 +724,29 @@ class fileIo { }); } - static native truncateSync(file: PathOrFd, len?: long): void; + static native truncateSync(file: PathOrFd, len?: number): void; - static native unlinkSync(path: string): int; + static native unlinkSync(path: string): void; - static unlink(path: string): Promise { - return new Promise((resolve: (result: int) => void, reject: (e: BusinessError) => void) => { - let promise = taskpool.execute(fileIo.unlinkSync, path); + static unlink(path: string): Promise { + return new Promise((resolve: (result: undefined) => void, + reject: (e: BusinessError) => void): void => { + let promise = taskpool.execute((path: string): void => fileIo.unlinkSync(path), path); promise.then((ret: NullishType) => { - let result = ret as int - if (ret === null || ret === undefined) { - let err = new BusinessError(-1, ""); - - reject(err); - } else { - resolve(result); - } + resolve(undefined); + }).catch((e: BusinessError): void => { + reject(e); }); }); } - static unlink(path: string, callback: AsyncCallback): void { - let promise = taskpool.execute(fileIo.unlinkSync, path); + static unlink(path: string, callback: AsyncCallback): void { + let promise = taskpool.execute((path: string): void => fileIo.unlinkSync(path), path); promise.then((ret: NullishType) => { - let err = new BusinessError(-1, ""); - if (ret === null || ret === undefined) { - err.code = -1 - callback(err, undefined) - } else { - err.code = 0 - let r = ret as int; - callback(err, r); - } + let e = new BusinessError(0, ""); + callback(e, undefined); + }).catch((e: BusinessError): void => { + callback(e, undefined); }); } diff --git a/interfaces/kits/js/src/mod_fs/properties/ani/unlink_ani.cpp b/interfaces/kits/js/src/mod_fs/properties/ani/unlink_ani.cpp index 7c8e7a8fdabc3c179fd1a0f266c0c7473270e724..978ea3dd9938afedd72313c1b330df3cda286c3b 100644 --- a/interfaces/kits/js/src/mod_fs/properties/ani/unlink_ani.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/ani/unlink_ani.cpp @@ -24,19 +24,18 @@ namespace FileManagement { namespace ModuleFileIO { namespace ANI { -ani_int UnlinkAni::UnlinkSync(ani_env *env, [[maybe_unused]] ani_class clazz, ani_string path) +void UnlinkAni::UnlinkSync(ani_env *env, [[maybe_unused]] ani_class clazz, ani_string path) { auto [succ, pathStr] = TypeConverter::ToUTF8String(env, path); if (!succ) { HILOGE("Invalid path"); - return -1; + return; } auto ret = UnlinkCore::DoUnlink(pathStr); if (!ret.IsSuccess()) { HILOGE("Unlink failed"); - return -1; + return; } - return 0; } } // namespace ANI diff --git a/interfaces/kits/js/src/mod_fs/properties/ani/unlink_ani.h b/interfaces/kits/js/src/mod_fs/properties/ani/unlink_ani.h index 83bb1722ec333bb5699264441ed03c591ecf1202..817b258000b9f13b5dbbc8f498b00cc74e7dc1e0 100644 --- a/interfaces/kits/js/src/mod_fs/properties/ani/unlink_ani.h +++ b/interfaces/kits/js/src/mod_fs/properties/ani/unlink_ani.h @@ -25,7 +25,7 @@ namespace ANI { class UnlinkAni final { public: - static ani_int UnlinkSync(ani_env *env, [[maybe_unused]] ani_class clazz, ani_string path); + static void UnlinkSync(ani_env *env, [[maybe_unused]] ani_class clazz, ani_string path); }; } // namespace ANI