mirror of
https://gitcode.com/gh_mirrors/re/react-native-pushy.git
synced 2025-11-22 15:36:10 +08:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e46d01714a | ||
|
|
366b2a6618 |
@@ -1,8 +1,7 @@
|
||||
import http from '@ohos.net.http';
|
||||
import fileIo from '@ohos.file.fs';
|
||||
import common from '@ohos.app.ability.common';
|
||||
import { buffer } from '@kit.ArkTS';
|
||||
import { zlib, BusinessError } from '@kit.BasicServicesKit';
|
||||
import { zlib } from '@kit.BasicServicesKit';
|
||||
import { EventHub } from './EventHub';
|
||||
import { DownloadTaskParams } from './DownloadTaskParams';
|
||||
import Pushy from 'librnupdate.so';
|
||||
@@ -128,53 +127,6 @@ export class DownloadTask {
|
||||
});
|
||||
}
|
||||
|
||||
private async copyFile(from: string, to: string): Promise<void> {
|
||||
let reader;
|
||||
let writer;
|
||||
try {
|
||||
reader = fileIo.openSync(from, fileIo.OpenMode.READ_ONLY);
|
||||
writer = fileIo.openSync(
|
||||
to,
|
||||
fileIo.OpenMode.CREATE | fileIo.OpenMode.WRITE_ONLY,
|
||||
);
|
||||
const arrayBuffer = new ArrayBuffer(4096);
|
||||
let bytesRead: number;
|
||||
do {
|
||||
bytesRead = await fileIo
|
||||
.read(reader.fd, arrayBuffer)
|
||||
.catch((err: BusinessError) => {
|
||||
throw Error(
|
||||
`Error reading file: ${err.message}, code: ${err.code}`,
|
||||
);
|
||||
});
|
||||
if (bytesRead > 0) {
|
||||
const buf = buffer.from(arrayBuffer, 0, bytesRead);
|
||||
await fileIo
|
||||
.write(writer.fd, buf.buffer, {
|
||||
offset: 0,
|
||||
length: bytesRead,
|
||||
})
|
||||
.catch((err: BusinessError) => {
|
||||
throw Error(
|
||||
`Error writing file: ${err.message}, code: ${err.code}`,
|
||||
);
|
||||
});
|
||||
}
|
||||
} while (bytesRead > 0);
|
||||
console.info('File copied successfully');
|
||||
} catch (error) {
|
||||
console.error('Copy file failed:', error);
|
||||
throw error;
|
||||
} finally {
|
||||
if (reader !== undefined) {
|
||||
fileIo.closeSync(reader);
|
||||
}
|
||||
if (writer !== undefined) {
|
||||
fileIo.closeSync(writer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async doFullPatch(params: DownloadTaskParams): Promise<void> {
|
||||
await this.downloadFile(params);
|
||||
await this.removeDirectory(params.unzipDirectory);
|
||||
@@ -243,7 +195,7 @@ export class DownloadTask {
|
||||
|
||||
const copies = obj.copies;
|
||||
for (const to in copies) {
|
||||
let from = copies[to];
|
||||
let from = copies[to].replace('resources/rawfile/', '');
|
||||
if (from === '') {
|
||||
from = to;
|
||||
}
|
||||
@@ -310,7 +262,6 @@ export class DownloadTask {
|
||||
|
||||
let foundDiff = false;
|
||||
let foundBundlePatch = false;
|
||||
const copyList: Map<string, Array<any>> = new Map();
|
||||
await zlib.decompressFile(params.targetFile, params.unzipDirectory);
|
||||
const zipFile = await this.processUnzippedFiles(params.unzipDirectory);
|
||||
for (const entry of zipFile.entries) {
|
||||
@@ -318,6 +269,13 @@ export class DownloadTask {
|
||||
|
||||
if (fn === '__diff.json') {
|
||||
foundDiff = true;
|
||||
|
||||
await fileIo
|
||||
.copyDir(params.originDirectory + '/', params.unzipDirectory + '/')
|
||||
.catch(error => {
|
||||
console.error('copy error:', error);
|
||||
});
|
||||
|
||||
let jsonContent = '';
|
||||
const bufferArray = new Uint8Array(entry.content);
|
||||
for (let i = 0; i < bufferArray.length; i++) {
|
||||
@@ -325,22 +283,23 @@ export class DownloadTask {
|
||||
}
|
||||
const obj = JSON.parse(jsonContent);
|
||||
|
||||
const copies = obj.copies;
|
||||
for (const to in copies) {
|
||||
let from = copies[to];
|
||||
if (from === '') {
|
||||
from = to;
|
||||
}
|
||||
|
||||
if (!copyList.has(from)) {
|
||||
copyList.set(from, []);
|
||||
}
|
||||
|
||||
const target = copyList.get(from);
|
||||
if (target) {
|
||||
const toFile = `${params.unzipDirectory}/${to}`;
|
||||
target.push(toFile);
|
||||
}
|
||||
const { copies, deletes } = obj;
|
||||
for (const [to, from] of Object.entries(copies)) {
|
||||
await fileIo
|
||||
.copyFile(
|
||||
`${params.originDirectory}/${from}`,
|
||||
`${params.unzipDirectory}/${to}`,
|
||||
)
|
||||
.catch(error => {
|
||||
console.error('copy error:', error);
|
||||
});
|
||||
}
|
||||
for (const fileToDelete of Object.keys(deletes)) {
|
||||
await fileIo
|
||||
.unlink(`${params.unzipDirectory}/${fileToDelete}`)
|
||||
.catch(error => {
|
||||
console.error('delete error:', error);
|
||||
});
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@@ -397,29 +356,14 @@ export class DownloadTask {
|
||||
copyList: Map<string, Array<string>>,
|
||||
): Promise<void> {
|
||||
try {
|
||||
const bundlePath = this.context.bundleCodeDir;
|
||||
const resourceManager = this.context.resourceManager;
|
||||
|
||||
const files = await fileIo.listFile(bundlePath);
|
||||
for (const file of files) {
|
||||
if (file === '.' || file === '..') {
|
||||
continue;
|
||||
}
|
||||
|
||||
const targets = copyList.get(file);
|
||||
if (targets) {
|
||||
let lastTarget: string | undefined;
|
||||
|
||||
for (const target of targets) {
|
||||
console.info(`Copying from resource ${file} to ${target}`);
|
||||
|
||||
if (lastTarget) {
|
||||
await this.copyFile(lastTarget, target);
|
||||
} else {
|
||||
const sourcePath = `${bundlePath}/${file}`;
|
||||
await this.copyFile(sourcePath, target);
|
||||
lastTarget = target;
|
||||
}
|
||||
}
|
||||
for (const [from, targets] of copyList.entries()) {
|
||||
const fromContent = await resourceManager.getRawFileContent(from);
|
||||
for (const target of targets) {
|
||||
const fileStream = fileIo.createStreamSync(target, 'w+');
|
||||
fileStream.writeSync(fromContent.buffer);
|
||||
fileStream.close();
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "react-native-update",
|
||||
"version": "10.35.3",
|
||||
"version": "10.35.4",
|
||||
"description": "react-native hot update",
|
||||
"main": "src/index",
|
||||
"scripts": {
|
||||
|
||||
Reference in New Issue
Block a user