Skip to content

make livesync work with renamed files and folders #3042

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 8 commits into from
Aug 17, 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
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if the lstat of the dir has been changed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well spotted, I don't know how I missed that!

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the fileStats object is not used anywhere outside of the isFileModified method. So I believe its place is inside it. At the moment on line 222 we have:

  1. get fstat
  2. call isFileModified

Here we are doing the same:

  1. get fstat
  2. call isFileModified

I suggest passing only the path to isFileModified and getting the fstat in the method itself

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's used here

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