Skip to content

fix: don't generate local hashes twice on full sync on android devices #3952

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 2, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions lib/services/livesync/android-device-livesync-service-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ export abstract class AndroidDeviceLiveSyncServiceBase extends DeviceLiveSyncSer
}

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

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

const localToDevicePathsToTransfer = await this.getLocalToDevicePathsToTransfer(deviceAppData, localToDevicePaths, options);
const localToDevicePathsToTransfer = await this.getLocalToDevicePathsToTransfer(deviceAppData, localToDevicePaths, currentHashes, options);
this.$logger.trace("Files to transfer: ", localToDevicePathsToTransfer);
await this.transferFilesOnDevice(deviceAppData, localToDevicePathsToTransfer);
return localToDevicePathsToTransfer;
}

private async getLocalToDevicePathsToTransfer(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[], options: ITransferFilesOptions): Promise<Mobile.ILocalToDevicePathData[]> {
private async getLocalToDevicePathsToTransfer(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[], currentHashes: IStringDictionary, options: ITransferFilesOptions): Promise<Mobile.ILocalToDevicePathData[]> {
if (options.force || !options.isFullSync) {
return localToDevicePaths;
}

const changedLocalToDevicePaths = await this.getChangedLocalToDevicePaths(deviceAppData.appIdentifier, localToDevicePaths);
const changedLocalToDevicePaths = await this.getChangedLocalToDevicePaths(deviceAppData.appIdentifier, localToDevicePaths, currentHashes);
return changedLocalToDevicePaths;
}

private async getChangedLocalToDevicePaths(appIdentifier: string, localToDevicePaths: Mobile.ILocalToDevicePathData[]): Promise<Mobile.ILocalToDevicePathData[]> {
private async getChangedLocalToDevicePaths(appIdentifier: string, localToDevicePaths: Mobile.ILocalToDevicePathData[], currentHashes: IStringDictionary): Promise<Mobile.ILocalToDevicePathData[]> {
const deviceHashService = this.getDeviceHashService(appIdentifier);
const currentHashes = await deviceHashService.generateHashesFromLocalToDevicePaths(localToDevicePaths);
const oldHashes = (await deviceHashService.getShasumsFromDevice()) || {};
const changedHashes = deviceHashService.getChangedShasums(oldHashes, currentHashes);
const changedFiles = _.keys(changedHashes);
const changedLocalToDevicePaths = localToDevicePaths.filter(localToDevicePathData => changedFiles.indexOf(localToDevicePathData.getLocalPath()) >= 0);
return changedLocalToDevicePaths;
}

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

private async updateHashesOnDevice(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[], projectData: IProjectData, liveSyncDeviceInfo: ILiveSyncDeviceInfo): Promise<IStringDictionary> {
private async updateHashesOnDevice(deviceAppData: Mobile.IDeviceAppData, currentHashes: IStringDictionary, projectData: IProjectData, liveSyncDeviceInfo: ILiveSyncDeviceInfo): Promise<IStringDictionary> {
const deviceHashService = this.getDeviceHashService(deviceAppData.appIdentifier);
const currentHashes = await deviceHashService.generateHashesFromLocalToDevicePaths(localToDevicePaths);
await deviceHashService.uploadHashFileToDevice(currentHashes);
return currentHashes;
}
Expand Down