Skip to content

Commit

Permalink
make livesync work with renamed files and folders (#3042)
Browse files Browse the repository at this point in the history
* added special check for file changes on Mac

* fix missing imports in tests

* add dir check, modified file check

* check isDirModified before anything else to save time

* updates after review

* bring back check for symlinks

* add check for modification in bot files and folders

* fixed lint
  • Loading branch information
Plamen5kov authored Aug 17, 2017
1 parent 4d5bcfb commit 1f46ca1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
29 changes: 22 additions & 7 deletions lib/services/project-changes-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,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;
}
Expand Down Expand Up @@ -218,20 +219,20 @@ 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)) {
return true;
}

let files = this.$fs.readDirectory(dir);
for (let file of files) {
let filePath = path.join(dir, file);
if (filePath === skipDir) {
continue;
}

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;
}
const fileStats = this.$fs.getFsStats(filePath);
let changed = this.isFileModified(fileStats, filePath);

if (changed) {
if (processFunc) {
Expand All @@ -250,10 +251,24 @@ export class ProjectChangesService implements IProjectChangesService {
return true;
}
}

}
return false;
}

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) {
if (path.basename(file) === "package.json") {
return true;
Expand Down
1 change: 0 additions & 1 deletion test/project-changes-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class ProjectChangesServiceTest extends BaseServiceTest {
this.injector.register("platformsData", PlatformsData);
this.injector.register("androidProjectService", {});
this.injector.register("iOSProjectService", {});

this.injector.register("fs", FileSystem);
this.injector.register("devicePlatformsConstants", {});
this.injector.register("devicePlatformsConstants", {});
Expand Down

0 comments on commit 1f46ca1

Please sign in to comment.