react-native-update 10.37.6 → 10.37.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/harmony/pushy/BuildProfile.ets +3 -1
- package/harmony/pushy/src/main/ets/DownloadTask.ts +23 -12
- package/harmony/pushy/src/main/ets/PushyFileJSBundleProvider.ets +11 -10
- package/harmony/pushy/src/main/ets/SaveFile.ts +34 -0
- package/harmony/pushy/src/main/ets/UpdateModuleImpl.ts +2 -2
- package/package.json +1 -1
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Use these variables when you tailor your ArkTS code. They must be of the const type.
|
|
3
3
|
*/
|
|
4
|
-
|
|
4
|
+
import packageJson from '../../package.json'
|
|
5
|
+
|
|
6
|
+
export const HAR_VERSION = packageJson.version;
|
|
5
7
|
export const BUILD_MODE_NAME = 'debug';
|
|
6
8
|
export const DEBUG = true;
|
|
7
9
|
export const TARGET_NAME = 'default';
|
|
@@ -5,6 +5,7 @@ import { zlib } from '@kit.BasicServicesKit';
|
|
|
5
5
|
import { EventHub } from './EventHub';
|
|
6
6
|
import { DownloadTaskParams } from './DownloadTaskParams';
|
|
7
7
|
import Pushy from 'librnupdate.so';
|
|
8
|
+
import { saveFileToSandbox } from './SaveFile';
|
|
8
9
|
|
|
9
10
|
interface ZipEntry {
|
|
10
11
|
filename: string;
|
|
@@ -233,7 +234,8 @@ export class DownloadTask {
|
|
|
233
234
|
|
|
234
235
|
return { entries };
|
|
235
236
|
} catch (error) {
|
|
236
|
-
|
|
237
|
+
error.message = 'Failed to process unzipped files:' + error.message;
|
|
238
|
+
console.error(error);
|
|
237
239
|
throw error;
|
|
238
240
|
}
|
|
239
241
|
}
|
|
@@ -262,10 +264,6 @@ export class DownloadTask {
|
|
|
262
264
|
|
|
263
265
|
const copies = obj.copies as Record<string, string>;
|
|
264
266
|
for (const [to, rawPath] of Object.entries(copies)) {
|
|
265
|
-
if (!rawPath.startsWith('resources/rawfile/')) {
|
|
266
|
-
// skip other resource
|
|
267
|
-
continue;
|
|
268
|
-
}
|
|
269
267
|
let from = rawPath.replace('resources/rawfile/', '');
|
|
270
268
|
if (from === '') {
|
|
271
269
|
from = to;
|
|
@@ -311,7 +309,7 @@ export class DownloadTask {
|
|
|
311
309
|
await fileIo.close(writer);
|
|
312
310
|
continue;
|
|
313
311
|
} catch (error) {
|
|
314
|
-
|
|
312
|
+
error.message = 'Failed to process bundle patch:' + error.message;
|
|
315
313
|
throw error;
|
|
316
314
|
}
|
|
317
315
|
}
|
|
@@ -432,15 +430,27 @@ export class DownloadTask {
|
|
|
432
430
|
|
|
433
431
|
for (const [from, targets] of copyList.entries()) {
|
|
434
432
|
currentFrom = from;
|
|
435
|
-
|
|
433
|
+
if (from.startsWith('resources/base/media/')) {
|
|
434
|
+
const mediaName = from
|
|
435
|
+
.replace('resources/base/media/', '')
|
|
436
|
+
.split('.')[0];
|
|
437
|
+
const mediaBuffer = await resourceManager.getMediaByName(mediaName);
|
|
438
|
+
for (const target of targets) {
|
|
439
|
+
const fileStream = fileIo.createStreamSync(target, 'w+');
|
|
440
|
+
fileStream.writeSync(mediaBuffer);
|
|
441
|
+
fileStream.close();
|
|
442
|
+
}
|
|
443
|
+
continue;
|
|
444
|
+
}
|
|
445
|
+
const fromContent = await resourceManager.getRawFd(from);
|
|
436
446
|
for (const target of targets) {
|
|
437
|
-
|
|
438
|
-
fileStream.writeSync(fromContent.buffer);
|
|
439
|
-
fileStream.close();
|
|
447
|
+
saveFileToSandbox(fromContent, target);
|
|
440
448
|
}
|
|
441
449
|
}
|
|
442
450
|
} catch (error) {
|
|
443
|
-
|
|
451
|
+
error.message =
|
|
452
|
+
'Copy from resource failed:' + currentFrom + ',' + error.message;
|
|
453
|
+
console.error(error);
|
|
444
454
|
throw error;
|
|
445
455
|
}
|
|
446
456
|
}
|
|
@@ -473,7 +483,8 @@ export class DownloadTask {
|
|
|
473
483
|
}
|
|
474
484
|
}
|
|
475
485
|
} catch (error) {
|
|
476
|
-
|
|
486
|
+
error.message = 'Cleanup failed:' + error.message;
|
|
487
|
+
console.error(error);
|
|
477
488
|
throw error;
|
|
478
489
|
}
|
|
479
490
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
FileJSBundle,
|
|
3
|
-
HotReloadConfig,
|
|
4
3
|
JSBundleProvider,
|
|
5
|
-
JSBundleProviderError
|
|
4
|
+
JSBundleProviderError,
|
|
6
5
|
} from '@rnoh/react-native-openharmony';
|
|
7
6
|
import common from '@ohos.app.ability.common';
|
|
8
7
|
import fs from '@ohos.file.fs';
|
|
@@ -10,7 +9,7 @@ import { UpdateContext } from './UpdateContext';
|
|
|
10
9
|
|
|
11
10
|
export class PushyFileJSBundleProvider extends JSBundleProvider {
|
|
12
11
|
private updateContext: UpdateContext;
|
|
13
|
-
private path: string = ''
|
|
12
|
+
private path: string = '';
|
|
14
13
|
|
|
15
14
|
constructor(context: common.UIAbilityContext) {
|
|
16
15
|
super();
|
|
@@ -26,24 +25,26 @@ export class PushyFileJSBundleProvider extends JSBundleProvider {
|
|
|
26
25
|
if (!this.path) {
|
|
27
26
|
throw new JSBundleProviderError({
|
|
28
27
|
whatHappened: 'No pushy bundle found. using default bundle',
|
|
29
|
-
howCanItBeFixed: ['']
|
|
30
|
-
})
|
|
28
|
+
howCanItBeFixed: [''],
|
|
29
|
+
});
|
|
31
30
|
}
|
|
32
31
|
try {
|
|
33
32
|
await fs.access(this.path, fs.OpenMode.READ_ONLY);
|
|
34
33
|
return {
|
|
35
|
-
filePath: this.path
|
|
36
|
-
}
|
|
34
|
+
filePath: this.path,
|
|
35
|
+
};
|
|
37
36
|
} catch (error) {
|
|
38
37
|
throw new JSBundleProviderError({
|
|
39
38
|
whatHappened: `Couldn't load JSBundle from ${this.path}`,
|
|
40
39
|
extraData: error,
|
|
41
|
-
howCanItBeFixed: [
|
|
42
|
-
|
|
40
|
+
howCanItBeFixed: [
|
|
41
|
+
`Check if a bundle exists at "${this.path}" on your device.`,
|
|
42
|
+
],
|
|
43
|
+
});
|
|
43
44
|
}
|
|
44
45
|
}
|
|
45
46
|
|
|
46
47
|
getAppKeys(): string[] {
|
|
47
48
|
return [];
|
|
48
49
|
}
|
|
49
|
-
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import resourceManager from '@ohos.resourceManager';
|
|
2
|
+
import fs, { ReadOptions } from '@ohos.file.fs';
|
|
3
|
+
|
|
4
|
+
export const saveFileToSandbox = (
|
|
5
|
+
from: resourceManager.RawFileDescriptor,
|
|
6
|
+
toPath: string,
|
|
7
|
+
) => {
|
|
8
|
+
let to = fs.openSync(toPath, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE);
|
|
9
|
+
|
|
10
|
+
let bufferSize = 30000;
|
|
11
|
+
let buffer = new ArrayBuffer(bufferSize); // 创建buffer缓冲区
|
|
12
|
+
// 要copy的文件的offset和length
|
|
13
|
+
let currentOffset = from.offset;
|
|
14
|
+
let readOption: ReadOptions = {
|
|
15
|
+
offset: currentOffset, // 期望读取文件的位置。可选,默认从当前位置开始读
|
|
16
|
+
length: bufferSize, // 每次期望读取数据的长度。可选,默认缓冲区长度
|
|
17
|
+
};
|
|
18
|
+
// 后面len会一直减,直到没有
|
|
19
|
+
while (true) {
|
|
20
|
+
// 读取buffer容量的内容
|
|
21
|
+
let readLength = fs.readSync(from.fd, buffer, readOption);
|
|
22
|
+
// 写入buffer容量的内容
|
|
23
|
+
fs.writeSync(to.fd, buffer, { length: readLength });
|
|
24
|
+
// 判断后续内容,修改读文件的参数
|
|
25
|
+
// buffer没读满代表文件读完了
|
|
26
|
+
if (readLength < bufferSize) {
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
if (readOption.offset) {
|
|
30
|
+
readOption.offset += readLength;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
fs.close(to);
|
|
34
|
+
};
|
|
@@ -69,7 +69,7 @@ export class UpdateModuleImpl {
|
|
|
69
69
|
): Promise<boolean> {
|
|
70
70
|
const hash = options.hash;
|
|
71
71
|
if (!hash) {
|
|
72
|
-
throw Error('hash
|
|
72
|
+
throw Error('empty hash');
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
try {
|
|
@@ -87,7 +87,7 @@ export class UpdateModuleImpl {
|
|
|
87
87
|
return true;
|
|
88
88
|
} catch (error) {
|
|
89
89
|
logger.error(TAG, `markSuccess failed: ${error}`);
|
|
90
|
-
throw
|
|
90
|
+
throw error;
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
|