diff --git a/zh-cn/application-dev/reference/apis-core-file-kit/js-apis-file-backup-sys.md b/zh-cn/application-dev/reference/apis-core-file-kit/js-apis-file-backup-sys.md index 3fd82c97aacbf3e081c31b055ef06d0855c02edb..d3969e6ec285d42b1980177fee7a3cdf23443b5c 100644 --- a/zh-cn/application-dev/reference/apis-core-file-kit/js-apis-file-backup-sys.md +++ b/zh-cn/application-dev/reference/apis-core-file-kit/js-apis-file-backup-sys.md @@ -1594,6 +1594,101 @@ cancel(bundleName: string): number this.sessionBackup = new backup.SessionBackup(generalCallbacks); // 创建备份流程 ``` +### cleanBundleTempDir20+ + +cleanBundleTempDir(bundleName: string): Promise<boolean> + +备份或者恢复任务结束后,提供给工具用于清理当前应用的临时目录(./backup目录下的backup和restore目录)的数据。 + +**需要权限**:ohos.permission.BACKUP + +**系统能力**:SystemCapability.FileManagement.StorageService.Backup + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| --------------- | -------- | ---- | -------------------------- | +| bundleName | string | 是 | 需要清理临时目录数据的应用名称。 | + +**返回值:** + +| 类型 | 说明 | +| ------------------- | ----------------------- | +| Promise<boolean> | 返回清理结果。
true:清理成功;
false:清理失败;
| + +**错误码:** + +以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。 + +| 错误码ID | 错误信息 | +| -------- | ---------------------------------------------------------------------------------------------- | +| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | +| 202 | Permission verification failed, application which is not a system application uses system API. | +| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verifcation faild| + +**示例:** + + ```ts + import fs from '@ohos.file.fs'; + import { BusinessError } from '@ohos.base'; + import backup from '@ohos.file.backup'; + + let generalCallbacks: backup.GeneralCallbacks = { + onFileReady: (err: BusinessError, file: backup.File) => { + if (err) { + console.error('onFileReady failed with err: ' + JSON.stringify(err)); + return; + } + console.info('onFileReady success'); + fs.closeSync(file.fd); + }, + onBundleBegin: (err: BusinessError, bundleName: string) => { + if (err) { + console.error('onBundleBegin failed with err: ' + JSON.stringify(err)); + return; + } + console.info('onBundleBegin success'); + }, + onBundleEnd: (err: BusinessError, bundleName: string) => { + if (err) { + console.error('onBundleEnd failed with err: ' + JSON.stringify(err)); + return; + } + this.cleanBundleTempDir(bundleName); + }, + onAllBundlesEnd: (err: BusinessError) => { + if (err) { + console.error('onAllBundlesEnd failed with err: ' + JSON.stringify(err)); + return; + } + console.info('onAllBundlesEnd success'); + }, + onBackupServiceDied: () => { + console.info('service died'); + }, + onResultReport: (bundleName: string, result: string) => { + console.info('onResultReport success, bundleName: ' + bundleName +'result: ' + result); + }, + onProcess: (bundleName: string, process: string) => { + console.info('onProcess success, bundleName: ' + bundleName +'process: ' + process); + } + }; + let sessionBackup = new backup.SessionBackup(generalCallbacks); // 创建备份流程 + async cleanBundleTempDir(bundleName: string) { + try { + let res = await sessionBackup.cleanBundleTempDir(bundleName); + if (res) { + console.info('cleanBundleTempDir success'); + } else { + console.info('cleanBundleTempDir fail'); + } + } catch (error) { + let err: BusinessError = error as BusinessError; + console.error('cleanBundleTempDir failed with err: ' + JSON.stringify(err)); + } + } + ``` + ## SessionRestore 恢复流程对象,用来支撑应用恢复的流程。在使用前,需要先创建SessionRestore实例。 @@ -2679,6 +2774,100 @@ cancel(bundleName: string): number }; this.sessionRestore = new backup.SessionRestore(generalCallbacks); // 创建恢复流程 ``` +### cleanBundleTempDir20+ + +cleanBundleTempDir(bundleName: string): Promise<boolean> + +备份或者恢复任务结束后,提供给工具用于清理当前应用的临时目录(./backup目录下的backup和restore目录)的数据。 + +**需要权限**:ohos.permission.BACKUP + +**系统能力**:SystemCapability.FileManagement.StorageService.Backup + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| --------------- | -------- | ---- | -------------------------- | +| bundleName | string | 是 | 需要清理临时目录数据的应用名称。 | + +**返回值:** + +| 类型 | 说明 | +| ------------------- | ----------------------- | +| Promise<boolean> | 返回清理结果。
true:清理成功;
false:清理失败;
| + +**错误码:** + +以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。 + +| 错误码ID | 错误信息 | +| -------- | ---------------------------------------------------------------------------------------------- | +| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | +| 202 | Permission verification failed, application which is not a system application uses system API. | +| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verifcation faild| + +**示例:** + + ```ts + import fs from '@ohos.file.fs'; + import { BusinessError } from '@ohos.base'; + import backup from '@ohos.file.backup'; + + let generalCallbacks: backup.GeneralCallbacks = { + onFileReady: (err: BusinessError, file: backup.File) => { + if (err) { + console.error('onFileReady failed with err: ' + JSON.stringify(err)); + return; + } + console.info('onFileReady success'); + fs.closeSync(file.fd); + }, + onBundleBegin: (err: BusinessError, bundleName: string) => { + if (err) { + console.error('onBundleBegin failed with err: ' + JSON.stringify(err)); + return; + } + console.info('onBundleBegin success'); + }, + onBundleEnd: (err: BusinessError, bundleName: string) => { + if (err) { + console.error('onBundleEnd failed with err: ' + JSON.stringify(err)); + return; + } + this.cleanBundleTempDir(bundleName); + }, + onAllBundlesEnd: (err: BusinessError) => { + if (err) { + console.error('onAllBundlesEnd failed with err: ' + JSON.stringify(err)); + return; + } + console.info('onAllBundlesEnd success'); + }, + onBackupServiceDied: () => { + console.info('service died'); + }, + onResultReport: (bundleName: string, result: string) => { + console.info('onResultReport success, bundleName: ' + bundleName +'result: ' + result); + }, + onProcess: (bundleName: string, process: string) => { + console.info('onProcess success, bundleName: ' + bundleName +'process: ' + process); + } + }; + let sessionRestore = new backup.SessionRestore(generalCallbacks); // 创建恢复流程 + async cleanBundleTempDir(bundleName: string) { + try { + let res = await sessionRestore.cleanBundleTempDir(bundleName); + if (res) { + console.info('cleanBundleTempDir success'); + } else { + console.info('cleanBundleTempDir fail'); + } + } catch (error) { + let err: BusinessError = error as BusinessError; + console.error('cleanBundleTempDir failed with err: ' + JSON.stringify(err)); + } + } + ``` ## IncrementalBackupSession12+ @@ -3468,3 +3657,98 @@ cancel(bundleName: string): number }; this.incrementalBackupSession = new backup.IncrementalBackupSession(generalCallbacks); // 创建增量备份流程 ``` + +### cleanBundleTempDir20+ + +cleanBundleTempDir(bundleName: string): Promise<boolean> + +备份或者恢复任务结束后,提供给工具用于清理当前应用的临时目录(./backup目录下的backup和restore目录)的数据。 + +**需要权限**:ohos.permission.BACKUP + +**系统能力**:SystemCapability.FileManagement.StorageService.Backup + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| --------------- | -------- | ---- | -------------------------- | +| bundleName | string | 是 | 需要清理临时目录数据的应用名称。 | + +**返回值:** + +| 类型 | 说明 | +| ------------------- | ----------------------- | +| Promise<boolean> | 返回清理结果。
true:清理成功;
false:清理失败;
| + +**错误码:** + +以下错误码的详细介绍请参见[文件管理子系统错误码](errorcode-filemanagement.md)。 + +| 错误码ID | 错误信息 | +| -------- | ---------------------------------------------------------------------------------------------- | +| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | +| 202 | Permission verification failed, application which is not a system application uses system API. | +| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3. Parameter verifcation faild| + +**示例:** + + ```ts + import fs from '@ohos.file.fs'; + import { BusinessError } from '@ohos.base'; + import backup from '@ohos.file.backup'; + + let generalCallbacks: backup.GeneralCallbacks = { + onFileReady: (err: BusinessError, file: backup.File) => { + if (err) { + console.error('onFileReady failed with err: ' + JSON.stringify(err)); + return; + } + console.info('onFileReady success'); + fs.closeSync(file.fd); + }, + onBundleBegin: (err: BusinessError, bundleName: string) => { + if (err) { + console.error('onBundleBegin failed with err: ' + JSON.stringify(err)); + return; + } + console.info('onBundleBegin success'); + }, + onBundleEnd: (err: BusinessError, bundleName: string) => { + if (err) { + console.error('onBundleEnd failed with err: ' + JSON.stringify(err)); + return; + } + this.cleanBundleTempDir(bundleName); + }, + onAllBundlesEnd: (err: BusinessError) => { + if (err) { + console.error('onAllBundlesEnd failed with err: ' + JSON.stringify(err)); + return; + } + console.info('onAllBundlesEnd success'); + }, + onBackupServiceDied: () => { + console.info('service died'); + }, + onResultReport: (bundleName: string, result: string) => { + console.info('onResultReport success, bundleName: ' + bundleName +'result: ' + result); + }, + onProcess: (bundleName: string, process: string) => { + console.info('onProcess success, bundleName: ' + bundleName +'process: ' + process); + } + }; + let incrementalBackupSession = new backup.IncrementalBackupSession(generalCallbacks); // 创建增量备份流程 + async cleanBundleTempDir(bundleName: string) { + try { + let res = await incrementalBackupSession.cleanBundleTempDir(bundleName); + if (res) { + console.info('cleanBundleTempDir success'); + } else { + console.info('cleanBundleTempDir fail'); + } + } catch (error) { + let err: BusinessError = error as BusinessError; + console.error('cleanBundleTempDir failed with err: ' + JSON.stringify(err)); + } + } + ```