提交 c5906728 编写于 作者: A Annie_wang

update docs

Signed-off-by: NAnnie_wang <annie.wangli@huawei.com>
上级 f9cf0d1c
...@@ -19,9 +19,9 @@ Defines a file metadata object, which includes the application name and file URI ...@@ -19,9 +19,9 @@ Defines a file metadata object, which includes the application name and file URI
**System capability**: SystemCapability.FileManagement.StorageService.Backup **System capability**: SystemCapability.FileManagement.StorageService.Backup
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| ---------- | ------ | ---- | ------------------------- | | ---------- | ------ | ---- | ---------------------------------------------------------------------------------------------- |
| bundleName | string | Yes | Bundle name of the application, which can be obtained by using the method provided by [bundle.BundleInfo](js-apis-bundle-BundleInfo.md). | | bundleName | string | Yes | Bundle name of the application, which can be obtained by using the method provided by [bundle.BundleInfo](js-apis-bundle-BundleInfo.md). |
| uri | string | Yes | Name of the file in the application sandbox.<br>Currently, the URI has not been upgraded to the standard format. It can consist of digits (0–9), letters (a–z and A–Z), underscores (_), and period (.) only.| | uri | string | Yes | Name of the file in the application sandbox.<br>Currently, the URI has not been upgraded to the standard format. It can consist of digits (0–9), letters (a–z and A–Z), underscores (_), and period (.) only.|
## FileData ## FileData
...@@ -63,21 +63,22 @@ Called when the server sends a file to the client. If the file is sent successfu ...@@ -63,21 +63,22 @@ Called when the server sends a file to the client. If the file is sent successfu
> **NOTE** > **NOTE**
> >
> The **File** returned by **AsyncCallback** is the file.backup.[File](#file). The returned file belongs to the backup service. Once the file is closed, the backup service shall clear the resources used by the file. However, the client must close the file handle first. > The **File** returned by **AsyncCallback** is the file.backup.[File](#file). The returned file belongs to the backup service. Once the file is closed, the backup service shall clear the resources used by the file at the proper time. However, the client must close the file handle first.
**System capability**: SystemCapability.FileManagement.StorageService.Backup **System capability**: SystemCapability.FileManagement.StorageService.Backup
**Error codes** **Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID | Error Message |
| ---------------------------- | ---------- | | ID| Error Message |
| 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 |
**Example** **Example**
...@@ -103,14 +104,15 @@ onBundleBegin : AsyncCallback&lt;string&gt; ...@@ -103,14 +104,15 @@ onBundleBegin : AsyncCallback&lt;string&gt;
**Error codes** **Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID | Error Message |
| ---------------------------- | ---------- | | ID| Error Message |
| 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 |
**Example** **Example**
...@@ -134,14 +136,15 @@ Called when the backup or restoration of an application ends. If the backup or r ...@@ -134,14 +136,15 @@ Called when the backup or restoration of an application ends. If the backup or r
**Error codes** **Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID | Error Message |
| ---------------------------- | ---------- | | ID| Error Message |
| 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 |
**Example** **Example**
...@@ -165,14 +168,15 @@ Called when the backup or restoration of all bundles ends. If the backup or rest ...@@ -165,14 +168,15 @@ Called when the backup or restoration of all bundles ends. If the backup or rest
**Error codes** **Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID | Error Message |
| ---------------------------- | ---------- | | ID| Error Message |
| 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 |
**Example** **Example**
...@@ -213,20 +217,21 @@ Obtains a JSON file that describes local capabilities. This API uses an asynchro ...@@ -213,20 +217,21 @@ Obtains a JSON file that describes local capabilities. This API uses an asynchro
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | --------------------- | | -------- | ------------------------------------------ | ---- | ------------------------------------------------------ |
| callback | AsyncCallback&lt;[FileData](#filedata)&gt; | Yes | Callback invoked to return the result. If the file is obtained, **err** is **undefined**. Otherwise, **err** is an error object.| | callback | AsyncCallback&lt;[FileData](#filedata)&gt; | Yes | Callback invoked to return the result. If the file is obtained, **err** is **undefined**. Otherwise, **err** is an error object.|
**Error codes** **Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID | Error Message |
| ---------------------------- | ---------- | | ID| Error Message |
| 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 |
**Example** **Example**
...@@ -275,31 +280,34 @@ Obtains a JSON file that describes local capabilities. This API uses a promise t ...@@ -275,31 +280,34 @@ Obtains a JSON file that describes local capabilities. This API uses a promise t
**Return value** **Return value**
| Type | Description | | Type | Description |
| -------------------- | ------------------ | | ------------------------------------ | --------------------------------------------------- |
| Promise&lt;[FileData](#filedata)&gt; | Promise used to return the **FileData** of the JSON file obtained.| | Promise&lt;[FileData](#filedata)&gt; | Promise used to return the **FileData** of the JSON file obtained.|
**Error codes** **Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID | Error Message |
| ---------------------------- | ---------- | | ID| Error Message |
| 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 |
**Example** **Example**
```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 @@ A constructor used to create a **SessionBackup** instance. ...@@ -345,7 +353,7 @@ A constructor used to create a **SessionBackup** instance.
```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 @@ A constructor used to create a **SessionBackup** instance. ...@@ -375,6 +383,7 @@ A constructor used to create a **SessionBackup** instance.
console.info('service died'); console.info('service died');
} }
}); });
let sessionBackup = new backup.SessionBackup(generalCallbacks);
``` ```
### appendBundles ### appendBundles
...@@ -397,19 +406,52 @@ Appends the applications whose data needs to be backed up. Currently, the obtain ...@@ -397,19 +406,52 @@ Appends the applications whose data needs to be backed up. Currently, the obtain
**Error codes** **Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID | Error Message |
| ---------------------------- | ---------- | | ID| Error Message |
| 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 |
**Example** **Example**
```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 @@ Appends the applications whose data needs to be backed up. Currently, the obtain ...@@ -447,24 +489,58 @@ Appends the applications whose data needs to be backed up. Currently, the obtain
**Error codes** **Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID | Error Message |
| ---------------------------- | ---------- | | ID| Error Message |
| 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 |
**Example** **Example**
```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 @@ A constructor used to create a **SessionRestore** instance. ...@@ -492,7 +568,7 @@ A constructor used to create a **SessionRestore** instance.
```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 @@ A constructor used to create a **SessionRestore** instance. ...@@ -518,10 +594,11 @@ A constructor used to create a **SessionRestore** instance.
} }
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 @@ Appends the applications whose data needs to be restored. Currently, the obtaine ...@@ -550,30 +627,64 @@ Appends the applications whose data needs to be restored. Currently, the obtaine
**Error codes** **Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID | Error Message |
| ---------------------------- | ---------- | | ID| Error Message |
| 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 |
**Example** **Example**
```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 @@ Appends the applications whose data needs to be restored. Currently, the obtaine ...@@ -608,26 +719,60 @@ Appends the applications whose data needs to be restored. Currently, the obtaine
**Error codes** **Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID | Error Message |
| ---------------------------- | ---------- | | ID| Error Message |
| 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 |
**Example** **Example**
```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 @@ Obtains the handle of the shared file from the service. This API uses an asynchr ...@@ -658,18 +803,49 @@ Obtains the handle of the shared file from the service. This API uses an asynchr
**Error codes** **Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID | Error Message |
| ---------------------------- | ---------- | | ID| Error Message |
| 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 |
**Example** **Example**
```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 @@ For details about the error codes, see [File Management Error Codes](../errorcod ...@@ -678,9 +854,6 @@ For details about the error codes, see [File Management Error Codes](../errorcod
} }
console.info('getFileHandle success'); console.info('getFileHandle success');
}); });
} catch (err) {
console.error('getFileHandle failed with err: ' + err);
}
``` ```
### getFileHandle ### getFileHandle
...@@ -715,24 +888,58 @@ Obtains the handle of the shared file from the service. This API uses a promise ...@@ -715,24 +888,58 @@ Obtains the handle of the shared file from the service. This API uses a promise
**Error codes** **Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID | Error Message |
| ---------------------------- | ---------- | | ID| Error Message |
| 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 |
**Example** **Example**
```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 @@ Publishes **FileMeta** to the backup service to indicate that the file content i ...@@ -762,36 +969,62 @@ Publishes **FileMeta** to the backup service to indicate that the file content i
**Error codes** **Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID | Error Message |
| ---------------------------- | ---------- | | ID| Error Message |
| 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 |
**Example** **Example**
```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 @@ Publishes **FileMeta** to the backup service to indicate that the file content i ...@@ -825,30 +1058,60 @@ Publishes **FileMeta** to the backup service to indicate that the file content i
**Error codes** **Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md). For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md).
| ID | Error Message |
| ---------------------------- | ---------- | | ID| Error Message |
| 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 |
**Example** **Example**
```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.
先完成此消息的编辑!
想要评论请 注册