Skip to content

fix(livesync): respect rapid file changes #3410

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
Mar 1, 2018
Merged
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions lib/services/livesync/platform-livesync-service-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export abstract class PlatformLiveSyncServiceBase {
const syncInfo = _.merge<IFullSyncInfo>({ device, watch: true }, liveSyncInfo);
const deviceAppData = await this.getAppData(syncInfo);

const modifiedLocalToDevicePaths: Mobile.ILocalToDevicePathData[] = [];
let modifiedLocalToDevicePaths: Mobile.ILocalToDevicePathData[] = [];
if (liveSyncInfo.filesToSync.length) {
const filesToSync = liveSyncInfo.filesToSync;
const mappedFiles = _.map(filesToSync, filePath => this.$projectFilesProvider.mapFilePath(filePath, device.deviceInfo.platform, projectData));
Expand All @@ -77,7 +77,7 @@ export abstract class PlatformLiveSyncServiceBase {
const localToDevicePaths = await this.$projectFilesManager.createLocalToDevicePaths(deviceAppData,
projectFilesPath, existingFiles, []);
modifiedLocalToDevicePaths.push(...localToDevicePaths);
await this.transferFiles(deviceAppData, localToDevicePaths, projectFilesPath, false);
modifiedLocalToDevicePaths = await this.transferFiles(deviceAppData, localToDevicePaths, projectFilesPath, false);
}
}

Expand Down Expand Up @@ -105,11 +105,11 @@ export abstract class PlatformLiveSyncServiceBase {
}

protected async transferFiles(deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[], projectFilesPath: string, isFullSync: boolean): Promise<Mobile.ILocalToDevicePathData[]> {
let transferredFiles = localToDevicePaths;
let transferredFiles: Mobile.ILocalToDevicePathData[] = [];
if (isFullSync) {
transferredFiles = await deviceAppData.device.fileSystem.transferDirectory(deviceAppData, localToDevicePaths, projectFilesPath);
} else {
await deviceAppData.device.fileSystem.transferFiles(deviceAppData, localToDevicePaths);
transferredFiles = await deviceAppData.device.fileSystem.transferFiles(deviceAppData, localToDevicePaths);
}

this.logFilesSyncInformation(transferredFiles, "Successfully transferred %s.", this.$logger.info);
Expand Down
6 changes: 5 additions & 1 deletion lib/services/prepare-platform-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,13 @@ export class PreparePlatformService {
beforeCopyAction: sourceFiles => {
this.$xmlValidator.validateXmlFiles(sourceFiles);
},
filesToSync: copyAppFilesData.filesToSync,
filesToRemove: copyAppFilesData.filesToRemove
};
// TODO: consider passing filesToSync in appUpdaterOptions
// this would currently lead to the following problem: imagine changing two files rapidly one after the other (transpilation for example)
// the first file would trigger the whole LiveSync process and the second will be queued
// after the first LiveSync is done the .nsprepare file is written and the second file is later on wrongly assumed as having been prepared
// because .nsprepare was written after both file changes
appUpdater.updateApp(appUpdaterOptions, copyAppFilesData.projectData);
}
}