From 7e5ff70c542dc926e9adbc0cb2aafa7540b7b333 Mon Sep 17 00:00:00 2001 From: 18721213663 Date: Mon, 16 Jan 2023 17:57:36 +0800 Subject: [PATCH] fs_add_movefile&filelock&listfile Signed-off-by: 18721213663 --- api/@ohos.file.fs.d.ts | 288 ++++++++++++++++++++++++++++++++++++++++- api/@ohos.fileio.d.ts | 34 ++++- 2 files changed, 318 insertions(+), 4 deletions(-) diff --git a/api/@ohos.file.fs.d.ts b/api/@ohos.file.fs.d.ts index ab7cf04075..b548623089 100644 --- a/api/@ohos.file.fs.d.ts +++ b/api/@ohos.file.fs.d.ts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -36,12 +36,16 @@ declare namespace fileIo { export { fdopenStreamSync }; export { fsync }; export { fsyncSync }; + export { listFile }; + export { listFileSync }; export { lstat }; export { lstatSync }; export { mkdir }; export { mkdirSync }; export { mkdtemp }; export { mkdtempSync }; + export { moveFile } + export { moveFileSync } export { open }; export { openSync }; export { read }; @@ -66,7 +70,7 @@ declare namespace fileIo { export { OpenMode }; export { Stat }; export { Stream }; - + /** * Mode Indicates the open flags. * @since 9 @@ -451,6 +455,76 @@ declare function fsync(fd: number, callback: AsyncCallback): void; */ declare function fsyncSync(fd: number): void; +/** + * List file. + * + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 9 + * @param {string} path - path. + * @param {Object} [options] - options. + * @param {boolean} [options.recursion = false] - whether to list recursively + * @param {number} [options.listNum = 0] - the number of listing file. + * @param {Filter} [options.filter] - file filter. + * @returns {Promise} return Promise + * @throws { BusinessError } 13900002 - No such file or directory + * @throws { BusinessError } 13900008 - Bad file descriptor + * @throws { BusinessError } 13900011 - Out of memory + * @throws { BusinessError } 13900018 - Not a directory + * @throws { BusinessError } 13900042 - Unknown error + */ +declare function listFile(path: string, options?: { + recursion?: boolean; + listNum?: number; + filter?: Filter; +}): Promise; + +/** + * List file. + * + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 9 + * @param {string} path - path. + * @param {Object} [options] - options. + * @param {boolean} [options.recursion = false] - whether to list recursively + * @param {number} [options.listNum = 0] - the number of listing file. + * @param {Filter} [options.filter] - file filter. + * @param {AsyncCallback} callback - callback. + * @throws { BusinessError } 13900002 - No such file or directory + * @throws { BusinessError } 13900008 - Bad file descriptor + * @throws { BusinessError } 13900011 - Out of memory + * @throws { BusinessError } 13900018 - Not a directory + * @throws { BusinessError } 13900042 - Unknown error + */ +declare function listFile(path: string, callback: AsyncCallback): void; +declare function listFile(path: string, options: { + recursion?: boolean; + listNum?: number; + filter?: Filter; +}, callback: AsyncCallback): void; + +/** + * List file with sync interface. + * + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 9 + * @param {string} path - path. + * @param {Object} [options] - options. + * @param {boolean} [options.recursion = false] - whether to list recursively + * @param {number} [options.listNum = 0] - the number of listing file. + * @param {Filter} [options.filter] - file filter. + * @returns {string[]} array of file name + * @throws { BusinessError } 13900002 - No such file or directory + * @throws { BusinessError } 13900008 - Bad file descriptor + * @throws { BusinessError } 13900011 - Out of memory + * @throws { BusinessError } 13900018 - Not a directory + * @throws { BusinessError } 13900042 - Unknown error + */ +declare function listFileSync(path: string, options?: { + recursion?: boolean; + listNum?: number; + filter?: Filter; +}): string[]; + /** * Stat link file. * @@ -597,6 +671,100 @@ declare function mkdtemp(prefix: string, callback: AsyncCallback): void; */ declare function mkdtempSync(prefix: string): string; +/** + * Move file. + * + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 9 + * @param {string} src - source file path. + * @param {string} dest - destination file path. + * @param {number} [mode = 0] - move mode when duplicate file name exists. + * @returns {Promise} return Promise + * @throws { BusinessError } 13900001 - Operation not permitted + * @throws { BusinessError } 13900002 - No such file or directory + * @throws { BusinessError } 13900008 - Bad file descriptor + * @throws { BusinessError } 13900011 - Out of memory + * @throws { BusinessError } 13900012 - Permission denied + * @throws { BusinessError } 13900013 - Bad address + * @throws { BusinessError } 13900014 - Device or resource busy + * @throws { BusinessError } 13900015 - File exists + * @throws { BusinessError } 13900015 - Cross-device link + * @throws { BusinessError } 13900018 - Not a directory + * @throws { BusinessError } 13900019 - Is a directory + * @throws { BusinessError } 13900020 - Invalid argument + * @throws { BusinessError } 13900025 - No space left on device + * @throws { BusinessError } 13900027 - Read-only file system + * @throws { BusinessError } 13900028 - Too many links + * @throws { BusinessError } 13900032 - Directory not empty + * @throws { BusinessError } 13900033 - Too many symbolic links encountered + * @throws { BusinessError } 13900041 - Quota exceeded + * @throws { BusinessError } 13900042 - Unknown error + */ +declare function moveFile(src: string, dest: string, mode?: number): Promise; + +/** + * Move file. + * + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 9 + * @param {string} src - source file path. + * @param {string} dest - destination file path. + * @param {number} [mode = 0] - move mode when duplicate file name exists. + * @param {AsyncCallback} callback - callback. + * @throws { BusinessError } 13900001 - Operation not permitted + * @throws { BusinessError } 13900002 - No such file or directory + * @throws { BusinessError } 13900008 - Bad file descriptor + * @throws { BusinessError } 13900011 - Out of memory + * @throws { BusinessError } 13900012 - Permission denied + * @throws { BusinessError } 13900013 - Bad address + * @throws { BusinessError } 13900014 - Device or resource busy + * @throws { BusinessError } 13900015 - File exists + * @throws { BusinessError } 13900015 - Cross-device link + * @throws { BusinessError } 13900018 - Not a directory + * @throws { BusinessError } 13900019 - Is a directory + * @throws { BusinessError } 13900020 - Invalid argument + * @throws { BusinessError } 13900025 - No space left on device + * @throws { BusinessError } 13900027 - Read-only file system + * @throws { BusinessError } 13900028 - Too many links + * @throws { BusinessError } 13900032 - Directory not empty + * @throws { BusinessError } 13900033 - Too many symbolic links encountered + * @throws { BusinessError } 13900041 - Quota exceeded + * @throws { BusinessError } 13900042 - Unknown error + */ +declare function moveFile(src: string, dest: string, callback: AsyncCallback): void; +declare function moveFile(src: string, dest: string, mode: number, callback: AsyncCallback): void; + +/** + * Move file with sync interface. + * + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 9 + * @param {string} src - source file path. + * @param {string} dest - destination file path. + * @param {number} [mode = 0] - move mode when duplicate file name exists. + * @returns {void} move success + * @throws { BusinessError } 13900001 - Operation not permitted + * @throws { BusinessError } 13900002 - No such file or directory + * @throws { BusinessError } 13900008 - Bad file descriptor + * @throws { BusinessError } 13900011 - Out of memory + * @throws { BusinessError } 13900012 - Permission denied + * @throws { BusinessError } 13900013 - Bad address + * @throws { BusinessError } 13900014 - Device or resource busy + * @throws { BusinessError } 13900015 - File exists + * @throws { BusinessError } 13900015 - Cross-device link + * @throws { BusinessError } 13900018 - Not a directory + * @throws { BusinessError } 13900019 - Is a directory + * @throws { BusinessError } 13900020 - Invalid argument + * @throws { BusinessError } 13900025 - No space left on device + * @throws { BusinessError } 13900027 - Read-only file system + * @throws { BusinessError } 13900028 - Too many links + * @throws { BusinessError } 13900032 - Directory not empty + * @throws { BusinessError } 13900033 - Too many symbolic links encountered + * @throws { BusinessError } 13900041 - Quota exceeded + * @throws { BusinessError } 13900042 - Unknown error + */ +declare function moveFileSync(src: string, dest: string, mode?: number): void; + /** * Open file. * @@ -1201,6 +1369,66 @@ declare interface File { * @readonly */ readonly fd: number; + + /** + * Lock file with blocking method. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 9 + * @param {boolean} exclusive - whether lock is exclusive. + * @returns {Promise} return Promise + * @throws { BusinessError } 13900004 - Interrupted system call + * @throws { BusinessError } 13900008 - Bad file descriptor + * @throws { BusinessError } 13900020 - Invalid argument + * @throws { BusinessError } 13900034 - Operation would block + * @throws { BusinessError } 13900042 - Unknown error + * @throws { BusinessError } 13900043 - No record locks available + */ + lock(exclusive?: boolean): Promise; + + /** + * Lock file with blocking method. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 9 + * @param {boolean} exclusive - whether lock is exclusive. + * @param {AsyncCallback} callback - callback. + * @throws { BusinessError } 13900004 - Interrupted system call + * @throws { BusinessError } 13900008 - Bad file descriptor + * @throws { BusinessError } 13900020 - Invalid argument + * @throws { BusinessError } 13900034 - Operation would block + * @throws { BusinessError } 13900042 - Unknown error + * @throws { BusinessError } 13900043 - No record locks available + */ + lock(callback: AsyncCallback): void; + lock(exclusive: boolean, callback: AsyncCallback): void; + + /** + * Try to lock file with returning results immediately. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 9 + * @param {boolean} exclusive - whether lock is exclusive. + * @returns {void} tryLock success + * @throws { BusinessError } 13900004 - Interrupted system call + * @throws { BusinessError } 13900008 - Bad file descriptor + * @throws { BusinessError } 13900020 - Invalid argument + * @throws { BusinessError } 13900034 - Operation would block + * @throws { BusinessError } 13900042 - Unknown error + * @throws { BusinessError } 13900043 - No record locks available + */ + tryLock(exclusive?: boolean): void; + + /** + * Unlock file. + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 9 + * @returns {void} unlock success + * @throws { BusinessError } 13900004 - Interrupted system call + * @throws { BusinessError } 13900008 - Bad file descriptor + * @throws { BusinessError } 13900020 - Invalid argument + * @throws { BusinessError } 13900034 - Operation would block + * @throws { BusinessError } 13900042 - Unknown error + * @throws { BusinessError } 13900043 - No record locks available + */ + unlock(): void; } /** * Stat object. @@ -1548,3 +1776,59 @@ declare interface Stream { length?: number; }): number; } + +/** + * File filter type + * @syscap SystemCapability.FileManagement.File.FileIO + * @since 9 + */ +export type Filter = { + /** + * @type {Array} + * @syscap SystemCapability.FileManagement.File.FileIO + * @systemapi + * @since 9 + * @readonly + */ + suffix?: Array; + /** + * @type {Array} + * @syscap SystemCapability.FileManagement.File.FileIO + * @systemapi + * @since 9 + * @readonly + */ + displayName?: Array; + /** + * @type {Array} + * @syscap SystemCapability.FileManagement.File.FileIO + * @systemapi + * @since 9 + * @readonly + */ + mimeType?: Array; + /** + * @type {number} + * @syscap SystemCapability.FileManagement.File.FileIO + * @systemapi + * @since 9 + * @readonly + */ + fileSizeOver?: number; + /** + * @type {number} + * @syscap SystemCapability.FileManagement.File.FileIO + * @systemapi + * @since 9 + * @readonly + */ + lastModifiedAfter?: number; + /** + * @type {boolean} + * @syscap SystemCapability.FileManagement.File.FileIO + * @systemapi + * @since 9 + * @readonly + */ + excludeMedia?: boolean; +} diff --git a/api/@ohos.fileio.d.ts b/api/@ohos.fileio.d.ts index be7a93c235..fb3f37b0af 100644 --- a/api/@ohos.fileio.d.ts +++ b/api/@ohos.fileio.d.ts @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -672,6 +672,8 @@ declare function openSync(path: string, flags?: number, mode?: number): number; * * @syscap SystemCapability.FileManagement.File.FileIO * @since 6 + * @deprecated since 9 + * @useinstead ohos.file.fs.listFile * @permission N/A * @function opendir * @param {string} path - directory name. @@ -683,7 +685,9 @@ declare function opendir(path: string): Promise; declare function opendir(path: string, callback: AsyncCallback): void; /** * opendirSync. - * + * @since 6 + * @deprecated since 9 + * @useinstead ohos.file.fs.listFile * @param {string} path - directory name. * @returns {Dir} opendir Dir Object * @throws {TypedError | Error} opendir fail @@ -1056,6 +1060,8 @@ declare interface Dir { * * @syscap SystemCapability.FileManagement.File.FileIO * @since 6 + * @deprecated since 9 + * @useinstead ohos.file.fs.listFile * @permission N/A * @function read * @param {AsyncCallback} [callback] - callback. @@ -1068,6 +1074,8 @@ declare interface Dir { * readSync. * @syscap SystemCapability.FileManagement.File.FileIO * @since 6 + * @deprecated since 9 + * @useinstead ohos.file.fs.listFile * @permission N/A * @function readSync * @returns {Dirent} Dirent Object @@ -1078,6 +1086,8 @@ declare interface Dir { * close. * @syscap SystemCapability.FileManagement.File.FileIO * @since 7 + * @deprecated since 9 + * @useinstead ohos.file.fs.listFile * @permission N/A * @function close * @param {AsyncCallback} [callback] - callback. @@ -1090,6 +1100,8 @@ declare interface Dir { * closeSync. * @syscap SystemCapability.FileManagement.File.FileIO * @since 6 + * @deprecated since 9 + * @useinstead ohos.file.fs.listFile * @permission N/A * @function closeSync * @returns {void} close success @@ -1102,6 +1114,8 @@ declare interface Dir { * Dirent * @syscap SystemCapability.FileManagement.File.FileIO * @since 6 + * @deprecated since 9 + * @useinstead ohos.file.fs.listFile * @permission N/A */ declare interface Dirent { @@ -1110,6 +1124,8 @@ declare interface Dirent { * @readonly * @syscap SystemCapability.FileManagement.File.FileIO * @since 6 + * @deprecated since 9 + * @useinstead ohos.file.fs.listFile * @permission N/A */ readonly name: string; @@ -1117,6 +1133,8 @@ declare interface Dirent { * isBlockDevice. * @syscap SystemCapability.FileManagement.File.FileIO * @since 6 + * @deprecated since 9 + * @useinstead ohos.file.fs.listFile * @permission N/A * @returns {boolean} is or not */ @@ -1125,6 +1143,8 @@ declare interface Dirent { * isCharacterDevice. * @syscap SystemCapability.FileManagement.File.FileIO * @since 6 + * @deprecated since 9 + * @useinstead ohos.file.fs.listFile * @permission N/A * @returns {boolean} is or not */ @@ -1133,6 +1153,8 @@ declare interface Dirent { * isDirectory. * @syscap SystemCapability.FileManagement.File.FileIO * @since 6 + * @deprecated since 9 + * @useinstead ohos.file.fs.listFile * @permission N/A * @returns {boolean} is or not */ @@ -1141,6 +1163,8 @@ declare interface Dirent { * isFIFO. * @syscap SystemCapability.FileManagement.File.FileIO * @since 6 + * @deprecated since 9 + * @useinstead ohos.file.fs.listFile * @permission N/A * @returns {boolean} is or not */ @@ -1149,6 +1173,8 @@ declare interface Dirent { * isFile. * @syscap SystemCapability.FileManagement.File.FileIO * @since 6 + * @deprecated since 9 + * @useinstead ohos.file.fs.listFile * @permission N/A * @returns {boolean} is or not */ @@ -1157,6 +1183,8 @@ declare interface Dirent { * isSocket. * @syscap SystemCapability.FileManagement.File.FileIO * @since 6 + * @deprecated since 9 + * @useinstead ohos.file.fs.listFile * @permission N/A * @returns {boolean} is or not */ @@ -1165,6 +1193,8 @@ declare interface Dirent { * isSymbolicLink. * @syscap SystemCapability.FileManagement.File.FileIO * @since 6 + * @deprecated since 9 + * @useinstead ohos.file.fs.listFile * @permission N/A * @returns {boolean} is or not */ -- Gitee