Skip to content

Commit 8e6fdea

Browse files
author
Fatme
authored
Merge pull request #3952 from NativeScript/fatme/android-hashes
fix: don't generate local hashes twice on full sync on android devices
2 parents 5c3f893 + 65d4019 commit 8e6fdea

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

lib/services/livesync/android-device-livesync-service-base.ts

+12-12
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@ export abstract class AndroidDeviceLiveSyncServiceBase extends DeviceLiveSyncSer
2727
}
2828

2929
public async transferFiles(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[], projectFilesPath: string, projectData: IProjectData, liveSyncDeviceInfo: ILiveSyncDeviceInfo, options: ITransferFilesOptions): Promise<Mobile.ILocalToDevicePathData[]> {
30-
const transferredFiles = await this.transferFilesCore(deviceAppData, localToDevicePaths, projectFilesPath, options);
31-
await this.updateHashes(deviceAppData, localToDevicePaths, projectData, liveSyncDeviceInfo);
30+
const deviceHashService = this.getDeviceHashService(deviceAppData.appIdentifier);
31+
const currentHashes = await deviceHashService.generateHashesFromLocalToDevicePaths(localToDevicePaths);
32+
const transferredFiles = await this.transferFilesCore(deviceAppData, localToDevicePaths, projectFilesPath, currentHashes, options);
33+
await this.updateHashes(deviceAppData, currentHashes, projectData, liveSyncDeviceInfo);
3234
return transferredFiles;
3335
}
3436

35-
private async transferFilesCore(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[], projectFilesPath: string, options: ITransferFilesOptions): Promise<Mobile.ILocalToDevicePathData[]> {
37+
private async transferFilesCore(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[], projectFilesPath: string, currentHashes: IStringDictionary, options: ITransferFilesOptions): Promise<Mobile.ILocalToDevicePathData[]> {
3638
if (options.force && options.isFullSync) {
3739
const hashFileDevicePath = this.getDeviceHashService(deviceAppData.appIdentifier).hashFileDevicePath;
3840
await this.device.fileSystem.deleteFile(hashFileDevicePath, deviceAppData.appIdentifier);
@@ -41,39 +43,37 @@ export abstract class AndroidDeviceLiveSyncServiceBase extends DeviceLiveSyncSer
4143
return localToDevicePaths;
4244
}
4345

44-
const localToDevicePathsToTransfer = await this.getLocalToDevicePathsToTransfer(deviceAppData, localToDevicePaths, options);
46+
const localToDevicePathsToTransfer = await this.getLocalToDevicePathsToTransfer(deviceAppData, localToDevicePaths, currentHashes, options);
4547
this.$logger.trace("Files to transfer: ", localToDevicePathsToTransfer);
4648
await this.transferFilesOnDevice(deviceAppData, localToDevicePathsToTransfer);
4749
return localToDevicePathsToTransfer;
4850
}
4951

50-
private async getLocalToDevicePathsToTransfer(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[], options: ITransferFilesOptions): Promise<Mobile.ILocalToDevicePathData[]> {
52+
private async getLocalToDevicePathsToTransfer(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[], currentHashes: IStringDictionary, options: ITransferFilesOptions): Promise<Mobile.ILocalToDevicePathData[]> {
5153
if (options.force || !options.isFullSync) {
5254
return localToDevicePaths;
5355
}
5456

55-
const changedLocalToDevicePaths = await this.getChangedLocalToDevicePaths(deviceAppData.appIdentifier, localToDevicePaths);
57+
const changedLocalToDevicePaths = await this.getChangedLocalToDevicePaths(deviceAppData.appIdentifier, localToDevicePaths, currentHashes);
5658
return changedLocalToDevicePaths;
5759
}
5860

59-
private async getChangedLocalToDevicePaths(appIdentifier: string, localToDevicePaths: Mobile.ILocalToDevicePathData[]): Promise<Mobile.ILocalToDevicePathData[]> {
61+
private async getChangedLocalToDevicePaths(appIdentifier: string, localToDevicePaths: Mobile.ILocalToDevicePathData[], currentHashes: IStringDictionary): Promise<Mobile.ILocalToDevicePathData[]> {
6062
const deviceHashService = this.getDeviceHashService(appIdentifier);
61-
const currentHashes = await deviceHashService.generateHashesFromLocalToDevicePaths(localToDevicePaths);
6263
const oldHashes = (await deviceHashService.getShasumsFromDevice()) || {};
6364
const changedHashes = deviceHashService.getChangedShasums(oldHashes, currentHashes);
6465
const changedFiles = _.keys(changedHashes);
6566
const changedLocalToDevicePaths = localToDevicePaths.filter(localToDevicePathData => changedFiles.indexOf(localToDevicePathData.getLocalPath()) >= 0);
6667
return changedLocalToDevicePaths;
6768
}
6869

69-
private async updateHashes(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[], projectData: IProjectData, liveSyncDeviceInfo: ILiveSyncDeviceInfo): Promise<void> {
70-
const hashes = await this.updateHashesOnDevice(deviceAppData, localToDevicePaths, projectData, liveSyncDeviceInfo);
70+
private async updateHashes(deviceAppData: Mobile.IDeviceAppData, currentHashes: IStringDictionary, projectData: IProjectData, liveSyncDeviceInfo: ILiveSyncDeviceInfo): Promise<void> {
71+
const hashes = await this.updateHashesOnDevice(deviceAppData, currentHashes, projectData, liveSyncDeviceInfo);
7172
this.updateLocalHashes(hashes, deviceAppData, projectData, liveSyncDeviceInfo);
7273
}
7374

74-
private async updateHashesOnDevice(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[], projectData: IProjectData, liveSyncDeviceInfo: ILiveSyncDeviceInfo): Promise<IStringDictionary> {
75+
private async updateHashesOnDevice(deviceAppData: Mobile.IDeviceAppData, currentHashes: IStringDictionary, projectData: IProjectData, liveSyncDeviceInfo: ILiveSyncDeviceInfo): Promise<IStringDictionary> {
7576
const deviceHashService = this.getDeviceHashService(deviceAppData.appIdentifier);
76-
const currentHashes = await deviceHashService.generateHashesFromLocalToDevicePaths(localToDevicePaths);
7777
await deviceHashService.uploadHashFileToDevice(currentHashes);
7878
return currentHashes;
7979
}

0 commit comments

Comments
 (0)