Skip to content

Fix livesync/run issue #2508

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 2 commits into from
Feb 9, 2017
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
1 change: 1 addition & 0 deletions lib/services/livesync/livesync-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ class LiveSyncService implements ILiveSyncService {
fiberBootstrap.run(() => {
that.$dispatcher.dispatch(() => (() => {
try {
that.$logger.trace(`Event '${event}' triggered for path: '${filePath}'`);
filePath = path.join(syncWorkingDirectory, filePath);
for (let i = 0; i < onChangedActions.length; i++) {
onChangedActions[i](event, filePath, that.$dispatcher);
Expand Down
38 changes: 27 additions & 11 deletions lib/services/livesync/platform-livesync-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ export abstract class PlatformLiveSyncServiceBase implements IPlatformLiveSyncSe
}

if (postAction) {
this.finishLivesync(deviceAppData).wait();
return postAction(deviceAppData).wait();
this.finishLivesync(deviceAppData).wait();
return postAction(deviceAppData).wait();
}

this.refreshApplication(deviceAppData, localToDevicePaths, true).wait();
Expand All @@ -65,9 +65,9 @@ export abstract class PlatformLiveSyncServiceBase implements IPlatformLiveSyncSe
return;
}

if (event === "add" || event === "change") {
if (event === "add" || event === "addDir" || event === "change") {
this.batchSync(filePath, dispatcher, afterFileSyncAction);
} else if (event === "unlink") {
} else if (event === "unlink" || event === "unlinkDir") {
this.syncRemovedFile(filePath, afterFileSyncAction).wait();
}
}
Expand Down Expand Up @@ -133,7 +133,7 @@ export abstract class PlatformLiveSyncServiceBase implements IPlatformLiveSyncSe
try {
for (let platform in this.batch) {
let batch = this.batch[platform];
batch.syncFiles(((filesToSync:string[]) => {
batch.syncFiles(((filesToSync: string[]) => {
this.$platformService.preparePlatform(this.liveSyncData.platform).wait();
let canExecute = this.getCanExecuteAction(this.liveSyncData.platform, this.liveSyncData.appIdentifier);
let deviceFileAction = (deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[]) => this.transferFiles(deviceAppData, localToDevicePaths, this.liveSyncData.projectFilesPath, !filePath);
Expand All @@ -142,7 +142,7 @@ export abstract class PlatformLiveSyncServiceBase implements IPlatformLiveSyncSe
}).future<void>()).wait();
}
} catch (err) {
this.$logger.warn(`Unable to sync files. Error is:`, err.message);
this.$logger.warn(`Unable to sync files. Error is:`, err.message);
}
}).future<void>()());
}).future<void>()();
Expand Down Expand Up @@ -173,8 +173,8 @@ export abstract class PlatformLiveSyncServiceBase implements IPlatformLiveSyncSe
afterFileSyncAction: (deviceAppData: Mobile.IDeviceAppData, localToDevicePaths: Mobile.ILocalToDevicePathData[]) => IFuture<void>): (device: Mobile.IDevice) => IFuture<void> {
let action = (device: Mobile.IDevice): IFuture<void> => {
return (() => {
let deviceAppData:Mobile.IDeviceAppData = null;
let localToDevicePaths:Mobile.ILocalToDevicePathData[] = null;
let deviceAppData: Mobile.IDeviceAppData = null;
let localToDevicePaths: Mobile.ILocalToDevicePathData[] = null;
let isFullSync = false;
if (this.$options.clean || this.$projectChangesService.currentChanges.changesRequireBuild) {
let buildConfig: IBuildConfig = { buildForDevice: !device.isEmulator };
Expand All @@ -187,13 +187,29 @@ export abstract class PlatformLiveSyncServiceBase implements IPlatformLiveSyncSe
isFullSync = true;
} else {
deviceAppData = this.$deviceAppDataFactory.create(this.liveSyncData.appIdentifier, this.$mobileHelper.normalizePlatformName(this.liveSyncData.platform), device);
let mappedFiles = filesToSync.map((file: string) => this.$projectFilesProvider.mapFilePath(file, device.deviceInfo.platform));
localToDevicePaths = this.$projectFilesManager.createLocalToDevicePaths(deviceAppData, this.liveSyncData.projectFilesPath, mappedFiles, this.liveSyncData.excludedProjectDirsAndFiles);

const mappedFiles = filesToSync.map((file: string) => this.$projectFilesProvider.mapFilePath(file, device.deviceInfo.platform));

// Some plugins modify platforms dir on afterPrepare (check nativescript-dev-sass) - we want to sync only existing file.
const existingFiles = mappedFiles.filter(m => this.$fs.exists(m));

this.$logger.trace("Will execute livesync for files: ", existingFiles);

const skippedFiles = _.difference(mappedFiles, existingFiles);

if (skippedFiles.length) {
this.$logger.trace("The following files will not be synced as they do not exist:", skippedFiles);
}

localToDevicePaths = this.$projectFilesManager.createLocalToDevicePaths(deviceAppData, this.liveSyncData.projectFilesPath, existingFiles, this.liveSyncData.excludedProjectDirsAndFiles);

fileSyncAction(deviceAppData, localToDevicePaths).wait();
}

if (!afterFileSyncAction) {
this.refreshApplication(deviceAppData, localToDevicePaths, isFullSync).wait();
}

device.fileSystem.putFile(this.$projectChangesService.getPrepareInfoFilePath(device.deviceInfo.platform), this.getLiveSyncInfoFilePath(deviceAppData), this.liveSyncData.appIdentifier).wait();
this.finishLivesync(deviceAppData).wait();
if (afterFileSyncAction) {
Expand All @@ -213,7 +229,7 @@ export abstract class PlatformLiveSyncServiceBase implements IPlatformLiveSyncSe
let remoteLivesyncInfo: IPrepareInfo = JSON.parse(fileText);
let localPrepareInfo = this.$projectChangesService.getPrepareInfo(platform);
return remoteLivesyncInfo.time !== localPrepareInfo.time;
} catch(e) {
} catch (e) {
return true;
}
}
Expand Down
3 changes: 3 additions & 0 deletions lib/services/platform-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ export class PlatformService implements IPlatformService {

this.ensurePlatformInstalled(platform).wait();
let changesInfo = this.$projectChangesService.checkForChanges(platform);

this.$logger.trace("Changes info in prepare platform:", changesInfo);

if (changesInfo.hasChanges) {
// android build artifacts need to be cleaned up when switching from release to debug builds
if (platform.toLowerCase() === "android") {
Expand Down
9 changes: 7 additions & 2 deletions lib/services/project-changes-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,16 @@ export class ProjectChangesService implements IProjectChangesService {
if (filePath === skipDir) {
continue;
}

let fileStats = this.$fs.getFsStats(filePath);
let changed = fileStats.mtime.getTime() > this._outputProjectMtime;

let changed = fileStats.mtime.getTime() > this._outputProjectMtime || fileStats.ctime.getTime() > this._outputProjectMtime;

if (!changed) {
let lFileStats = this.$fs.getLsStats(filePath);
changed = lFileStats.mtime.getTime() > this._outputProjectMtime;
changed = lFileStats.mtime.getTime() > this._outputProjectMtime || lFileStats.ctime.getTime() > this._outputProjectMtime;
}

if (changed) {
if (processFunc) {
this._newFiles ++;
Expand All @@ -193,6 +197,7 @@ export class ProjectChangesService implements IProjectChangesService {
return true;
}
}

if (fileStats.isDirectory()) {
if (this.containsNewerFiles(filePath, skipDir, processFunc)) {
return true;
Expand Down