react-native-update 10.35.3 → 10.35.4
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.
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import http from '@ohos.net.http';
|
|
2
2
|
import fileIo from '@ohos.file.fs';
|
|
3
3
|
import common from '@ohos.app.ability.common';
|
|
4
|
-
import {
|
|
5
|
-
import { zlib, BusinessError } from '@kit.BasicServicesKit';
|
|
4
|
+
import { zlib } from '@kit.BasicServicesKit';
|
|
6
5
|
import { EventHub } from './EventHub';
|
|
7
6
|
import { DownloadTaskParams } from './DownloadTaskParams';
|
|
8
7
|
import Pushy from 'librnupdate.so';
|
|
@@ -128,53 +127,6 @@ export class DownloadTask {
|
|
|
128
127
|
});
|
|
129
128
|
}
|
|
130
129
|
|
|
131
|
-
private async copyFile(from: string, to: string): Promise<void> {
|
|
132
|
-
let reader;
|
|
133
|
-
let writer;
|
|
134
|
-
try {
|
|
135
|
-
reader = fileIo.openSync(from, fileIo.OpenMode.READ_ONLY);
|
|
136
|
-
writer = fileIo.openSync(
|
|
137
|
-
to,
|
|
138
|
-
fileIo.OpenMode.CREATE | fileIo.OpenMode.WRITE_ONLY,
|
|
139
|
-
);
|
|
140
|
-
const arrayBuffer = new ArrayBuffer(4096);
|
|
141
|
-
let bytesRead: number;
|
|
142
|
-
do {
|
|
143
|
-
bytesRead = await fileIo
|
|
144
|
-
.read(reader.fd, arrayBuffer)
|
|
145
|
-
.catch((err: BusinessError) => {
|
|
146
|
-
throw Error(
|
|
147
|
-
`Error reading file: ${err.message}, code: ${err.code}`,
|
|
148
|
-
);
|
|
149
|
-
});
|
|
150
|
-
if (bytesRead > 0) {
|
|
151
|
-
const buf = buffer.from(arrayBuffer, 0, bytesRead);
|
|
152
|
-
await fileIo
|
|
153
|
-
.write(writer.fd, buf.buffer, {
|
|
154
|
-
offset: 0,
|
|
155
|
-
length: bytesRead,
|
|
156
|
-
})
|
|
157
|
-
.catch((err: BusinessError) => {
|
|
158
|
-
throw Error(
|
|
159
|
-
`Error writing file: ${err.message}, code: ${err.code}`,
|
|
160
|
-
);
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
} while (bytesRead > 0);
|
|
164
|
-
console.info('File copied successfully');
|
|
165
|
-
} catch (error) {
|
|
166
|
-
console.error('Copy file failed:', error);
|
|
167
|
-
throw error;
|
|
168
|
-
} finally {
|
|
169
|
-
if (reader !== undefined) {
|
|
170
|
-
fileIo.closeSync(reader);
|
|
171
|
-
}
|
|
172
|
-
if (writer !== undefined) {
|
|
173
|
-
fileIo.closeSync(writer);
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
130
|
private async doFullPatch(params: DownloadTaskParams): Promise<void> {
|
|
179
131
|
await this.downloadFile(params);
|
|
180
132
|
await this.removeDirectory(params.unzipDirectory);
|
|
@@ -243,7 +195,7 @@ export class DownloadTask {
|
|
|
243
195
|
|
|
244
196
|
const copies = obj.copies;
|
|
245
197
|
for (const to in copies) {
|
|
246
|
-
let from = copies[to];
|
|
198
|
+
let from = copies[to].replace('resources/rawfile/', '');
|
|
247
199
|
if (from === '') {
|
|
248
200
|
from = to;
|
|
249
201
|
}
|
|
@@ -310,7 +262,6 @@ export class DownloadTask {
|
|
|
310
262
|
|
|
311
263
|
let foundDiff = false;
|
|
312
264
|
let foundBundlePatch = false;
|
|
313
|
-
const copyList: Map<string, Array<any>> = new Map();
|
|
314
265
|
await zlib.decompressFile(params.targetFile, params.unzipDirectory);
|
|
315
266
|
const zipFile = await this.processUnzippedFiles(params.unzipDirectory);
|
|
316
267
|
for (const entry of zipFile.entries) {
|
|
@@ -318,6 +269,13 @@ export class DownloadTask {
|
|
|
318
269
|
|
|
319
270
|
if (fn === '__diff.json') {
|
|
320
271
|
foundDiff = true;
|
|
272
|
+
|
|
273
|
+
await fileIo
|
|
274
|
+
.copyDir(params.originDirectory + '/', params.unzipDirectory + '/')
|
|
275
|
+
.catch(error => {
|
|
276
|
+
console.error('copy error:', error);
|
|
277
|
+
});
|
|
278
|
+
|
|
321
279
|
let jsonContent = '';
|
|
322
280
|
const bufferArray = new Uint8Array(entry.content);
|
|
323
281
|
for (let i = 0; i < bufferArray.length; i++) {
|
|
@@ -325,22 +283,23 @@ export class DownloadTask {
|
|
|
325
283
|
}
|
|
326
284
|
const obj = JSON.parse(jsonContent);
|
|
327
285
|
|
|
328
|
-
const copies = obj
|
|
329
|
-
for (const to
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
286
|
+
const { copies, deletes } = obj;
|
|
287
|
+
for (const [to, from] of Object.entries(copies)) {
|
|
288
|
+
await fileIo
|
|
289
|
+
.copyFile(
|
|
290
|
+
`${params.originDirectory}/${from}`,
|
|
291
|
+
`${params.unzipDirectory}/${to}`,
|
|
292
|
+
)
|
|
293
|
+
.catch(error => {
|
|
294
|
+
console.error('copy error:', error);
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
for (const fileToDelete of Object.keys(deletes)) {
|
|
298
|
+
await fileIo
|
|
299
|
+
.unlink(`${params.unzipDirectory}/${fileToDelete}`)
|
|
300
|
+
.catch(error => {
|
|
301
|
+
console.error('delete error:', error);
|
|
302
|
+
});
|
|
344
303
|
}
|
|
345
304
|
continue;
|
|
346
305
|
}
|
|
@@ -397,29 +356,14 @@ export class DownloadTask {
|
|
|
397
356
|
copyList: Map<string, Array<string>>,
|
|
398
357
|
): Promise<void> {
|
|
399
358
|
try {
|
|
400
|
-
const
|
|
401
|
-
|
|
402
|
-
const
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
const targets = copyList.get(file);
|
|
409
|
-
if (targets) {
|
|
410
|
-
let lastTarget: string | undefined;
|
|
411
|
-
|
|
412
|
-
for (const target of targets) {
|
|
413
|
-
console.info(`Copying from resource ${file} to ${target}`);
|
|
414
|
-
|
|
415
|
-
if (lastTarget) {
|
|
416
|
-
await this.copyFile(lastTarget, target);
|
|
417
|
-
} else {
|
|
418
|
-
const sourcePath = `${bundlePath}/${file}`;
|
|
419
|
-
await this.copyFile(sourcePath, target);
|
|
420
|
-
lastTarget = target;
|
|
421
|
-
}
|
|
422
|
-
}
|
|
359
|
+
const resourceManager = this.context.resourceManager;
|
|
360
|
+
|
|
361
|
+
for (const [from, targets] of copyList.entries()) {
|
|
362
|
+
const fromContent = await resourceManager.getRawFileContent(from);
|
|
363
|
+
for (const target of targets) {
|
|
364
|
+
const fileStream = fileIo.createStreamSync(target, 'w+');
|
|
365
|
+
fileStream.writeSync(fromContent.buffer);
|
|
366
|
+
fileStream.close();
|
|
423
367
|
}
|
|
424
368
|
}
|
|
425
369
|
} catch (error) {
|