diff --git a/interfaces/kits/js/src/mod_fs/ani/bind_function_class.cpp b/interfaces/kits/js/src/mod_fs/ani/bind_function_class.cpp index 2d7283c7d9887f878763c47d22f689e782262a7d..7bfe4e95942a852ddb83ab5c393a9bb6adb2d130 100644 --- a/interfaces/kits/js/src/mod_fs/ani/bind_function_class.cpp +++ b/interfaces/kits/js/src/mod_fs/ani/bind_function_class.cpp @@ -62,7 +62,7 @@ using namespace OHOS::FileManagement::ModuleFileIO::ANI; static ani_status BindRafFileMethods(ani_env *env) { - static const char *className = "L@ohos/file/fs/RandomAccessFileInner;"; + static const char *className = "L@ohos/file/fs/fileIo/RandomAccessFileInner;"; std::array methods = { ani_native_function { @@ -77,7 +77,7 @@ static ani_status BindRafFileMethods(ani_env *env) static ani_status BindFileMethods(ani_env *env) { - static const char *className = "L@ohos/file/fs/FileInner;"; + static const char *className = "L@ohos/file/fs/fileIo/FileInner;"; std::array methods = { ani_native_function { "getParent", nullptr, reinterpret_cast(FileAni::GetParent) }, @@ -91,7 +91,7 @@ static ani_status BindFileMethods(ani_env *env) static ani_status BindReaderIteratorMethods(ani_env *env) { - static const char *className = "L@ohos/file/fs/ReaderIteratorInner;"; + static const char *className = "L@ohos/file/fs/fileIo/ReaderIteratorInner;"; std::array methods = { ani_native_function { "next", nullptr, reinterpret_cast(ReaderIteratorAni::Next) }, @@ -102,7 +102,7 @@ static ani_status BindReaderIteratorMethods(ani_env *env) static ani_status BindStatClassMethods(ani_env *env) { - static const char *className = "L@ohos/file/fs/StatInner;"; + static const char *className = "L@ohos/file/fs/fileIo/StatInner;"; std::array methods = { ani_native_function { "isBlockDevice", ":Z", reinterpret_cast(StatAni::IsBlockDevice) }, @@ -119,7 +119,7 @@ static ani_status BindStatClassMethods(ani_env *env) static ani_status BindStreamMethods(ani_env *env) { - static const char *className = "L@ohos/file/fs/StreamInner;"; + static const char *className = "L@ohos/file/fs/fileIo/StreamInner;"; std::array methods = { ani_native_function { "closeSync", nullptr, reinterpret_cast(StreamAni::Close) }, @@ -134,7 +134,7 @@ static ani_status BindStreamMethods(ani_env *env) static ani_status BindTaskSignalClassMethods(ani_env *env) { - static const char *className = "L@ohos/file/fs/TaskSignal;"; + static const char *className = "L@ohos/file/fs/fileIo/TaskSignal;"; std::array methods = { ani_native_function { "cancel", ":V", reinterpret_cast(TaskSignalAni::Cancel) }, 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 00920e50f8a9ca9d5039bbf3c1551e1c2ad751d7..07c5c4517007e1e078e6b8cb2882dbf498d25283 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 @@ -14,7 +14,7 @@ */ import { BusinessError, AsyncCallback } from '@ohos.base'; import stream from '@ohos.util.stream'; - +namespace fileIo { function access(path: string, mode?: AccessModeType): Promise { return new Promise((resolve: (result: boolean) => void, reject: (e: BusinessError) => void) => { if (mode === undefined) { @@ -474,23 +474,13 @@ function openSync(path: string, mode?: number): File { function open(path: String, mode?: number): Promise { return new Promise((resolve: (result: File) => void, reject: (e: BusinessError) => void) => { - if (mode === undefined) { - let promise = taskpool.execute(FileIoImpl.openSync, path); - promise.then((ret: NullishType): void => { - let file = ret as File; - resolve(file); - }).catch((e: BusinessError): void => { - reject(e); - }); - } else { - let promise = taskpool.execute(FileIoImpl.openSync, path, mode); - promise.then((ret: NullishType): void => { - let file = ret as File; - resolve(file); - }).catch((e: BusinessError): void => { - reject(e); - }); - } + let promise = taskpool.execute(FileIoImpl.openSync, path, mode); + promise.then((ret: NullishType): void => { + let file = ret as File; + resolve(file); + }).catch((e: BusinessError): void => { + reject(e); + }); }); } @@ -934,6 +924,19 @@ function fsync(fd: number): Promise { }); } +function fsync(fd: number, callback: AsyncCallback): void { + let promise = taskpool.execute((fd: number): undefined => { + return FileIoImpl.fsyncSync(fd); + }, fd); + promise.then((ret: NullishType): void => { + let e = new BusinessError(); + e.code = 0; + callback(e, undefined); + }).catch((e: BusinessError): void => { + callback(e, undefined); + }); +} + function symlinkSync(target: string, srcPath: string): void { return FileIoImpl.symlinkSync(target, srcPath); } @@ -967,6 +970,20 @@ function rename(oldPath: string, newPath: string): Promise { }); }); } + +function rename(oldPath: string, newPath: string, callback: AsyncCallback): void { + let promise = taskpool.execute((oldPath: string, newPath: string): undefined => { + return FileIoImpl.renameSync(oldPath, newPath); + }, oldPath, newPath); + promise.then((ret: NullishType): void => { + let e = new BusinessError(); + e.code = 0; + callback(e, undefined); + }).catch((e: BusinessError): void => { + callback(e, undefined); + }); +} + function createRandomAccessFileSync(file: string | File, mode?: number, options?: RandomAccessFileOptions): RandomAccessFile { return FileIoImpl.createRandomAccessFileSync(file, mode, options); @@ -1266,36 +1283,6 @@ function lseek(fd: number, offset: number, whence?: WhenceType): number { return FileIoImpl.lseekSync(fd, offset, whence); } -export interface ConflictFiles { - srcFile: string; - destFile: string; -} - -class ConflictFilesInner implements ConflictFiles { - srcFile: string = ""; - destFile: string = ""; - - constructor(src: string, dest: string) { - this.srcFile = src; - this.destFile = dest; - } -} - -export interface Filter { - suffix?: Array; - displayName?: Array; - mimeType?: Array; - fileSizeOver?: number; - lastModifiedAfter?: number; - excludeMedia?: boolean; -} - -export interface ListFileOptions { - recursion?: boolean; - listNum?: number; - filter?: Filter; -} - export interface ReadOptions { offset?: number; length?: number; @@ -1305,20 +1292,6 @@ export interface ReadTextOptions extends ReadOptions { encoding?: string; } -export interface Options { - encoding?: string; -} - -export interface WriteOptions extends Options { - offset?: number; - length?: number; -} - -export interface RandomAccessFileOptions { - start?: number; - end?: number; -} - export interface Progress { processedSize: number; totalSize: number; @@ -1328,7 +1301,7 @@ export interface DfsListeners { onStatus(networkId: string, status: number): void; } -class ProgressInner implements Progress { +export class ProgressInner implements Progress { processedSize: number; totalSize: number; @@ -1363,14 +1336,14 @@ export interface CopyOptions { copySignal?: TaskSignal; } -enum AccessModeType { +export enum AccessModeType { EXIST = 0, WRITE = 2, READ = 4, READ_WRITE = 6, } -enum AccessFlagType { +export enum AccessFlagType { LOCAL = 0, } @@ -1390,7 +1363,7 @@ export interface RandomAccessFile { readSync(buffer: ArrayBuffer, options?: ReadOptions): number; } -class RandomAccessFileInner implements RandomAccessFile { +export class RandomAccessFileInner implements RandomAccessFile { fd: number = -1; filePointer: number = -1; @@ -1533,7 +1506,7 @@ export interface File { unlock(): void; } -class FileInner implements File { +export class FileInner implements File { fd: number = -1; path: String = ""; name: String = ""; @@ -1604,17 +1577,13 @@ class FileInner implements File { } -enum LocationType { +export enum LocationType { LOCAL = 1, CLOUD = 2 } -export interface ReaderIteratorResult { - done: boolean; - value: string; -} -class ReaderIteratorResultInner implements ReaderIteratorResult { +export class ReaderIteratorResultInner implements ReaderIteratorResult { private nativePtr: long = 0; constructor(ptr: long) { @@ -1631,7 +1600,7 @@ export interface ReaderIterator { next(): ReaderIteratorResult; } -class ReaderIteratorInner implements ReaderIterator { +export class ReaderIteratorInner implements ReaderIterator { private nativePtr: long = 0; constructor(ptr: long) { @@ -1666,7 +1635,7 @@ export interface Stat { isSymbolicLink(): boolean; } -class StatInner implements Stat { +export class StatInner implements Stat { ino: bigint = 0n; mode: number; uid: number; @@ -1715,7 +1684,7 @@ export interface Stream { seek(offset: number, whence?: number): number; } -class StreamInner implements Stream { +export class StreamInner implements Stream { private nativePtr: long = 0; constructor(ptr: long) { @@ -1883,16 +1852,6 @@ enum OpenMode { SYNC = 0o4010000, } -export interface ReadStreamOptions { - start?: number; - end?: number; -} - -export interface WriteStreamOptions { - mode?: number; - start?: number; -} - export class ReadStream extends stream.Readable { private pathInner: string; private bytesReadInner: number; @@ -2052,23 +2011,72 @@ export class WriteStream extends stream.Writable { return modeStr; } } -enum WhenceType { +export enum WhenceType { SEEK_SET = 0, SEEK_CUR = 1, SEEK_END = 2 } +} -class FileIoImpl { +export interface Options { + encoding?: string; +} + +export interface WriteOptions extends Options { + offset?: number; + length?: number; +} + +export interface RandomAccessFileOptions { + start?: number; + end?: number; +} + +export interface ListFileOptions { + recursion?: boolean; + listNum?: number; + filter?: Filter; +} + +export interface WriteStreamOptions { + mode?: number; + start?: number; +} + +export interface ReadStreamOptions { + start?: number; + end?: number; +} + +export interface ReaderIteratorResult { + done: boolean; + 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; + + +export class FileIoImpl { static { loadLibrary("ani_fs_class"); } - static native doAccessSync(path: string, mode?: AccessModeType, flag?: AccessFlagType): boolean; + static native doAccessSync(path: string, mode?: fileIo.AccessModeType, flag?: fileIo.AccessFlagType): boolean; - static native closeSync(file: number | File): void; + static native closeSync(file: number | fileIo.File): void; - static native copySync(srcUri: string, destUri: string, options?: CopyOptions): void; + static native copySync(srcUri: string, destUri: string, options?: fileIo.CopyOptions): void; static native connectDfs(networkId: string, listeners: DfsListeners): void; @@ -2082,17 +2090,17 @@ class FileIoImpl { static native getxattrSync(path: string, key: string): string; - static native createStreamSync(path: string, mode: string): Stream; - - static native fdopenStreamSync(fd: number, mode: string): Stream; - - static native dup(fd: number): File; + static native createStreamSync(path: string, mode: string): fileIo.Stream; + + static native fdopenStreamSync(fd: number, mode: string): fileIo.Stream; + + static native dup(fd: number): fileIo.File; static native listFileSync(path: string, options?: ListFileOptions): string[]; - static native lstatSync(path: string): Stat; - - static native lseekSync(fd: number, offset: number, whence?: WhenceType): number; + static native lstatSync(path: string): fileIo.Stat; + + static native lseekSync(fd: number, offset: number, whence?: fileIo.WhenceType): number; static native mkdirSync(path: string): void; @@ -2104,19 +2112,19 @@ class FileIoImpl { static native moveFileSync(src: String, dest: String, mode?: number): void; - static native openSync(path: String, mode?: number): File; + static native openSync(path: String, mode?: number): fileIo.File; - static native readlinesSync(filePath: string, options?: Options): ReaderIterator; - - static native readSync(fd: number, buffer: ArrayBuffer, options?: ReadOptions): number; + static native readlinesSync(filePath: string, options?: Options): fileIo.ReaderIterator; + + static native readSync(fd: number, buffer: ArrayBuffer, options?: fileIo.ReadOptions): number; - static native readTextSync(filePath: string, options?: ReadTextOptions): string; + static native readTextSync(filePath: string, options?: fileIo.ReadTextOptions): string; static native rmdirSync(path: string): void; static native setxattrSync(path: string, key: string, value: string): void; - static native statSync(file: string | number): Stat; + static native statSync(file: string | number): fileIo.Stat; static native truncateSync(file: string | number, len?: number): void; @@ -2128,8 +2136,8 @@ class FileIoImpl { static native renameSync(oldPath: string, newPath: string): void; - static native createRandomAccessFileSync(file: string | File, mode?: number, - options?: RandomAccessFileOptions): RandomAccessFile; + static native createRandomAccessFileSync(file: string | fileIo.File, mode?: number, + options?: RandomAccessFileOptions): fileIo.RandomAccessFile; static native symlinkSync(target: string, srcPath: string): void; diff --git a/interfaces/kits/js/src/mod_fs/properties/ani/copy_ani.cpp b/interfaces/kits/js/src/mod_fs/properties/ani/copy_ani.cpp index 1f9b713c328cf0f9e8fef23f1eef5d2f60fc0116..287f4a832455d4d966e826746f558130fb0d22da 100644 --- a/interfaces/kits/js/src/mod_fs/properties/ani/copy_ani.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/ani/copy_ani.cpp @@ -47,7 +47,8 @@ static void SetProgressListenerCb(ani_env *env, ani_ref &callback, CopyOptions & } if (progressSize > MAX_VALUE || totalSize > MAX_VALUE) { - HILOGE("progressSize or totalSize exceed MAX_VALUE: %{private}llu %{private}llu", progressSize, totalSize); + HILOGE("progressSize or totalSize exceed MAX_VALUE: %{private}" PRIu64 " %{private}" PRIu64, progressSize, + totalSize); } if ((ret = env->FindClass(className, &cls)) != ANI_OK) {