mirror of
https://gitee.com/openharmony/xts_dcts
synced 2024-11-22 23:29:46 +00:00
【分布式文件】【master】分布式文件server端代码上库
Signed-off-by: jinhaihw <jinhai2@huawei.com> Change-Id: Ib6808ca5c1180ddd49a34ce44d0a56ba6fb22c23
This commit is contained in:
parent
4d1bcd4d45
commit
477d96d1ff
@ -15,7 +15,10 @@ import("//build/ohos_var.gni")
|
||||
group("filemanagement") {
|
||||
testonly = true
|
||||
if (is_standard_system) {
|
||||
deps = [ "fileioClient:DctsFileioClientTest" ]
|
||||
deps = [
|
||||
"fileio/client:DctsFileioClientTest",
|
||||
"fileio/server:DctsFileioServer",
|
||||
]
|
||||
} else {
|
||||
deps = [ "wifi_standard:ActsWifiJSTest" ]
|
||||
}
|
||||
|
Binary file not shown.
@ -15,14 +15,13 @@
|
||||
|
||||
import rpc from "@ohos.rpc";
|
||||
import fileio from '@ohos.fileio';
|
||||
import featureAbility from '@ohos.ability.featureAbility'
|
||||
import deviceManager from '@ohos.distributedHardware.deviceManager';
|
||||
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from 'deccjsunit/index';
|
||||
import featureAbility from "@ohos.ability.featureAbility";
|
||||
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index';
|
||||
|
||||
let gIRemoteObject = null;
|
||||
let connectId = null;
|
||||
|
||||
describe('FileioJsUnitTest', function () {
|
||||
describe('FileioJsUnit', function(){
|
||||
console.info("----------SUB_Storage_Fileio_Distributed JS Test is starting----------");
|
||||
const DISTRIBUTED_FILE_CONTENT = 'content';
|
||||
const SERVER_CHECK_SUCCESS = 'SUCCESS';
|
||||
@ -114,7 +113,7 @@ describe('FileioJsUnitTest', function () {
|
||||
|
||||
let want = {
|
||||
"bundleName": "com.ohos.fileiotest",
|
||||
"abilityName": "com.example.server.ServiceAbility",
|
||||
"abilityName": "com.ohos.fileiotest.ServiceAbility",
|
||||
"deviceId": deviceId,
|
||||
"flags": 256
|
||||
}
|
||||
@ -3435,4 +3434,4 @@ describe('FileioJsUnitTest', function () {
|
||||
});
|
||||
|
||||
console.info("----------SUB_Storage_Fileio_Distributed JS Test is end----------");
|
||||
});
|
||||
});
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
* Copyright (C) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
@ -2,7 +2,7 @@
|
||||
"string": [
|
||||
{
|
||||
"name": "app_name",
|
||||
"value": "fileioClient"
|
||||
"value": "FileioClientTest"
|
||||
},
|
||||
{
|
||||
"name": "mainability_description",
|
Before Width: | Height: | Size: 6.6 KiB After Width: | Height: | Size: 6.6 KiB |
35
filemanagement/fileio/server/BUILD.gn
Normal file
35
filemanagement/fileio/server/BUILD.gn
Normal file
@ -0,0 +1,35 @@
|
||||
# Copyright (C) 2022 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//test/xts/tools/build/suite.gni")
|
||||
|
||||
ohos_hap_assist_suite("DctsFileioServer") {
|
||||
hap_profile = "./src/main/config.json"
|
||||
deps = [
|
||||
":fileio_js_assets",
|
||||
":fileio_js_resources",
|
||||
]
|
||||
|
||||
certificate_profile = "./signature/openharmony_sx.p7b"
|
||||
hap_name = "DctsFileioServer"
|
||||
subsystem_name = "filemanagement"
|
||||
part_name = "dfs_service"
|
||||
}
|
||||
ohos_js_assets("fileio_js_assets") {
|
||||
source_dir = "./src/main/js"
|
||||
hap_profile = "./src/main/config.json"
|
||||
}
|
||||
ohos_resources("fileio_js_resources") {
|
||||
sources = [ "./src/main/resources" ]
|
||||
hap_profile = "./src/main/config.json"
|
||||
}
|
21
filemanagement/fileio/server/Test.json
Normal file
21
filemanagement/fileio/server/Test.json
Normal file
@ -0,0 +1,21 @@
|
||||
{
|
||||
"description": "Configuration for fileio Server",
|
||||
"driver": {
|
||||
"type": "JSUnitServer",
|
||||
"test-timeout": "900000",
|
||||
"package": "com.ohos.fileiotest",
|
||||
|
||||
"abilityName": ".MainAbility",
|
||||
"shell-timeout": "900000"
|
||||
},
|
||||
"kits": [
|
||||
{
|
||||
"test-file-name": [
|
||||
"DctsFileioServer.hap"
|
||||
],
|
||||
"type": "AppInstallKit",
|
||||
"cleanup-apps": true
|
||||
}
|
||||
]
|
||||
|
||||
}
|
BIN
filemanagement/fileio/server/signature/openharmony_sx.p7b
Normal file
BIN
filemanagement/fileio/server/signature/openharmony_sx.p7b
Normal file
Binary file not shown.
89
filemanagement/fileio/server/src/main/config.json
Normal file
89
filemanagement/fileio/server/src/main/config.json
Normal file
@ -0,0 +1,89 @@
|
||||
{
|
||||
"app": {
|
||||
"bundleName": "com.ohos.fileiotest",
|
||||
"vendor": "fileio",
|
||||
"version": {
|
||||
"code": 1000000,
|
||||
"name": "1.0.0"
|
||||
},
|
||||
"apiVersion": {
|
||||
"compatible": 7,
|
||||
"target": 8
|
||||
}
|
||||
},
|
||||
"deviceConfig": {},
|
||||
"module": {
|
||||
"reqPermissions": [
|
||||
{
|
||||
"name": "ohos.permission.DISTRIBUTED_DATASYNC"
|
||||
},
|
||||
{
|
||||
"name": "ohos.permission.GET_DISTRIBUTED_DEVICE_INFO"
|
||||
},
|
||||
{
|
||||
"name": "ohos.permission.GET_BUNDLE_INFO"
|
||||
}
|
||||
],
|
||||
"package": "com.ohos.fileiotest",
|
||||
"name": ".MyApplication",
|
||||
"mainAbility": "com.ohos.fileiotest.MainAbility",
|
||||
"deviceType": [
|
||||
"phone"
|
||||
],
|
||||
"distro": {
|
||||
"deliveryWithInstall": true,
|
||||
"moduleName": "entry",
|
||||
"moduleType": "entry",
|
||||
"installationFree": false
|
||||
},
|
||||
"abilities": [
|
||||
{
|
||||
"skills": [
|
||||
{
|
||||
"entities": [
|
||||
"entity.system.home"
|
||||
],
|
||||
"actions": [
|
||||
"action.system.home"
|
||||
]
|
||||
}
|
||||
],
|
||||
"orientation": "unspecified",
|
||||
"visible": true,
|
||||
"srcPath": "MainAbility",
|
||||
"name": ".MainAbility",
|
||||
"srcLanguage": "js",
|
||||
"icon": "$media:icon",
|
||||
"description": "$string:mainability_description",
|
||||
"formsEnabled": false,
|
||||
"label": "$string:entry_MainAbility",
|
||||
"type": "page",
|
||||
"launchType": "standard"
|
||||
},
|
||||
{
|
||||
"srcPath": "ServiceAbility",
|
||||
"name": ".ServiceAbility",
|
||||
"icon": "$media:icon",
|
||||
"srcLanguage": "js",
|
||||
|
||||
"description": "$string:serviceability_description",
|
||||
"type": "service",
|
||||
"visible": true,
|
||||
"formsEnabled": false
|
||||
}
|
||||
],
|
||||
"js": [
|
||||
{
|
||||
"pages": [
|
||||
"pages/index/index",
|
||||
"pages/second/second"
|
||||
],
|
||||
"name": ".MainAbility",
|
||||
"window": {
|
||||
"designWidth": 720,
|
||||
"autoDesignWidth": false
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
23
filemanagement/fileio/server/src/main/js/MainAbility/app.js
Normal file
23
filemanagement/fileio/server/src/main/js/MainAbility/app.js
Normal file
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export default {
|
||||
onCreate() {
|
||||
console.info("Application onCreate");
|
||||
},
|
||||
onDestroy() {
|
||||
console.info("Application onDestroy");
|
||||
}
|
||||
};
|
@ -0,0 +1,11 @@
|
||||
{
|
||||
"strings": {
|
||||
"hello": "Hello",
|
||||
"world": "World",
|
||||
"page": "Second Page",
|
||||
"next": "Next Page",
|
||||
"back": "Back"
|
||||
},
|
||||
"Files": {
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
{
|
||||
"strings": {
|
||||
"hello": "您好",
|
||||
"world": "世界",
|
||||
"page": "第二页",
|
||||
"next": "下一页",
|
||||
"back": "返回"
|
||||
},
|
||||
"Files": {
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
.container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
left: 0px;
|
||||
top: 0px;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.title {
|
||||
font-size: 60px;
|
||||
text-align: center;
|
||||
width: 100%;
|
||||
height: 40%;
|
||||
margin: 10px;
|
||||
}
|
||||
|
||||
.btn {
|
||||
width: 50%;
|
||||
height: 100px;
|
||||
font-size: 40px;
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
<div class="container" onswipe="touchMove">
|
||||
<text class="title">
|
||||
{{ $t('strings.hello') }} {{ title }}
|
||||
</text>
|
||||
<input class="btn" type="button" value="{{ $t('strings.next') }}" onclick="onclick"></input>
|
||||
</div>
|
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import router from '@system.router'
|
||||
import featureAbility from '@ohos.ability.featureAbility';
|
||||
|
||||
export default {
|
||||
data: {
|
||||
title: ""
|
||||
},
|
||||
|
||||
onInit() {
|
||||
this.grantPermission();
|
||||
},
|
||||
onclick: function () {
|
||||
router.replace({
|
||||
uri: "pages/second/second"
|
||||
})
|
||||
},
|
||||
grantPermission() {
|
||||
console.info('Calc[IndexPage] grantPermission')
|
||||
let context = featureAbility.getContext()
|
||||
context.requestPermissionsFromUser(['ohos.permission.DISTRIBUTED_DATASYNC'], 666, function (result) {
|
||||
console.info('Calc[IndexPage] grantPermission,requestPermissionsFromUser,'+result.requestCode)
|
||||
|
||||
})
|
||||
},
|
||||
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
.container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
left: 0px;
|
||||
top: 0px;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.title {
|
||||
font-size: 60px;
|
||||
text-align: center;
|
||||
width: 100%;
|
||||
height: 40%;
|
||||
margin: 10px;
|
||||
}
|
||||
|
||||
.btn {
|
||||
width: 50%;
|
||||
height: 100px;
|
||||
font-size: 40px;
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
<div class="container">
|
||||
<text class="title">
|
||||
{{ $t('strings.page') }}
|
||||
</text>
|
||||
<input class="btn" type="button" value="{{ $t('strings.back') }}" onclick="onclick"></input>
|
||||
</div>
|
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import router from '@system.router'
|
||||
|
||||
export default {
|
||||
data: {
|
||||
title: 'World'
|
||||
},
|
||||
onclick: function () {
|
||||
router.replace({
|
||||
uri: "pages/index/index"
|
||||
})
|
||||
}
|
||||
}
|
@ -0,0 +1,218 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import rpc from "@ohos.rpc";
|
||||
import fileio from '@ohos.fileio';
|
||||
|
||||
export default {
|
||||
onStart() {
|
||||
console.info('FileioServer: onStart')
|
||||
},
|
||||
onStop() {
|
||||
console.info('FileioServer: onStop')
|
||||
},
|
||||
onCommand(want, startId) {
|
||||
console.info('FileioServer: onCommand, want: ' + JSON.stringify(want) + ', startId: ' + startId)
|
||||
},
|
||||
onConnect(want) {
|
||||
console.info('FileioServer: service onConnect called.')
|
||||
return new Stub("rpcTestAbility")
|
||||
},
|
||||
onDisconnect(want) {
|
||||
console.info('FileioServer: service onDisConnect called.')
|
||||
},
|
||||
onReconnect(want) {
|
||||
console.info('FileioServer: service onReConnect called.')
|
||||
}
|
||||
}
|
||||
|
||||
function checkDirExists(destDirPath) {
|
||||
console.info("start check dir :" + destDirPath);
|
||||
try {
|
||||
fileio.accessSync(destDirPath, 0);
|
||||
console.info('------------------- dest dir exists.');
|
||||
return true;
|
||||
} catch (e) {
|
||||
console.info('------------------- dest dir is not exists.');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function checkFileExists(destFilePath,) {
|
||||
console.info("start check file :" + destFilePath);
|
||||
try {
|
||||
fileio.accessSync(destFilePath, 0);
|
||||
console.info('------------------- ' + destFilePath + ' exists.');
|
||||
return true;
|
||||
} catch (e) {
|
||||
console.info('------------------- ' + destFilePath + ' not exists.');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function getFileContent(fpath) {
|
||||
console.info("start get file content:" + fpath);
|
||||
let content = "";
|
||||
try {
|
||||
content = fileio.readTextSync(fpath);
|
||||
console.info("-------------- dest file content :" + content);
|
||||
} catch (e) {
|
||||
console.info("-------------- read dest file content failed." + e);
|
||||
}
|
||||
return content;
|
||||
}
|
||||
|
||||
const CODE_MK_DIR = 1;
|
||||
const CODE_RM_DIR = 2;
|
||||
const CODE_CREATE_FILE = 3;
|
||||
const CODE_DELETE_FILE = 4;
|
||||
const CODE_GET_FILE_CONTENT = 5;
|
||||
const CODE_GET_FILE_STAT = 6;
|
||||
const CODE_FSYNC_FILE = 7;
|
||||
|
||||
class Stub extends rpc.RemoteObject {
|
||||
constructor(descriptor) {
|
||||
super(descriptor);
|
||||
}
|
||||
|
||||
onRemoteRequest(code, data, reply, option) {
|
||||
try {
|
||||
console.info("onRemoteRequest: " + code)
|
||||
switch (code) {
|
||||
case CODE_MK_DIR:
|
||||
{
|
||||
console.info("case CODE_MK_DIR start")
|
||||
let path = data.readString()
|
||||
console.info("The server's readString result is " + path);
|
||||
let checkResult = checkDirExists(path);
|
||||
let result;
|
||||
if (checkResult == true) {
|
||||
result = reply.writeString("SUCCESS");
|
||||
} else {
|
||||
result = reply.writeString("Server side dir synchronization creation failed.");
|
||||
}
|
||||
|
||||
console.info("The server's writeString result is " + result);
|
||||
return true;
|
||||
}
|
||||
case CODE_RM_DIR:
|
||||
{
|
||||
console.info("case CODE_RM_DIR start");
|
||||
let path = data.readString();
|
||||
console.info("The server's readString result is " + path);
|
||||
|
||||
let checkResult = checkDirExists(path);
|
||||
let result;
|
||||
if (checkResult == false) {
|
||||
result = reply.writeString("SUCCESS");
|
||||
} else {
|
||||
result = reply.writeString("Server side dir synchronization deletion failed.");
|
||||
}
|
||||
|
||||
console.info("The server's writeString result is " + result);
|
||||
return true;
|
||||
}
|
||||
case CODE_CREATE_FILE:
|
||||
{
|
||||
console.info("case CODE_CREATE_FILE start");
|
||||
let path = data.readString();
|
||||
console.info("The server's readString result is " + path);
|
||||
|
||||
let checkResult = checkFileExists(path);
|
||||
let result;
|
||||
if (checkResult == true) {
|
||||
result = reply.writeString("SUCCESS");
|
||||
} else {
|
||||
result = reply.writeString("Server side file synchronization creation failed!");
|
||||
}
|
||||
|
||||
console.info("The server's writeString result is " + result);
|
||||
return true;
|
||||
}
|
||||
case CODE_DELETE_FILE:
|
||||
{
|
||||
console.info("case CODE_DELETE_FILE start");
|
||||
let path = data.readString();
|
||||
console.info("The server's readString result is " + path);
|
||||
|
||||
let checkResult = checkFileExists(path);
|
||||
let result;
|
||||
if (checkResult == true) {
|
||||
result = reply.writeString("Server side file synchronization deletion failed.");
|
||||
} else {
|
||||
result = reply.writeString("SUCCESS");
|
||||
}
|
||||
|
||||
console.info("The server's writeString result is " + result);
|
||||
return true;
|
||||
}
|
||||
case CODE_GET_FILE_CONTENT:
|
||||
{
|
||||
console.info("case CODE_GET_FILE_CONTENT start");
|
||||
let path = data.readString();
|
||||
console.info("The server's readString result is " + path);
|
||||
checkFileExists(path);
|
||||
let content ="";
|
||||
try {
|
||||
console.info("---------------- start get file content:" + path);
|
||||
content = getFileContent(path);
|
||||
console.info("-------------- dest file content :" + content);
|
||||
} catch (e) {
|
||||
console.info("-------------- read dest file content failed." + e);
|
||||
}
|
||||
|
||||
let result = reply.writeString(content);
|
||||
console.info("The server's writeString result is " + result);
|
||||
return true;
|
||||
}
|
||||
case CODE_GET_FILE_STAT:
|
||||
{
|
||||
console.info("case CODE_GET_FILE_STAT start");
|
||||
let path = data.readString();
|
||||
console.info("The server's readString result is " + path);
|
||||
let localStat = fileio.statSync(path);
|
||||
let localStatInfo = "localStat.size = " + localStat.size + ",localStat.mode = " + localStat.mode;
|
||||
let result = reply.writeString(localStatInfo);
|
||||
console.info("The server's writeString result is " + result);
|
||||
return true;
|
||||
}
|
||||
case CODE_FSYNC_FILE:
|
||||
{
|
||||
console.info("case CODE_FSYNC_FILE start");
|
||||
let path = data.readString();
|
||||
console.info("The server's readString result is " + path);
|
||||
let result;
|
||||
try{
|
||||
let fd = fileio.openSync(path, 0o2);
|
||||
fileio.fsyncSync(fd);
|
||||
console.info("sync data succeed");
|
||||
result = reply.writeString("SUCCESS");
|
||||
} catch (e) {
|
||||
console.info("sync data failed with error:" + e);
|
||||
result = reply.writeString("FAILED");
|
||||
}
|
||||
console.info("The server's writeString result is " + result);
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
console.error("default case " + code);
|
||||
return super.onRemoteMessageRequest(code, data, reply, option);
|
||||
}
|
||||
} catch (error) {
|
||||
console.info("onRemoteMessageRequest: " + error);
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
{
|
||||
"string": [
|
||||
{
|
||||
"name": "entry_MainAbility",
|
||||
"value": "FileioServer"
|
||||
},
|
||||
{
|
||||
"name": "mainability_description",
|
||||
"value": "JS_Empty Ability"
|
||||
},
|
||||
{
|
||||
"name": "serviceability_description",
|
||||
"value": "hap sample empty service"
|
||||
}
|
||||
]
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 6.6 KiB |
Loading…
Reference in New Issue
Block a user