From 94eeebb57e3a5db0bf210d31d2cbaa835c92976d Mon Sep 17 00:00:00 2001 From: plamen5kov Date: Wed, 9 Aug 2017 10:01:56 +0300 Subject: [PATCH 1/8] added special check for file changes on Mac --- lib/services/project-changes-service.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/services/project-changes-service.ts b/lib/services/project-changes-service.ts index 5fbfa2a892..ab5ce7848d 100644 --- a/lib/services/project-changes-service.ts +++ b/lib/services/project-changes-service.ts @@ -47,7 +47,8 @@ export class ProjectChangesService implements IProjectChangesService { constructor( private $platformsData: IPlatformsData, private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants, - private $fs: IFileSystem) { + private $fs: IFileSystem, + private $hostInfo: IHostInfo) { } public get currentChanges(): IProjectChangesInfo { @@ -227,10 +228,15 @@ export class ProjectChangesService implements IProjectChangesService { let fileStats = this.$fs.getFsStats(filePath); - let changed = fileStats.mtime.getTime() >= this._outputProjectMtime || fileStats.ctime.getTime() >= this._outputProjectCTime; - if (!changed) { - let lFileStats = this.$fs.getLsStats(filePath); - changed = lFileStats.mtime.getTime() >= this._outputProjectMtime || lFileStats.ctime.getTime() >= this._outputProjectCTime; + let changed = fileStats.mtime.getTime() > this._outputProjectMtime || + fileStats.ctime.getTime() >= this._outputProjectCTime; + + if (this.$hostInfo.isDarwin && !fileStats.isDirectory() && !changed) { + const parentDirPath: string = path.dirname(filePath); + const parentDirStat = this.$fs.getFsStats(parentDirPath); + + changed = parentDirStat.mtime.getTime() > this._outputProjectMtime || + parentDirStat.ctime.getTime() >= this._outputProjectCTime; } if (changed) { From d7f06d28aab388de9ec7c712404bae39d1855da1 Mon Sep 17 00:00:00 2001 From: plamen5kov Date: Wed, 9 Aug 2017 10:38:25 +0300 Subject: [PATCH 2/8] fix missing imports in tests --- test/project-changes-service.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/project-changes-service.ts b/test/project-changes-service.ts index 3593400340..ee9b2082c1 100644 --- a/test/project-changes-service.ts +++ b/test/project-changes-service.ts @@ -6,6 +6,8 @@ import { PlatformsData } from "../lib/platforms-data"; import { ProjectChangesService } from "../lib/services/project-changes-service"; import * as Constants from "../lib/constants"; import { FileSystem } from "../lib/common/file-system"; +import * as HostInfoLib from "../lib/common/host-info"; +import * as ErrorsLib from "../lib/common/errors"; // start tracking temporary folders/files temp.track(); @@ -26,7 +28,8 @@ class ProjectChangesServiceTest extends BaseServiceTest { this.injector.register("platformsData", PlatformsData); this.injector.register("androidProjectService", {}); this.injector.register("iOSProjectService", {}); - + this.injector.register("hostInfo", HostInfoLib.HostInfo); + this.injector.register("errors", ErrorsLib.Errors); this.injector.register("fs", FileSystem); this.injector.register("devicePlatformsConstants", {}); this.injector.register("devicePlatformsConstants", {}); From 3692d8b2a2fa25d6086530ccf09ceecccba5da2b Mon Sep 17 00:00:00 2001 From: plamen5kov Date: Thu, 10 Aug 2017 10:46:40 +0300 Subject: [PATCH 3/8] add dir check, modified file check --- lib/services/project-changes-service.ts | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/lib/services/project-changes-service.ts b/lib/services/project-changes-service.ts index ab5ce7848d..47aa9768cc 100644 --- a/lib/services/project-changes-service.ts +++ b/lib/services/project-changes-service.ts @@ -47,8 +47,7 @@ export class ProjectChangesService implements IProjectChangesService { constructor( private $platformsData: IPlatformsData, private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants, - private $fs: IFileSystem, - private $hostInfo: IHostInfo) { + private $fs: IFileSystem) { } public get currentChanges(): IProjectChangesInfo { @@ -69,6 +68,7 @@ export class ProjectChangesService implements IProjectChangesService { path.join(projectData.projectDir, NODE_MODULES_FOLDER_NAME, "tns-ios-inspector"), projectData, this.fileChangeRequiresBuild); + if (this._newFiles > 0) { this._changesInfo.modulesChanged = true; } @@ -231,14 +231,6 @@ export class ProjectChangesService implements IProjectChangesService { let changed = fileStats.mtime.getTime() > this._outputProjectMtime || fileStats.ctime.getTime() >= this._outputProjectCTime; - if (this.$hostInfo.isDarwin && !fileStats.isDirectory() && !changed) { - const parentDirPath: string = path.dirname(filePath); - const parentDirStat = this.$fs.getFsStats(parentDirPath); - - changed = parentDirStat.mtime.getTime() > this._outputProjectMtime || - parentDirStat.ctime.getTime() >= this._outputProjectCTime; - } - if (changed) { if (processFunc) { this._newFiles++; @@ -252,14 +244,25 @@ export class ProjectChangesService implements IProjectChangesService { } if (fileStats.isDirectory()) { + if (this.isDirectoryModified(dir)) { + return true; + } + if (this.containsNewerFiles(filePath, skipDir, projectData, processFunc)) { return true; } } + } return false; } + private isDirectoryModified(dirPath: string): boolean { + const dirPathStat = this.$fs.getFsStats(dirPath); + return dirPathStat.mtime.getTime() > this._outputProjectMtime || + dirPathStat.ctime.getTime() >= this._outputProjectCTime; + } + private fileChangeRequiresBuild(file: string, projectData: IProjectData) { if (path.basename(file) === "package.json") { return true; From c861d06224e1f675d8fe1533eaa0fb38725f1bf6 Mon Sep 17 00:00:00 2001 From: plamen5kov Date: Thu, 10 Aug 2017 10:56:48 +0300 Subject: [PATCH 4/8] check isDirModified before anything else to save time --- lib/services/project-changes-service.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/services/project-changes-service.ts b/lib/services/project-changes-service.ts index 47aa9768cc..f4a742fcd8 100644 --- a/lib/services/project-changes-service.ts +++ b/lib/services/project-changes-service.ts @@ -219,6 +219,10 @@ export class ProjectChangesService implements IProjectChangesService { } private containsNewerFiles(dir: string, skipDir: string, projectData: IProjectData, processFunc?: (filePath: string, projectData: IProjectData) => boolean): boolean { + if (this.isDirectoryModified(dir)) { + return true; + } + let files = this.$fs.readDirectory(dir); for (let file of files) { let filePath = path.join(dir, file); @@ -244,10 +248,6 @@ export class ProjectChangesService implements IProjectChangesService { } if (fileStats.isDirectory()) { - if (this.isDirectoryModified(dir)) { - return true; - } - if (this.containsNewerFiles(filePath, skipDir, projectData, processFunc)) { return true; } From 3b8cb028d7ca9be3a10042e12d9d020f7957527d Mon Sep 17 00:00:00 2001 From: plamen5kov Date: Fri, 11 Aug 2017 14:36:42 +0300 Subject: [PATCH 5/8] updates after review --- lib/services/project-changes-service.ts | 16 +++++++--------- test/project-changes-service.ts | 4 ---- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/lib/services/project-changes-service.ts b/lib/services/project-changes-service.ts index f4a742fcd8..f55f60c618 100644 --- a/lib/services/project-changes-service.ts +++ b/lib/services/project-changes-service.ts @@ -219,7 +219,8 @@ export class ProjectChangesService implements IProjectChangesService { } private containsNewerFiles(dir: string, skipDir: string, projectData: IProjectData, processFunc?: (filePath: string, projectData: IProjectData) => boolean): boolean { - if (this.isDirectoryModified(dir)) { + const dirFileStat = this.$fs.getFsStats(dir); + if (this.isFileModified(dirFileStat)) { return true; } @@ -230,10 +231,8 @@ export class ProjectChangesService implements IProjectChangesService { continue; } - let fileStats = this.$fs.getFsStats(filePath); - - let changed = fileStats.mtime.getTime() > this._outputProjectMtime || - fileStats.ctime.getTime() >= this._outputProjectCTime; + const fileStats = this.$fs.getFsStats(filePath); + let changed = this.isFileModified(fileStats); if (changed) { if (processFunc) { @@ -257,10 +256,9 @@ export class ProjectChangesService implements IProjectChangesService { return false; } - private isDirectoryModified(dirPath: string): boolean { - const dirPathStat = this.$fs.getFsStats(dirPath); - return dirPathStat.mtime.getTime() > this._outputProjectMtime || - dirPathStat.ctime.getTime() >= this._outputProjectCTime; + private isFileModified(filePathStat: IFsStats): boolean { + return filePathStat.mtime.getTime() >= this._outputProjectMtime || + filePathStat.ctime.getTime() >= this._outputProjectCTime; } private fileChangeRequiresBuild(file: string, projectData: IProjectData) { diff --git a/test/project-changes-service.ts b/test/project-changes-service.ts index ee9b2082c1..cc29656ebd 100644 --- a/test/project-changes-service.ts +++ b/test/project-changes-service.ts @@ -6,8 +6,6 @@ import { PlatformsData } from "../lib/platforms-data"; import { ProjectChangesService } from "../lib/services/project-changes-service"; import * as Constants from "../lib/constants"; import { FileSystem } from "../lib/common/file-system"; -import * as HostInfoLib from "../lib/common/host-info"; -import * as ErrorsLib from "../lib/common/errors"; // start tracking temporary folders/files temp.track(); @@ -28,8 +26,6 @@ class ProjectChangesServiceTest extends BaseServiceTest { this.injector.register("platformsData", PlatformsData); this.injector.register("androidProjectService", {}); this.injector.register("iOSProjectService", {}); - this.injector.register("hostInfo", HostInfoLib.HostInfo); - this.injector.register("errors", ErrorsLib.Errors); this.injector.register("fs", FileSystem); this.injector.register("devicePlatformsConstants", {}); this.injector.register("devicePlatformsConstants", {}); From 3c2713cee044a9a45a52248140f044de8f874b7c Mon Sep 17 00:00:00 2001 From: plamen5kov Date: Mon, 14 Aug 2017 10:42:41 +0300 Subject: [PATCH 6/8] bring back check for symlinks --- lib/services/project-changes-service.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/services/project-changes-service.ts b/lib/services/project-changes-service.ts index f55f60c618..5728f0a675 100644 --- a/lib/services/project-changes-service.ts +++ b/lib/services/project-changes-service.ts @@ -233,6 +233,10 @@ export class ProjectChangesService implements IProjectChangesService { const fileStats = this.$fs.getFsStats(filePath); let changed = this.isFileModified(fileStats); + if (!changed) { + let lFileStats = this.$fs.getLsStats(filePath); + changed = this.isFileModified(lFileStats); + } if (changed) { if (processFunc) { From 9020a8648f41416cec30c7c45456033c33b96db7 Mon Sep 17 00:00:00 2001 From: plamen5kov Date: Mon, 14 Aug 2017 11:35:27 +0300 Subject: [PATCH 7/8] add check for modification in bot files and folders --- lib/services/project-changes-service.ts | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/services/project-changes-service.ts b/lib/services/project-changes-service.ts index 5728f0a675..c20f27fe0e 100644 --- a/lib/services/project-changes-service.ts +++ b/lib/services/project-changes-service.ts @@ -220,7 +220,7 @@ export class ProjectChangesService implements IProjectChangesService { private containsNewerFiles(dir: string, skipDir: string, projectData: IProjectData, processFunc?: (filePath: string, projectData: IProjectData) => boolean): boolean { const dirFileStat = this.$fs.getFsStats(dir); - if (this.isFileModified(dirFileStat)) { + if(this.isFileModified(dirFileStat, dir)) { return true; } @@ -232,11 +232,7 @@ export class ProjectChangesService implements IProjectChangesService { } const fileStats = this.$fs.getFsStats(filePath); - let changed = this.isFileModified(fileStats); - if (!changed) { - let lFileStats = this.$fs.getLsStats(filePath); - changed = this.isFileModified(lFileStats); - } + let changed = this.isFileModified(fileStats, filePath); if (changed) { if (processFunc) { @@ -260,9 +256,17 @@ export class ProjectChangesService implements IProjectChangesService { return false; } - private isFileModified(filePathStat: IFsStats): boolean { - return filePathStat.mtime.getTime() >= this._outputProjectMtime || + private isFileModified(filePathStat: IFsStats, filePath: string): boolean { + let changed = filePathStat.mtime.getTime() >= this._outputProjectMtime || filePathStat.ctime.getTime() >= this._outputProjectCTime; + + if (!changed) { + let lFileStats = this.$fs.getLsStats(filePath); + changed = lFileStats.mtime.getTime() >= this._outputProjectMtime || + lFileStats.ctime.getTime() >= this._outputProjectCTime; + } + + return changed; } private fileChangeRequiresBuild(file: string, projectData: IProjectData) { From f99697d33a88d327002eda615ef64669457b5ee8 Mon Sep 17 00:00:00 2001 From: plamen5kov Date: Mon, 14 Aug 2017 17:01:23 +0300 Subject: [PATCH 8/8] fixed lint --- lib/services/project-changes-service.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/services/project-changes-service.ts b/lib/services/project-changes-service.ts index c20f27fe0e..08c87a3df5 100644 --- a/lib/services/project-changes-service.ts +++ b/lib/services/project-changes-service.ts @@ -220,7 +220,7 @@ export class ProjectChangesService implements IProjectChangesService { private containsNewerFiles(dir: string, skipDir: string, projectData: IProjectData, processFunc?: (filePath: string, projectData: IProjectData) => boolean): boolean { const dirFileStat = this.$fs.getFsStats(dir); - if(this.isFileModified(dirFileStat, dir)) { + if (this.isFileModified(dirFileStat, dir)) { return true; } @@ -258,12 +258,12 @@ export class ProjectChangesService implements IProjectChangesService { private isFileModified(filePathStat: IFsStats, filePath: string): boolean { let changed = filePathStat.mtime.getTime() >= this._outputProjectMtime || - filePathStat.ctime.getTime() >= this._outputProjectCTime; + filePathStat.ctime.getTime() >= this._outputProjectCTime; if (!changed) { let lFileStats = this.$fs.getLsStats(filePath); changed = lFileStats.mtime.getTime() >= this._outputProjectMtime || - lFileStats.ctime.getTime() >= this._outputProjectCTime; + lFileStats.ctime.getTime() >= this._outputProjectCTime; } return changed;