Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
fa97eacf
D
Docs
项目概览
OpenHarmony
/
Docs
大约 2 年 前同步成功
通知
161
Star
293
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
fa97eacf
编写于
5月 19, 2023
作者:
O
openharmony_ci
提交者:
Gitee
5月 19, 2023
浏览文件
操作
浏览文件
下载
差异文件
!18425 备份恢复接口说明文档说明调整
Merge pull request !18425 from 花轻似梦/master
上级
6f1eac15
3fea5e52
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
426 addition
and
163 deletion
+426
-163
zh-cn/application-dev/reference/apis/js-apis-file-backup.md
zh-cn/application-dev/reference/apis/js-apis-file-backup.md
+426
-163
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-file-backup.md
浏览文件 @
fa97eacf
...
@@ -20,7 +20,7 @@ import backup from '@ohos.file.backup';
...
@@ -20,7 +20,7 @@ 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下划线(_)点(.)组成的名称 |
...
@@ -70,8 +70,9 @@ onFileReady : AsyncCallback<File>
...
@@ -70,8 +70,9 @@ onFileReady : AsyncCallback<File>
**错误码:**
**错误码:**
以下错误码的详细介绍请参见
[
文件管理子系统错误码
](
../errorcodes/errorcode-filemanagement.md
)
。
以下错误码的详细介绍请参见
[
文件管理子系统错误码
](
../errorcodes/errorcode-filemanagement.md
)
。
| 错误码ID | 错误信息 |
| 错误码ID | 错误信息 |
| --------
-------------------- |
---------- |
| --------
| -------------
---------- |
| 13600001 | IPC error |
| 13600001 | IPC error |
| 13900005 | I/O error |
| 13900005 | I/O error |
| 13900011 | Out of memory |
| 13900011 | Out of memory |
...
@@ -103,8 +104,9 @@ onBundleBegin : AsyncCallback<string>
...
@@ -103,8 +104,9 @@ onBundleBegin : AsyncCallback<string>
**错误码:**
**错误码:**
以下错误码的详细介绍请参见
[
文件管理子系统错误码
](
../errorcodes/errorcode-filemanagement.md
)
。
以下错误码的详细介绍请参见
[
文件管理子系统错误码
](
../errorcodes/errorcode-filemanagement.md
)
。
| 错误码ID | 错误信息 |
| 错误码ID | 错误信息 |
| --------
-------------------- |
---------- |
| --------
| -------------
---------- |
| 13600001 | IPC error |
| 13600001 | IPC error |
| 13900005 | I/O error |
| 13900005 | I/O error |
| 13900011 | Out of memory |
| 13900011 | Out of memory |
...
@@ -134,8 +136,9 @@ onBundleEnd : AsyncCallback<string>
...
@@ -134,8 +136,9 @@ onBundleEnd : AsyncCallback<string>
**错误码:**
**错误码:**
以下错误码的详细介绍请参见
[
文件管理子系统错误码
](
../errorcodes/errorcode-filemanagement.md
)
。
以下错误码的详细介绍请参见
[
文件管理子系统错误码
](
../errorcodes/errorcode-filemanagement.md
)
。
| 错误码ID | 错误信息 |
| 错误码ID | 错误信息 |
| --------
-------------------- |
---------- |
| --------
| -------------
---------- |
| 13600001 | IPC error |
| 13600001 | IPC error |
| 13900005 | I/O error |
| 13900005 | I/O error |
| 13900011 | Out of memory |
| 13900011 | Out of memory |
...
@@ -165,8 +168,9 @@ onAllBundlesEnd : AsyncCallback<undefined>
...
@@ -165,8 +168,9 @@ onAllBundlesEnd : AsyncCallback<undefined>
**错误码:**
**错误码:**
以下错误码的详细介绍请参见
[
文件管理子系统错误码
](
../errorcodes/errorcode-filemanagement.md
)
。
以下错误码的详细介绍请参见
[
文件管理子系统错误码
](
../errorcodes/errorcode-filemanagement.md
)
。
| 错误码ID | 错误信息 |
| 错误码ID | 错误信息 |
| --------
-------------------- |
---------- |
| --------
| -------------
---------- |
| 13600001 | IPC error |
| 13600001 | IPC error |
| 13900005 | I/O error |
| 13900005 | I/O error |
| 13900011 | Out of memory |
| 13900011 | Out of memory |
...
@@ -214,14 +218,15 @@ getLocalCapabilities(callback: AsyncCallback<FileData>): void
...
@@ -214,14 +218,15 @@ 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 |
| 13600001 | IPC error |
| 13900005 | I/O error |
| 13900005 | I/O error |
| 13900011 | Out of memory |
| 13900011 | Out of memory |
...
@@ -276,14 +281,15 @@ getLocalCapabilities(): Promise<FileData>
...
@@ -276,14 +281,15 @@ 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 |
| 13600001 | IPC error |
| 13900005 | I/O error |
| 13900005 | I/O error |
| 13900011 | Out of memory |
| 13900011 | Out of memory |
...
@@ -294,6 +300,7 @@ getLocalCapabilities(): Promise<FileData>
...
@@ -294,6 +300,7 @@ getLocalCapabilities(): Promise<FileData>
```
js
```
js
import
fs
from
'
@ohos.file.fs
'
;
import
fs
from
'
@ohos.file.fs
'
;
async
function
getLocalCapabilities
()
{
try
{
try
{
let
fileData
=
await
backup
.
getLocalCapabilities
();
let
fileData
=
await
backup
.
getLocalCapabilities
();
console
.
info
(
'
getLocalCapabilities success
'
);
console
.
info
(
'
getLocalCapabilities success
'
);
...
@@ -301,6 +308,7 @@ getLocalCapabilities(): Promise<FileData>
...
@@ -301,6 +308,7 @@ getLocalCapabilities(): Promise<FileData>
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
error
(
'
getLocalCapabilities failed with err:
'
+
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,8 +406,9 @@ appendBundles(bundlesToBackup: string[], callback: AsyncCallback<void>): v
...
@@ -397,8 +406,9 @@ 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 |
...
@@ -409,7 +419,39 @@ appendBundles(bundlesToBackup: string[], callback: AsyncCallback<void>): v
...
@@ -409,7 +419,39 @@ appendBundles(bundlesToBackup: string[], callback: AsyncCallback<void>): v
**示例:**
**示例:**
```
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,8 +489,9 @@ appendBundles(bundlesToBackup: string[]): Promise<void>
...
@@ -447,8 +489,9 @@ 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 |
...
@@ -460,12 +503,45 @@ appendBundles(bundlesToBackup: string[]): Promise<void>
...
@@ -460,12 +503,45 @@ appendBundles(bundlesToBackup: string[]): Promise<void>
**示例:**
**示例:**
```
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
'
);
}
});
async
function
appendBundles
()
{
try
{
try
{
await
sessionBackup
.
appendBundles
([
'
com.example.hiworld
'
]);
await
sessionBackup
.
appendBundles
([
'
com.example.hiworld
'
]);
console
.
info
(
'
appendBundles success
'
);
console
.
info
(
'
appendBundles success
'
);
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
error
(
'
appendBundles failed with err:
'
+
err
);
console
.
error
(
'
appendBundles failed with err:
'
+
err
);
}
}
}
```
```
## SessionRestore
## SessionRestore
...
@@ -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
'
);
},
},
on
Restore
ServiceDied
:
()
=>
{
on
Backup
ServiceDied
:
()
=>
{
console
.
info
(
'
service died
'
);
console
.
info
(
'
service died
'
);
}
}
});
});
let
sessionRestore
=
new
backup
.
SessionRestore
(
generalCallbacks
);
```
```
### appendBundles
### appendBundles
...
@@ -550,8 +627,9 @@ appendBundles(remoteCapabilitiesFd: number, bundlesToBackup: string[], callback:
...
@@ -550,8 +627,9 @@ 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 |
...
@@ -563,6 +641,38 @@ appendBundles(remoteCapabilitiesFd: number, bundlesToBackup: string[], callback:
...
@@ -563,6 +641,38 @@ appendBundles(remoteCapabilitiesFd: number, bundlesToBackup: string[], callback:
**示例:**
**示例:**
```
js
```
js
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
{
try
{
let
fileData
=
await
backup
.
getLocalCapabilities
();
let
fileData
=
await
backup
.
getLocalCapabilities
();
console
.
info
(
'
getLocalCapabilities success
'
);
console
.
info
(
'
getLocalCapabilities success
'
);
...
@@ -573,7 +683,8 @@ appendBundles(remoteCapabilitiesFd: number, bundlesToBackup: string[], callback:
...
@@ -573,7 +683,8 @@ appendBundles(remoteCapabilitiesFd: number, bundlesToBackup: string[], callback:
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,8 +719,9 @@ appendBundles(remoteCapabilitiesFd: number, bundlesToBackup: string[]): Promise&
...
@@ -608,8 +719,9 @@ 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 |
...
@@ -621,13 +733,46 @@ appendBundles(remoteCapabilitiesFd: number, bundlesToBackup: string[]): Promise&
...
@@ -621,13 +733,46 @@ appendBundles(remoteCapabilitiesFd: number, bundlesToBackup: string[]): Promise&
**示例:**
**示例:**
```
js
```
js
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
{
try
{
let
fileData
=
await
backup
.
getLocalCapabilities
();
let
fileData
=
await
backup
.
getLocalCapabilities
();
console
.
info
(
'
getLocalCapabilities success
'
);
console
.
info
(
'
getLocalCapabilities success
'
);
await
sessionRestore
.
appendBundles
(
fileData
.
fd
,
[
'
com.example.hiworld
'
]);
await
sessionRestore
.
appendBundles
(
fileData
.
fd
,
[
'
com.example.hiworld
'
]);
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
);
}
}
}
```
```
...
@@ -658,8 +803,9 @@ getFileHandle(fileMeta: FileMeta, callback: AsyncCallback<void>): void
...
@@ -658,8 +803,9 @@ 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 |
...
@@ -668,7 +814,37 @@ getFileHandle(fileMeta: FileMeta, callback: AsyncCallback<void>): void
...
@@ -668,7 +814,37 @@ getFileHandle(fileMeta: FileMeta, callback: AsyncCallback<void>): void
**示例:**
**示例:**
```
js
```
js
try
{
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
({
sessionRestore
.
getFileHandle
({
bundleName
:
"
com.example.hiworld
"
,
bundleName
:
"
com.example.hiworld
"
,
uri
:
"
test.txt
"
uri
:
"
test.txt
"
...
@@ -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,8 +888,9 @@ getFileHandle(fileMeta: FileMeta): Promise<void>
...
@@ -715,8 +888,9 @@ 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 |
...
@@ -725,6 +899,38 @@ getFileHandle(fileMeta: FileMeta): Promise<void>
...
@@ -725,6 +899,38 @@ getFileHandle(fileMeta: FileMeta): Promise<void>
**示例:**
**示例:**
```
js
```
js
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
{
try
{
await
sessionRestore
.
getFileHandle
({
await
sessionRestore
.
getFileHandle
({
bundleName
:
"
com.example.hiworld
"
,
bundleName
:
"
com.example.hiworld
"
,
...
@@ -734,6 +940,7 @@ getFileHandle(fileMeta: FileMeta): Promise<void>
...
@@ -734,6 +940,7 @@ getFileHandle(fileMeta: FileMeta): Promise<void>
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
error
(
'
getFileHandle failed with err:
'
+
err
);
console
.
error
(
'
getFileHandle failed with err:
'
+
err
);
}
}
}
```
```
### publishFile
### publishFile
...
@@ -762,8 +969,9 @@ publishFile(fileMeta: FileMeta, callback: AsyncCallback<void>): void
...
@@ -762,8 +969,9 @@ 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 |
...
@@ -772,14 +980,17 @@ publishFile(fileMeta: FileMeta, callback: AsyncCallback<void>): void
...
@@ -772,14 +980,17 @@ publishFile(fileMeta: FileMeta, callback: AsyncCallback<void>): void
**示例:**
**示例:**
```
js
```
js
try
{
import
fs
from
'
@ohos.file.fs
'
;
let
g_session
;
function
createSessionRestore
()
{
let
sessionRestore
=
new
backup
.
SessionRestore
({
onFileReady
:
(
err
,
file
)
=>
{
onFileReady
:
(
err
,
file
)
=>
{
if
(
err
)
{
if
(
err
)
{
console
.
error
(
'
onFileReady failed with err:
'
+
err
);
console
.
error
(
'
onFileReady failed with err:
'
+
err
);
}
}
console
.
info
(
'
onFileReady success
'
);
console
.
info
(
'
onFileReady success
'
);
fs
.
closeSync
(
file
.
fd
);
fs
.
closeSync
(
file
.
fd
);
sessionRestore
.
publishFile
({
g_session
.
publishFile
({
bundleName
:
file
.
bundleName
,
bundleName
:
file
.
bundleName
,
uri
:
file
.
uri
uri
:
file
.
uri
},
(
err
)
=>
{
},
(
err
)
=>
{
...
@@ -788,10 +999,32 @@ publishFile(fileMeta: FileMeta, callback: AsyncCallback<void>): void
...
@@ -788,10 +999,32 @@ publishFile(fileMeta: FileMeta, callback: AsyncCallback<void>): void
}
}
console
.
info
(
'
publishFile success
'
);
console
.
info
(
'
publishFile success
'
);
});
});
},
onBundleBegin
:
(
err
,
bundleName
)
=>
{
if
(
err
)
{
console
.
error
(
'
onBundleBegin failed with err:
'
+
err
);
}
}
}
catch
(
err
)
{
console
.
info
(
'
onBundleBegin success
'
);
console
.
error
(
'
publishFile failed with err:
'
+
err
);
},
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,8 +1058,9 @@ publishFile(fileMeta: FileMeta): Promise<void>
...
@@ -825,8 +1058,9 @@ 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 |
...
@@ -835,20 +1069,49 @@ publishFile(fileMeta: FileMeta): Promise<void>
...
@@ -835,20 +1069,49 @@ publishFile(fileMeta: FileMeta): Promise<void>
**示例:**
**示例:**
```
js
```
js
try
{
import
fs
from
'
@ohos.file.fs
'
;
let
g_session
;
async
function
publishFile
(
file
)
{
await
g_session
.
publishFile
({
bundleName
:
file
.
bundleName
,
uri
:
file
.
uri
});
}
function
createSessionRestore
()
{
let
sessionRestore
=
new
backup
.
SessionRestore
({
onFileReady
:
(
err
,
file
)
=>
{
onFileReady
:
(
err
,
file
)
=>
{
if
(
err
)
{
if
(
err
)
{
console
.
error
(
'
onFileReady failed with err:
'
+
err
);
console
.
error
(
'
onFileReady failed with err:
'
+
err
);
}
}
console
.
info
(
'
onFileReady success
'
);
console
.
info
(
'
onFileReady success
'
);
fs
.
closeSync
(
file
.
fd
);
fs
.
closeSync
(
file
.
fd
);
await
sessionRestore
.
publishFile
({
publishFile
(
file
);
bundleName
:
file
.
bundleName
,
uri
:
file
.
uri
});
console
.
info
(
'
publishFile success
'
);
console
.
info
(
'
publishFile success
'
);
},
},
}
catch
(
err
)
{
onBundleBegin
:
(
err
,
bundleName
)
=>
{
console
.
error
(
'
publishFile failed with err:
'
+
err
);
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录