From 3fea5e52804a2f5bb8dd58cd62191c22d716b51e Mon Sep 17 00:00:00 2001 From: huaqingsimeng <1004904143@qq.com> Date: Fri, 19 May 2023 11:05:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=87=E4=BB=BD=E6=81=A2=E5=A4=8D=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E8=AF=B4=E6=98=8E=E6=96=87=E6=A1=A3=E8=AF=B4=E6=98=8E?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: huaqingsimeng <qiukaiqing@huawei.com> --- .../reference/apis/js-apis-file-backup.md | 589 +++++++++++++----- 1 file changed, 426 insertions(+), 163 deletions(-) diff --git a/zh-cn/application-dev/reference/apis/js-apis-file-backup.md b/zh-cn/application-dev/reference/apis/js-apis-file-backup.md index 90e9dc3a84..3dffdc6fea 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-file-backup.md +++ b/zh-cn/application-dev/reference/apis/js-apis-file-backup.md @@ -19,9 +19,9 @@ import backup from '@ohos.file.backup'; **系统能力**:SystemCapability.FileManagement.StorageService.Backup -| å称 | 类型 | å¿…å¡« | 说明 | -| ---------- | ------ | ---- | ------------------------- | -| bundleName | string | 是 | 应用å称,å¯é€šè¿‡[bundle.BundleInfo](js-apis-bundle-BundleInfo.md)æ供的获å–æ–¹å¼èŽ·å–。 | +| å称 | 类型 | å¿…å¡« | 说明 | +| ---------- | ------ | ---- | ---------------------------------------------------------------------------------------------- | +| bundleName | string | 是 | 应用å称,å¯é€šè¿‡[bundle.BundleInfo](js-apis-bundle-BundleInfo.md)æ供的获å–æ–¹å¼èŽ·å–。 | | uri | string | 是 | åº”ç”¨æ²™ç®±å†…å¾…ä¼ è¾“æ–‡ä»¶çš„å称,当å‰uri尚未å‡çº§ä¸ºæ ‡å‡†æ ¼å¼ï¼Œä»…接å—0-9a-zA-Z下划线(_)点(.)组æˆçš„å称 | ## FileData @@ -70,14 +70,15 @@ onFileReady : AsyncCallback<File> **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[文件管ç†å系统错误ç ](../errorcodes/errorcode-filemanagement.md)。 -| 错误ç ID | é”™è¯¯ä¿¡æ¯ | -| ---------------------------- | ---------- | -| 13600001 | IPC error | -| 13900005 | I/O error | -| 13900011 | Out of memory | -| 13900020 | Invalid argument | + +| 错误ç ID | é”™è¯¯ä¿¡æ¯ | +| -------- | ----------------------- | +| 13600001 | IPC error | +| 13900005 | I/O error | +| 13900011 | Out of memory | +| 13900020 | Invalid argument | | 13900025 | No space left on device | -| 13900042 | Unknown error | +| 13900042 | Unknown error | **示例:** @@ -103,14 +104,15 @@ onBundleBegin : AsyncCallback<string> **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[文件管ç†å系统错误ç ](../errorcodes/errorcode-filemanagement.md)。 -| 错误ç ID | é”™è¯¯ä¿¡æ¯ | -| ---------------------------- | ---------- | -| 13600001 | IPC error | -| 13900005 | I/O error | -| 13900011 | Out of memory | -| 13900020 | Invalid argument | + +| 错误ç ID | é”™è¯¯ä¿¡æ¯ | +| -------- | ----------------------- | +| 13600001 | IPC error | +| 13900005 | I/O error | +| 13900011 | Out of memory | +| 13900020 | Invalid argument | | 13900025 | No space left on device | -| 13900042 | Unknown error | +| 13900042 | Unknown error | **示例:** @@ -134,14 +136,15 @@ onBundleEnd : AsyncCallback<string> **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[文件管ç†å系统错误ç ](../errorcodes/errorcode-filemanagement.md)。 -| 错误ç ID | é”™è¯¯ä¿¡æ¯ | -| ---------------------------- | ---------- | -| 13600001 | IPC error | -| 13900005 | I/O error | -| 13900011 | Out of memory | -| 13900020 | Invalid argument | + +| 错误ç ID | é”™è¯¯ä¿¡æ¯ | +| -------- | ----------------------- | +| 13600001 | IPC error | +| 13900005 | I/O error | +| 13900011 | Out of memory | +| 13900020 | Invalid argument | | 13900025 | No space left on device | -| 13900042 | Unknown error | +| 13900042 | Unknown error | **示例:** @@ -165,14 +168,15 @@ onAllBundlesEnd : AsyncCallback<undefined> **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[文件管ç†å系统错误ç ](../errorcodes/errorcode-filemanagement.md)。 -| 错误ç ID | é”™è¯¯ä¿¡æ¯ | -| ---------------------------- | ---------- | -| 13600001 | IPC error | -| 13900005 | I/O error | -| 13900011 | Out of memory | -| 13900020 | Invalid argument | + +| 错误ç ID | é”™è¯¯ä¿¡æ¯ | +| -------- | ----------------------- | +| 13600001 | IPC error | +| 13900005 | I/O error | +| 13900011 | Out of memory | +| 13900020 | Invalid argument | | 13900025 | No space left on device | -| 13900042 | Unknown error | +| 13900042 | Unknown error | **示例:** @@ -213,20 +217,21 @@ getLocalCapabilities(callback: AsyncCallback<FileData>): void **å‚数:** -| å‚æ•°å | 类型 | å¿…å¡« | 说明 | -| -------- | ------------------------- | ---- | --------------------- | +| å‚æ•°å | 类型 | å¿…å¡« | 说明 | +| -------- | ------------------------------------------ | ---- | ------------------------------------------------------ | | callback | AsyncCallback<[FileData](#filedata)> | 是 | 回调函数。当获å–æˆåŠŸï¼Œerr为undefined,å¦åˆ™ä¸ºé”™è¯¯å¯¹è±¡ã€‚ | **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[文件管ç†å系统错误ç ](../errorcodes/errorcode-filemanagement.md)。 -| 错误ç ID | é”™è¯¯ä¿¡æ¯ | -| ---------------------------- | ---------- | -| 13600001 | IPC error | -| 13900005 | I/O error | -| 13900011 | Out of memory | + +| 错误ç ID | é”™è¯¯ä¿¡æ¯ | +| -------- | ----------------------- | +| 13600001 | IPC error | +| 13900005 | I/O error | +| 13900011 | Out of memory | | 13900025 | No space left on device | -| 13900042 | Unknown error | +| 13900042 | Unknown error | **示例:** @@ -275,31 +280,34 @@ getLocalCapabilities(): Promise<FileData> **返回值:** -| 类型 | 说明 | -| -------------------- | ------------------ | +| 类型 | 说明 | +| ------------------------------------ | --------------------------------------------------- | | Promise<[FileData](#filedata)> | Promise对象,返回æ述本地能力的Json文件的FileData。 | **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[文件管ç†å系统错误ç ](../errorcodes/errorcode-filemanagement.md)。 -| 错误ç ID | é”™è¯¯ä¿¡æ¯ | -| ---------------------------- | ---------- | -| 13600001 | IPC error | -| 13900005 | I/O error | -| 13900011 | Out of memory | + +| 错误ç ID | é”™è¯¯ä¿¡æ¯ | +| -------- | ----------------------- | +| 13600001 | IPC error | +| 13900005 | I/O error | +| 13900011 | Out of memory | | 13900025 | No space left on device | -| 13900042 | Unknown error | +| 13900042 | Unknown error | **示例:** ```js import fs from '@ohos.file.fs'; - try { - let fileData = await backup.getLocalCapabilities(); - console.info('getLocalCapabilities success'); - fs.closeSync(fileData.fd); - } catch (err) { - console.error('getLocalCapabilities failed with err: ' + err); + async function getLocalCapabilities() { + try { + let fileData = await backup.getLocalCapabilities(); + console.info('getLocalCapabilities success'); + fs.closeSync(fileData.fd); + } catch (err) { + console.error('getLocalCapabilities failed with err: ' + err); + } } ``` @@ -345,7 +353,7 @@ constructor(callbacks: GeneralCallbacks); ```js import fs from '@ohos.file.fs'; - let sessionBackup = new backup.SessionBackup({ + let generalCallbacks = backup.GeneralCallbacks({ onFileReady: (err, file) => { if (err) { console.error('onFileReady failed with err: ' + err); @@ -375,6 +383,7 @@ constructor(callbacks: GeneralCallbacks); console.info('service died'); } }); + let sessionBackup = new backup.SessionBackup(generalCallbacks); ``` ### appendBundles @@ -397,19 +406,52 @@ appendBundles(bundlesToBackup: string[], callback: AsyncCallback<void>): v **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[文件管ç†å系统错误ç ](../errorcodes/errorcode-filemanagement.md)。 -| 错误ç ID | é”™è¯¯ä¿¡æ¯ | -| ---------------------------- | ---------- | -| 13600001 | IPC error | + +| 错误ç ID | é”™è¯¯ä¿¡æ¯ | +| -------- | ----------------------- | +| 13600001 | IPC error | | 13900001 | Operation not permitted | -| 13900005 | I/O error | -| 13900011 | Out of memory | -| 13900020 | Invalid argument | +| 13900005 | I/O error | +| 13900011 | Out of memory | +| 13900020 | Invalid argument | | 13900025 | No space left on device | -| 13900042 | Unknown error | +| 13900042 | Unknown error | **示例:** + ```js + import fs from '@ohos.file.fs'; + let sessionBackup = new backup.SessionBackup({ + onFileReady: (err, file) => { + if (err) { + console.error('onFileReady failed with err: ' + err); + } + console.info('onFileReady success'); + fs.closeSync(file.fd); + }, + onBundleBegin: (err, bundleName) => { + if (err) { + console.error('onBundleBegin failed with err: ' + err); + } + console.info('onBundleBegin success'); + }, + onBundleEnd: (err, bundleName) => { + if (err) { + console.error('onBundleEnd failed with err: ' + err); + } + console.info('onBundleEnd success'); + }, + onAllBundlesEnd: (err) => { + if (err) { + console.error('onAllBundlesEnd failed with err: ' + err); + } + console.info('onAllBundlesEnd success'); + }, + onBackupServiceDied: () => { + console.info('service died'); + } + }); try { sessionBackup.appendBundles(['com.example.hiworld'], (err) => { if (err) { @@ -447,24 +489,58 @@ appendBundles(bundlesToBackup: string[]): Promise<void> **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[文件管ç†å系统错误ç ](../errorcodes/errorcode-filemanagement.md)。 -| 错误ç ID | é”™è¯¯ä¿¡æ¯ | -| ---------------------------- | ---------- | -| 13600001 | IPC error | + +| 错误ç ID | é”™è¯¯ä¿¡æ¯ | +| -------- | ----------------------- | +| 13600001 | IPC error | | 13900001 | Operation not permitted | -| 13900005 | I/O error | -| 13900011 | Out of memory | -| 13900020 | Invalid argument | +| 13900005 | I/O error | +| 13900011 | Out of memory | +| 13900020 | Invalid argument | | 13900025 | No space left on device | -| 13900042 | Unknown error | +| 13900042 | Unknown error | **示例:** ```js - try { - await sessionBackup.appendBundles(['com.example.hiworld']); - console.info('appendBundles success'); - } catch (err) { + import fs from '@ohos.file.fs'; + let sessionBackup = new backup.SessionBackup({ + onFileReady: (err, file) => { + if (err) { + console.error('onFileReady failed with err: ' + err); + } + console.info('onFileReady success'); + fs.closeSync(file.fd); + }, + onBundleBegin: (err, bundleName) => { + if (err) { + console.error('onBundleBegin failed with err: ' + err); + } + console.info('onBundleBegin success'); + }, + onBundleEnd: (err, bundleName) => { + if (err) { + console.error('onBundleEnd failed with err: ' + err); + } + console.info('onBundleEnd success'); + }, + onAllBundlesEnd: (err) => { + if (err) { + console.error('onAllBundlesEnd failed with err: ' + err); + } + console.info('onAllBundlesEnd success'); + }, + onBackupServiceDied: () => { + console.info('service died'); + } + }); + async function appendBundles() { + try { + await sessionBackup.appendBundles(['com.example.hiworld']); + console.info('appendBundles success'); + } catch (err) { console.error('appendBundles failed with err: ' + err); + } } ``` @@ -492,7 +568,7 @@ constructor(callbacks: GeneralCallbacks); ```js import fs from '@ohos.file.fs'; - let sessionRestore = new backup.SessionRestore({ + let generalCallbacks = backup.GeneralCallbacks({ onFileReady: (err, file) => { if (err) { console.error('onFileReady failed with err: ' + err); @@ -518,10 +594,11 @@ constructor(callbacks: GeneralCallbacks); } console.info('onAllBundlesEnd success'); }, - onRestoreServiceDied: () => { + onBackupServiceDied: () => { console.info('service died'); } }); + let sessionRestore = new backup.SessionRestore(generalCallbacks); ``` ### appendBundles @@ -550,30 +627,64 @@ appendBundles(remoteCapabilitiesFd: number, bundlesToBackup: string[], callback: **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[文件管ç†å系统错误ç ](../errorcodes/errorcode-filemanagement.md)。 -| 错误ç ID | é”™è¯¯ä¿¡æ¯ | -| ---------------------------- | ---------- | -| 13600001 | IPC error | + +| 错误ç ID | é”™è¯¯ä¿¡æ¯ | +| -------- | ----------------------- | +| 13600001 | IPC error | | 13900001 | Operation not permitted | -| 13900005 | I/O error | -| 13900011 | Out of memory | -| 13900020 | Invalid argument | +| 13900005 | I/O error | +| 13900011 | Out of memory | +| 13900020 | Invalid argument | | 13900025 | No space left on device | -| 13900042 | Unknown error | +| 13900042 | Unknown error | **示例:** ```js - try { - let fileData = await backup.getLocalCapabilities(); - console.info('getLocalCapabilities success'); - sessionRestore.appendBundles(fileData.fd, ['com.example.hiworld'], (err) => { + import fs from '@ohos.file.fs'; + let sessionRestore = new backup.SessionRestore({ + onFileReady: (err, file) => { + if (err) { + console.error('onFileReady failed with err: ' + err); + } + console.info('onFileReady success'); + fs.closeSync(file.fd); + }, + onBundleBegin: (err, bundleName) => { + if (err) { + console.error('onBundleBegin failed with err: ' + err); + } + console.info('onBundleBegin success'); + }, + onBundleEnd: (err, bundleName) => { + if (err) { + console.error('onBundleEnd failed with err: ' + err); + } + console.info('onBundleEnd success'); + }, + onAllBundlesEnd: (err) => { + if (err) { + console.error('onAllBundlesEnd failed with err: ' + err); + } + console.info('onAllBundlesEnd success'); + }, + onBackupServiceDied: () => { + console.info('service died'); + } + }); + async function appendBundles() { + try { + let fileData = await backup.getLocalCapabilities(); + console.info('getLocalCapabilities success'); + sessionRestore.appendBundles(fileData.fd, ['com.example.hiworld'], (err) => { if (err) { console.error('appendBundles failed with err: ' + err); } console.info('appendBundles success'); }); - } catch (err) { - console.error('appendBundles failed with err: ' + err); + } catch (err) { + console.error('getLocalCapabilities failed with err: ' + err); + } } ``` @@ -608,26 +719,60 @@ appendBundles(remoteCapabilitiesFd: number, bundlesToBackup: string[]): Promise& **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[文件管ç†å系统错误ç ](../errorcodes/errorcode-filemanagement.md)。 -| 错误ç ID | é”™è¯¯ä¿¡æ¯ | -| ---------------------------- | ---------- | -| 13600001 | IPC error | + +| 错误ç ID | é”™è¯¯ä¿¡æ¯ | +| -------- | ----------------------- | +| 13600001 | IPC error | | 13900001 | Operation not permitted | -| 13900005 | I/O error | -| 13900011 | Out of memory | -| 13900020 | Invalid argument | +| 13900005 | I/O error | +| 13900011 | Out of memory | +| 13900020 | Invalid argument | | 13900025 | No space left on device | -| 13900042 | Unknown error | +| 13900042 | Unknown error | **示例:** ```js - try { - let fileData = await backup.getLocalCapabilities(); - console.info('getLocalCapabilities success'); - await sessionRestore.appendBundles(fileData.fd, ['com.example.hiworld']); - console.info('appendBundles success'); - } catch (err) { - console.error('appendBundles failed with err: ' + err); + import fs from '@ohos.file.fs'; + let sessionRestore = new backup.SessionRestore({ + onFileReady: (err, file) => { + if (err) { + console.error('onFileReady failed with err: ' + err); + } + console.info('onFileReady success'); + fs.closeSync(file.fd); + }, + onBundleBegin: (err, bundleName) => { + if (err) { + console.error('onBundleBegin failed with err: ' + err); + } + console.info('onBundleBegin success'); + }, + onBundleEnd: (err, bundleName) => { + if (err) { + console.error('onBundleEnd failed with err: ' + err); + } + console.info('onBundleEnd success'); + }, + onAllBundlesEnd: (err) => { + if (err) { + console.error('onAllBundlesEnd failed with err: ' + err); + } + console.info('onAllBundlesEnd success'); + }, + onBackupServiceDied: () => { + console.info('service died'); + } + }); + async function appendBundles() { + try { + let fileData = await backup.getLocalCapabilities(); + console.info('getLocalCapabilities success'); + await sessionRestore.appendBundles(fileData.fd, ['com.example.hiworld']); + console.info('appendBundles success'); + } catch (err) { + console.error('getLocalCapabilities failed with err: ' + err); + } } ``` @@ -658,18 +803,49 @@ getFileHandle(fileMeta: FileMeta, callback: AsyncCallback<void>): void **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[文件管ç†å系统错误ç ](../errorcodes/errorcode-filemanagement.md)。 -| 错误ç ID | é”™è¯¯ä¿¡æ¯ | -| ---------------------------- | ---------- | -| 13600001 | IPC error | + +| 错误ç ID | é”™è¯¯ä¿¡æ¯ | +| -------- | ----------------------- | +| 13600001 | IPC error | | 13900001 | Operation not permitted | -| 13900020 | Invalid argument | -| 13900042 | Unknown error | +| 13900020 | Invalid argument | +| 13900042 | Unknown error | **示例:** ```js - try { - sessionRestore.getFileHandle({ + import fs from '@ohos.file.fs'; + let sessionRestore = new backup.SessionRestore({ + onFileReady: (err, file) => { + if (err) { + console.error('onFileReady failed with err: ' + err); + } + console.info('onFileReady success'); + fs.closeSync(file.fd); + }, + onBundleBegin: (err, bundleName) => { + if (err) { + console.error('onBundleBegin failed with err: ' + err); + } + console.info('onBundleBegin success'); + }, + onBundleEnd: (err, bundleName) => { + if (err) { + console.error('onBundleEnd failed with err: ' + err); + } + console.info('onBundleEnd success'); + }, + onAllBundlesEnd: (err) => { + if (err) { + console.error('onAllBundlesEnd failed with err: ' + err); + } + console.info('onAllBundlesEnd success'); + }, + onBackupServiceDied: () => { + console.info('service died'); + } + }); + sessionRestore.getFileHandle({ bundleName: "com.example.hiworld", uri: "test.txt" }, (err, file) => { @@ -678,9 +854,6 @@ getFileHandle(fileMeta: FileMeta, callback: AsyncCallback<void>): void } console.info('getFileHandle success'); }); - } catch (err) { - console.error('getFileHandle failed with err: ' + err); - } ``` ### getFileHandle @@ -715,24 +888,58 @@ getFileHandle(fileMeta: FileMeta): Promise<void> **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[文件管ç†å系统错误ç ](../errorcodes/errorcode-filemanagement.md)。 -| 错误ç ID | é”™è¯¯ä¿¡æ¯ | -| ---------------------------- | ---------- | -| 13600001 | IPC error | + +| 错误ç ID | é”™è¯¯ä¿¡æ¯ | +| -------- | ----------------------- | +| 13600001 | IPC error | | 13900001 | Operation not permitted | -| 13900020 | Invalid argument | -| 13900042 | Unknown error | +| 13900020 | Invalid argument | +| 13900042 | Unknown error | **示例:** ```js - try { - await sessionRestore.getFileHandle({ - bundleName: "com.example.hiworld", - uri: "test.txt" + import fs from '@ohos.file.fs'; + let sessionRestore = new backup.SessionRestore({ + onFileReady: (err, file) => { + if (err) { + console.error('onFileReady failed with err: ' + err); + } + console.info('onFileReady success'); + fs.closeSync(file.fd); + }, + onBundleBegin: (err, bundleName) => { + if (err) { + console.error('onBundleBegin failed with err: ' + err); + } + console.info('onBundleBegin success'); + }, + onBundleEnd: (err, bundleName) => { + if (err) { + console.error('onBundleEnd failed with err: ' + err); + } + console.info('onBundleEnd success'); + }, + onAllBundlesEnd: (err) => { + if (err) { + console.error('onAllBundlesEnd failed with err: ' + err); + } + console.info('onAllBundlesEnd success'); + }, + onBackupServiceDied: () => { + console.info('service died'); + } + }); + async function getFileHandle() { + try { + await sessionRestore.getFileHandle({ + bundleName: "com.example.hiworld", + uri: "test.txt" }); - console.info('getFileHandle success'); - } catch (err) { - console.error('getFileHandle failed with err: ' + err); + console.info('getFileHandle success'); + } catch (err) { + console.error('getFileHandle failed with err: ' + err); + } } ``` @@ -762,36 +969,62 @@ publishFile(fileMeta: FileMeta, callback: AsyncCallback<void>): void **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[文件管ç†å系统错误ç ](../errorcodes/errorcode-filemanagement.md)。 -| 错误ç ID | é”™è¯¯ä¿¡æ¯ | -| ---------------------------- | ---------- | -| 13600001 | IPC error | + +| 错误ç ID | é”™è¯¯ä¿¡æ¯ | +| -------- | ----------------------- | +| 13600001 | IPC error | | 13900001 | Operation not permitted | -| 13900020 | Invalid argument | -| 13900042 | Unknown error | +| 13900020 | Invalid argument | +| 13900042 | Unknown error | **示例:** ```js - try { - onFileReady: (err, file) => { - if (err) { - console.error('onFileReady failed with err: ' + err); - } - console.info('onFileReady success'); - fs.closeSync(file.fd); - sessionRestore.publishFile({ - bundleName: file.bundleName, - uri: file.uri - }, (err) => { + import fs from '@ohos.file.fs'; + let g_session; + function createSessionRestore() { + let sessionRestore = new backup.SessionRestore({ + onFileReady: (err, file) => { if (err) { - console.error('publishFile failed with err: ' + err); + console.error('onFileReady failed with err: ' + err); } - console.info('publishFile success'); - }); - } - } catch (err) { - console.error('publishFile failed with err: ' + err); + console.info('onFileReady success'); + fs.closeSync(file.fd); + g_session.publishFile({ + bundleName: file.bundleName, + uri: file.uri + }, (err) => { + if (err) { + console.error('publishFile failed with err: ' + err); + } + console.info('publishFile success'); + }); + }, + onBundleBegin: (err, bundleName) => { + if (err) { + console.error('onBundleBegin failed with err: ' + err); + } + console.info('onBundleBegin success'); + }, + onBundleEnd: (err, bundleName) => { + if (err) { + console.error('onBundleEnd failed with err: ' + err); + } + console.info('onBundleEnd success'); + }, + onAllBundlesEnd: (err) => { + if (err) { + console.error('onAllBundlesEnd failed with err: ' + err); + } + console.info('onAllBundlesEnd success'); + }, + onBackupServiceDied: () => { + console.info('service died'); + } + }); + return sessionRestore; } + g_session = createSessionRestore(); ``` ### publishFile @@ -825,30 +1058,60 @@ publishFile(fileMeta: FileMeta): Promise<void> **错误ç :** 以下错误ç 的详细介ç»è¯·å‚è§[文件管ç†å系统错误ç ](../errorcodes/errorcode-filemanagement.md)。 -| 错误ç ID | é”™è¯¯ä¿¡æ¯ | -| ---------------------------- | ---------- | -| 13600001 | IPC error | + +| 错误ç ID | é”™è¯¯ä¿¡æ¯ | +| -------- | ----------------------- | +| 13600001 | IPC error | | 13900001 | Operation not permitted | -| 13900020 | Invalid argument | -| 13900042 | Unknown error | +| 13900020 | Invalid argument | +| 13900042 | Unknown error | **示例:** ```js - try { - onFileReady: (err, file) => { - if (err) { - console.error('onFileReady failed with err: ' + err); - } - console.info('onFileReady success'); - fs.closeSync(file.fd); - await sessionRestore.publishFile({ + import fs from '@ohos.file.fs'; + let g_session; + async function publishFile(file) + { + await g_session.publishFile({ bundleName: file.bundleName, uri: file.uri - }); - console.info('publishFile success'); - }, - } catch (err) { - console.error('publishFile failed with err: ' + err); + }); + } + function createSessionRestore() { + let sessionRestore = new backup.SessionRestore({ + onFileReady: (err, file) => { + if (err) { + console.error('onFileReady failed with err: ' + err); + } + console.info('onFileReady success'); + fs.closeSync(file.fd); + publishFile(file); + console.info('publishFile success'); + }, + onBundleBegin: (err, bundleName) => { + if (err) { + console.error('onBundleBegin failed with err: ' + err); + } + console.info('onBundleBegin success'); + }, + onBundleEnd: (err, bundleName) => { + if (err) { + console.error('onBundleEnd failed with err: ' + err); + } + console.info('onBundleEnd success'); + }, + onAllBundlesEnd: (err) => { + if (err) { + console.error('onAllBundlesEnd failed with err: ' + err); + } + console.info('onAllBundlesEnd success'); + }, + onBackupServiceDied: () => { + console.info('service died'); + } + }); + return sessionRestore; } + g_session = createSessionRestore(); ``` -- GitLab