未验证 提交 fa97eacf 编写于 作者: O openharmony_ci 提交者: Gitee

!18425 备份恢复接口说明文档说明调整

Merge pull request !18425 from 花轻似梦/master
...@@ -19,9 +19,9 @@ import backup from '@ohos.file.backup'; ...@@ -19,9 +19,9 @@ import backup from '@ohos.file.backup';
**系统能力**:SystemCapability.FileManagement.StorageService.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下划线(_)点(.)组成的名称 | | uri | string | 是 | 应用沙箱内待传输文件的名称,当前uri尚未升级为标准格式,仅接受0-9a-zA-Z下划线(_)点(.)组成的名称 |
## FileData ## FileData
...@@ -70,14 +70,15 @@ onFileReady : AsyncCallback<File> ...@@ -70,14 +70,15 @@ onFileReady : AsyncCallback<File>
**错误码:** **错误码:**
以下错误码的详细介绍请参见[文件管理子系统错误码](../errorcodes/errorcode-filemanagement.md) 以下错误码的详细介绍请参见[文件管理子系统错误码](../errorcodes/errorcode-filemanagement.md)
| 错误码ID | 错误信息 |
| ---------------------------- | ---------- | | 错误码ID | 错误信息 |
| 13600001 | IPC error | | -------- | ----------------------- |
| 13900005 | I/O error | | 13600001 | IPC error |
| 13900011 | Out of memory | | 13900005 | I/O error |
| 13900020 | Invalid argument | | 13900011 | Out of memory |
| 13900020 | Invalid argument |
| 13900025 | No space left on device | | 13900025 | No space left on device |
| 13900042 | Unknown error | | 13900042 | Unknown error |
**示例:** **示例:**
...@@ -103,14 +104,15 @@ onBundleBegin : AsyncCallback<string> ...@@ -103,14 +104,15 @@ onBundleBegin : AsyncCallback<string>
**错误码:** **错误码:**
以下错误码的详细介绍请参见[文件管理子系统错误码](../errorcodes/errorcode-filemanagement.md) 以下错误码的详细介绍请参见[文件管理子系统错误码](../errorcodes/errorcode-filemanagement.md)
| 错误码ID | 错误信息 |
| ---------------------------- | ---------- | | 错误码ID | 错误信息 |
| 13600001 | IPC error | | -------- | ----------------------- |
| 13900005 | I/O error | | 13600001 | IPC error |
| 13900011 | Out of memory | | 13900005 | I/O error |
| 13900020 | Invalid argument | | 13900011 | Out of memory |
| 13900020 | Invalid argument |
| 13900025 | No space left on device | | 13900025 | No space left on device |
| 13900042 | Unknown error | | 13900042 | Unknown error |
**示例:** **示例:**
...@@ -134,14 +136,15 @@ onBundleEnd : AsyncCallback<string> ...@@ -134,14 +136,15 @@ onBundleEnd : AsyncCallback<string>
**错误码:** **错误码:**
以下错误码的详细介绍请参见[文件管理子系统错误码](../errorcodes/errorcode-filemanagement.md) 以下错误码的详细介绍请参见[文件管理子系统错误码](../errorcodes/errorcode-filemanagement.md)
| 错误码ID | 错误信息 |
| ---------------------------- | ---------- | | 错误码ID | 错误信息 |
| 13600001 | IPC error | | -------- | ----------------------- |
| 13900005 | I/O error | | 13600001 | IPC error |
| 13900011 | Out of memory | | 13900005 | I/O error |
| 13900020 | Invalid argument | | 13900011 | Out of memory |
| 13900020 | Invalid argument |
| 13900025 | No space left on device | | 13900025 | No space left on device |
| 13900042 | Unknown error | | 13900042 | Unknown error |
**示例:** **示例:**
...@@ -165,14 +168,15 @@ onAllBundlesEnd : AsyncCallback<undefined> ...@@ -165,14 +168,15 @@ onAllBundlesEnd : AsyncCallback<undefined>
**错误码:** **错误码:**
以下错误码的详细介绍请参见[文件管理子系统错误码](../errorcodes/errorcode-filemanagement.md) 以下错误码的详细介绍请参见[文件管理子系统错误码](../errorcodes/errorcode-filemanagement.md)
| 错误码ID | 错误信息 |
| ---------------------------- | ---------- | | 错误码ID | 错误信息 |
| 13600001 | IPC error | | -------- | ----------------------- |
| 13900005 | I/O error | | 13600001 | IPC error |
| 13900011 | Out of memory | | 13900005 | I/O error |
| 13900020 | Invalid argument | | 13900011 | Out of memory |
| 13900020 | Invalid argument |
| 13900025 | No space left on device | | 13900025 | No space left on device |
| 13900042 | Unknown error | | 13900042 | Unknown error |
**示例:** **示例:**
...@@ -213,20 +217,21 @@ getLocalCapabilities(callback: AsyncCallback<FileData>): void ...@@ -213,20 +217,21 @@ getLocalCapabilities(callback: AsyncCallback<FileData>): void
**参数:** **参数:**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------------- | ---- | --------------------- | | -------- | ------------------------------------------ | ---- | ------------------------------------------------------ |
| callback | AsyncCallback<[FileData](#filedata)> | 是 | 回调函数。当获取成功,err为undefined,否则为错误对象。 | | callback | AsyncCallback<[FileData](#filedata)> | 是 | 回调函数。当获取成功,err为undefined,否则为错误对象。 |
**错误码:** **错误码:**
以下错误码的详细介绍请参见[文件管理子系统错误码](../errorcodes/errorcode-filemanagement.md) 以下错误码的详细介绍请参见[文件管理子系统错误码](../errorcodes/errorcode-filemanagement.md)
| 错误码ID | 错误信息 |
| ---------------------------- | ---------- | | 错误码ID | 错误信息 |
| 13600001 | IPC error | | -------- | ----------------------- |
| 13900005 | I/O error | | 13600001 | IPC error |
| 13900011 | Out of memory | | 13900005 | I/O error |
| 13900011 | Out of memory |
| 13900025 | No space left on device | | 13900025 | No space left on device |
| 13900042 | Unknown error | | 13900042 | Unknown error |
**示例:** **示例:**
...@@ -275,31 +280,34 @@ getLocalCapabilities(): Promise<FileData> ...@@ -275,31 +280,34 @@ getLocalCapabilities(): Promise<FileData>
**返回值:** **返回值:**
| 类型 | 说明 | | 类型 | 说明 |
| -------------------- | ------------------ | | ------------------------------------ | --------------------------------------------------- |
| Promise<[FileData](#filedata)> | Promise对象,返回描述本地能力的Json文件的FileData。 | | Promise<[FileData](#filedata)> | Promise对象,返回描述本地能力的Json文件的FileData。 |
**错误码:** **错误码:**
以下错误码的详细介绍请参见[文件管理子系统错误码](../errorcodes/errorcode-filemanagement.md) 以下错误码的详细介绍请参见[文件管理子系统错误码](../errorcodes/errorcode-filemanagement.md)
| 错误码ID | 错误信息 |
| ---------------------------- | ---------- | | 错误码ID | 错误信息 |
| 13600001 | IPC error | | -------- | ----------------------- |
| 13900005 | I/O error | | 13600001 | IPC error |
| 13900011 | Out of memory | | 13900005 | I/O error |
| 13900011 | Out of memory |
| 13900025 | No space left on device | | 13900025 | No space left on device |
| 13900042 | Unknown error | | 13900042 | Unknown error |
**示例:** **示例:**
```js ```js
import fs from '@ohos.file.fs'; import fs from '@ohos.file.fs';
try { async function getLocalCapabilities() {
let fileData = await backup.getLocalCapabilities(); try {
console.info('getLocalCapabilities success'); let fileData = await backup.getLocalCapabilities();
fs.closeSync(fileData.fd); console.info('getLocalCapabilities success');
} catch (err) { fs.closeSync(fileData.fd);
console.error('getLocalCapabilities failed with err: ' + err); } catch (err) {
console.error('getLocalCapabilities failed with err: ' + err);
}
} }
``` ```
...@@ -345,7 +353,7 @@ constructor(callbacks: GeneralCallbacks); ...@@ -345,7 +353,7 @@ constructor(callbacks: GeneralCallbacks);
```js ```js
import fs from '@ohos.file.fs'; import fs from '@ohos.file.fs';
let sessionBackup = new backup.SessionBackup({ let generalCallbacks = backup.GeneralCallbacks({
onFileReady: (err, file) => { onFileReady: (err, file) => {
if (err) { if (err) {
console.error('onFileReady failed with err: ' + err); console.error('onFileReady failed with err: ' + err);
...@@ -375,6 +383,7 @@ constructor(callbacks: GeneralCallbacks); ...@@ -375,6 +383,7 @@ constructor(callbacks: GeneralCallbacks);
console.info('service died'); console.info('service died');
} }
}); });
let sessionBackup = new backup.SessionBackup(generalCallbacks);
``` ```
### appendBundles ### appendBundles
...@@ -397,19 +406,52 @@ appendBundles(bundlesToBackup: string[], callback: AsyncCallback<void>): v ...@@ -397,19 +406,52 @@ appendBundles(bundlesToBackup: string[], callback: AsyncCallback<void>): v
**错误码:** **错误码:**
以下错误码的详细介绍请参见[文件管理子系统错误码](../errorcodes/errorcode-filemanagement.md) 以下错误码的详细介绍请参见[文件管理子系统错误码](../errorcodes/errorcode-filemanagement.md)
| 错误码ID | 错误信息 |
| ---------------------------- | ---------- | | 错误码ID | 错误信息 |
| 13600001 | IPC error | | -------- | ----------------------- |
| 13600001 | IPC error |
| 13900001 | Operation not permitted | | 13900001 | Operation not permitted |
| 13900005 | I/O error | | 13900005 | I/O error |
| 13900011 | Out of memory | | 13900011 | Out of memory |
| 13900020 | Invalid argument | | 13900020 | Invalid argument |
| 13900025 | No space left on device | | 13900025 | No space left on device |
| 13900042 | Unknown error | | 13900042 | Unknown error |
**示例:** **示例:**
```js ```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 { try {
sessionBackup.appendBundles(['com.example.hiworld'], (err) => { sessionBackup.appendBundles(['com.example.hiworld'], (err) => {
if (err) { if (err) {
...@@ -447,24 +489,58 @@ appendBundles(bundlesToBackup: string[]): Promise<void> ...@@ -447,24 +489,58 @@ appendBundles(bundlesToBackup: string[]): Promise<void>
**错误码:** **错误码:**
以下错误码的详细介绍请参见[文件管理子系统错误码](../errorcodes/errorcode-filemanagement.md) 以下错误码的详细介绍请参见[文件管理子系统错误码](../errorcodes/errorcode-filemanagement.md)
| 错误码ID | 错误信息 |
| ---------------------------- | ---------- | | 错误码ID | 错误信息 |
| 13600001 | IPC error | | -------- | ----------------------- |
| 13600001 | IPC error |
| 13900001 | Operation not permitted | | 13900001 | Operation not permitted |
| 13900005 | I/O error | | 13900005 | I/O error |
| 13900011 | Out of memory | | 13900011 | Out of memory |
| 13900020 | Invalid argument | | 13900020 | Invalid argument |
| 13900025 | No space left on device | | 13900025 | No space left on device |
| 13900042 | Unknown error | | 13900042 | Unknown error |
**示例:** **示例:**
```js ```js
try { import fs from '@ohos.file.fs';
await sessionBackup.appendBundles(['com.example.hiworld']); let sessionBackup = new backup.SessionBackup({
console.info('appendBundles success'); onFileReady: (err, file) => {
} catch (err) { 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); console.error('appendBundles failed with err: ' + err);
}
} }
``` ```
...@@ -492,7 +568,7 @@ constructor(callbacks: GeneralCallbacks); ...@@ -492,7 +568,7 @@ constructor(callbacks: GeneralCallbacks);
```js ```js
import fs from '@ohos.file.fs'; import fs from '@ohos.file.fs';
let sessionRestore = new backup.SessionRestore({ let generalCallbacks = backup.GeneralCallbacks({
onFileReady: (err, file) => { onFileReady: (err, file) => {
if (err) { if (err) {
console.error('onFileReady failed with err: ' + err); console.error('onFileReady failed with err: ' + err);
...@@ -518,10 +594,11 @@ constructor(callbacks: GeneralCallbacks); ...@@ -518,10 +594,11 @@ constructor(callbacks: GeneralCallbacks);
} }
console.info('onAllBundlesEnd success'); console.info('onAllBundlesEnd success');
}, },
onRestoreServiceDied: () => { onBackupServiceDied: () => {
console.info('service died'); console.info('service died');
} }
}); });
let sessionRestore = new backup.SessionRestore(generalCallbacks);
``` ```
### appendBundles ### appendBundles
...@@ -550,30 +627,64 @@ appendBundles(remoteCapabilitiesFd: number, bundlesToBackup: string[], callback: ...@@ -550,30 +627,64 @@ appendBundles(remoteCapabilitiesFd: number, bundlesToBackup: string[], callback:
**错误码:** **错误码:**
以下错误码的详细介绍请参见[文件管理子系统错误码](../errorcodes/errorcode-filemanagement.md) 以下错误码的详细介绍请参见[文件管理子系统错误码](../errorcodes/errorcode-filemanagement.md)
| 错误码ID | 错误信息 |
| ---------------------------- | ---------- | | 错误码ID | 错误信息 |
| 13600001 | IPC error | | -------- | ----------------------- |
| 13600001 | IPC error |
| 13900001 | Operation not permitted | | 13900001 | Operation not permitted |
| 13900005 | I/O error | | 13900005 | I/O error |
| 13900011 | Out of memory | | 13900011 | Out of memory |
| 13900020 | Invalid argument | | 13900020 | Invalid argument |
| 13900025 | No space left on device | | 13900025 | No space left on device |
| 13900042 | Unknown error | | 13900042 | Unknown error |
**示例:** **示例:**
```js ```js
try { import fs from '@ohos.file.fs';
let fileData = await backup.getLocalCapabilities(); let sessionRestore = new backup.SessionRestore({
console.info('getLocalCapabilities success'); onFileReady: (err, file) => {
sessionRestore.appendBundles(fileData.fd, ['com.example.hiworld'], (err) => { 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) { if (err) {
console.error('appendBundles failed with err: ' + err); console.error('appendBundles failed with err: ' + err);
} }
console.info('appendBundles success'); console.info('appendBundles success');
}); });
} catch (err) { } catch (err) {
console.error('appendBundles failed with err: ' + err); console.error('getLocalCapabilities failed with err: ' + err);
}
} }
``` ```
...@@ -608,26 +719,60 @@ appendBundles(remoteCapabilitiesFd: number, bundlesToBackup: string[]): Promise& ...@@ -608,26 +719,60 @@ appendBundles(remoteCapabilitiesFd: number, bundlesToBackup: string[]): Promise&
**错误码:** **错误码:**
以下错误码的详细介绍请参见[文件管理子系统错误码](../errorcodes/errorcode-filemanagement.md) 以下错误码的详细介绍请参见[文件管理子系统错误码](../errorcodes/errorcode-filemanagement.md)
| 错误码ID | 错误信息 |
| ---------------------------- | ---------- | | 错误码ID | 错误信息 |
| 13600001 | IPC error | | -------- | ----------------------- |
| 13600001 | IPC error |
| 13900001 | Operation not permitted | | 13900001 | Operation not permitted |
| 13900005 | I/O error | | 13900005 | I/O error |
| 13900011 | Out of memory | | 13900011 | Out of memory |
| 13900020 | Invalid argument | | 13900020 | Invalid argument |
| 13900025 | No space left on device | | 13900025 | No space left on device |
| 13900042 | Unknown error | | 13900042 | Unknown error |
**示例:** **示例:**
```js ```js
try { import fs from '@ohos.file.fs';
let fileData = await backup.getLocalCapabilities(); let sessionRestore = new backup.SessionRestore({
console.info('getLocalCapabilities success'); onFileReady: (err, file) => {
await sessionRestore.appendBundles(fileData.fd, ['com.example.hiworld']); if (err) {
console.info('appendBundles success'); console.error('onFileReady failed with err: ' + err);
} catch (err) { }
console.error('appendBundles 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 ...@@ -658,18 +803,49 @@ getFileHandle(fileMeta: FileMeta, callback: AsyncCallback<void>): void
**错误码:** **错误码:**
以下错误码的详细介绍请参见[文件管理子系统错误码](../errorcodes/errorcode-filemanagement.md) 以下错误码的详细介绍请参见[文件管理子系统错误码](../errorcodes/errorcode-filemanagement.md)
| 错误码ID | 错误信息 |
| ---------------------------- | ---------- | | 错误码ID | 错误信息 |
| 13600001 | IPC error | | -------- | ----------------------- |
| 13600001 | IPC error |
| 13900001 | Operation not permitted | | 13900001 | Operation not permitted |
| 13900020 | Invalid argument | | 13900020 | Invalid argument |
| 13900042 | Unknown error | | 13900042 | Unknown error |
**示例:** **示例:**
```js ```js
try { import fs from '@ohos.file.fs';
sessionRestore.getFileHandle({ 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", bundleName: "com.example.hiworld",
uri: "test.txt" uri: "test.txt"
}, (err, file) => { }, (err, file) => {
...@@ -678,9 +854,6 @@ getFileHandle(fileMeta: FileMeta, callback: AsyncCallback<void>): void ...@@ -678,9 +854,6 @@ getFileHandle(fileMeta: FileMeta, callback: AsyncCallback<void>): void
} }
console.info('getFileHandle success'); console.info('getFileHandle success');
}); });
} catch (err) {
console.error('getFileHandle failed with err: ' + err);
}
``` ```
### getFileHandle ### getFileHandle
...@@ -715,24 +888,58 @@ getFileHandle(fileMeta: FileMeta): Promise<void> ...@@ -715,24 +888,58 @@ getFileHandle(fileMeta: FileMeta): Promise<void>
**错误码:** **错误码:**
以下错误码的详细介绍请参见[文件管理子系统错误码](../errorcodes/errorcode-filemanagement.md) 以下错误码的详细介绍请参见[文件管理子系统错误码](../errorcodes/errorcode-filemanagement.md)
| 错误码ID | 错误信息 |
| ---------------------------- | ---------- | | 错误码ID | 错误信息 |
| 13600001 | IPC error | | -------- | ----------------------- |
| 13600001 | IPC error |
| 13900001 | Operation not permitted | | 13900001 | Operation not permitted |
| 13900020 | Invalid argument | | 13900020 | Invalid argument |
| 13900042 | Unknown error | | 13900042 | Unknown error |
**示例:** **示例:**
```js ```js
try { import fs from '@ohos.file.fs';
await sessionRestore.getFileHandle({ let sessionRestore = new backup.SessionRestore({
bundleName: "com.example.hiworld", onFileReady: (err, file) => {
uri: "test.txt" 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'); console.info('getFileHandle success');
} catch (err) { } catch (err) {
console.error('getFileHandle failed with err: ' + err); console.error('getFileHandle failed with err: ' + err);
}
} }
``` ```
...@@ -762,36 +969,62 @@ publishFile(fileMeta: FileMeta, callback: AsyncCallback<void>): void ...@@ -762,36 +969,62 @@ publishFile(fileMeta: FileMeta, callback: AsyncCallback<void>): void
**错误码:** **错误码:**
以下错误码的详细介绍请参见[文件管理子系统错误码](../errorcodes/errorcode-filemanagement.md) 以下错误码的详细介绍请参见[文件管理子系统错误码](../errorcodes/errorcode-filemanagement.md)
| 错误码ID | 错误信息 |
| ---------------------------- | ---------- | | 错误码ID | 错误信息 |
| 13600001 | IPC error | | -------- | ----------------------- |
| 13600001 | IPC error |
| 13900001 | Operation not permitted | | 13900001 | Operation not permitted |
| 13900020 | Invalid argument | | 13900020 | Invalid argument |
| 13900042 | Unknown error | | 13900042 | Unknown error |
**示例:** **示例:**
```js ```js
try { import fs from '@ohos.file.fs';
onFileReady: (err, file) => { let g_session;
if (err) { function createSessionRestore() {
console.error('onFileReady failed with err: ' + err); let sessionRestore = new backup.SessionRestore({
} onFileReady: (err, file) => {
console.info('onFileReady success');
fs.closeSync(file.fd);
sessionRestore.publishFile({
bundleName: file.bundleName,
uri: file.uri
}, (err) => {
if (err) { if (err) {
console.error('publishFile failed with err: ' + err); console.error('onFileReady failed with err: ' + err);
} }
console.info('publishFile success'); console.info('onFileReady success');
}); fs.closeSync(file.fd);
} g_session.publishFile({
} catch (err) { bundleName: file.bundleName,
console.error('publishFile failed with err: ' + err); 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 ### publishFile
...@@ -825,30 +1058,60 @@ publishFile(fileMeta: FileMeta): Promise<void> ...@@ -825,30 +1058,60 @@ publishFile(fileMeta: FileMeta): Promise<void>
**错误码:** **错误码:**
以下错误码的详细介绍请参见[文件管理子系统错误码](../errorcodes/errorcode-filemanagement.md) 以下错误码的详细介绍请参见[文件管理子系统错误码](../errorcodes/errorcode-filemanagement.md)
| 错误码ID | 错误信息 |
| ---------------------------- | ---------- | | 错误码ID | 错误信息 |
| 13600001 | IPC error | | -------- | ----------------------- |
| 13600001 | IPC error |
| 13900001 | Operation not permitted | | 13900001 | Operation not permitted |
| 13900020 | Invalid argument | | 13900020 | Invalid argument |
| 13900042 | Unknown error | | 13900042 | Unknown error |
**示例:** **示例:**
```js ```js
try { import fs from '@ohos.file.fs';
onFileReady: (err, file) => { let g_session;
if (err) { async function publishFile(file)
console.error('onFileReady failed with err: ' + err); {
} await g_session.publishFile({
console.info('onFileReady success');
fs.closeSync(file.fd);
await sessionRestore.publishFile({
bundleName: file.bundleName, bundleName: file.bundleName,
uri: file.uri uri: file.uri
}); });
console.info('publishFile success'); }
}, function createSessionRestore() {
} catch (err) { let sessionRestore = new backup.SessionRestore({
console.error('publishFile failed with err: ' + err); 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();
``` ```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册