Skip to content
This repository has been archived by the owner on Feb 2, 2021. It is now read-only.

Commit

Permalink
DiskManager: handle the case where we get a directory change notifica…
Browse files Browse the repository at this point in the history
…tion for a new project file half way through the copy, try to load it, fail, and need to retry next time we see the file being modified.
  • Loading branch information
mikehearn committed Dec 4, 2014
1 parent 005a947 commit e84ba2b
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions common/src/main/java/lighthouse/files/DiskManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,37 +131,41 @@ private void onDirectoryChanged(Path path, WatchEvent.Kind<Path> kind) {
executor.checkOnThread();
boolean isProject = path.toString().endsWith(PROJECT_FILE_EXTENSION);
boolean isPledge = path.toString().endsWith(PLEDGE_FILE_EXTENSION);
// We model a change as a delete followed by an add.
boolean isCreate = kind == StandardWatchEventKinds.ENTRY_CREATE || kind == StandardWatchEventKinds.ENTRY_MODIFY;
boolean isDelete = kind == StandardWatchEventKinds.ENTRY_DELETE || kind == StandardWatchEventKinds.ENTRY_MODIFY;
boolean isCreate = kind == StandardWatchEventKinds.ENTRY_CREATE;
boolean isDelete = kind == StandardWatchEventKinds.ENTRY_DELETE;
boolean isModify = kind == StandardWatchEventKinds.ENTRY_MODIFY;

if (isProject || isPledge)
log.info("{} -> {}", path, kind);

// Project files are only auto loaded from the app directory. If the user downloads a serverless project to their
// Downloads folder, imports it, then downloads a second project, we don't want it to automatically appear.
if (isProject && path.getParent().equals(AppDirectory.dir())) {
if (isDelete) {
if (isDelete || isModify) {
log.info("Project file deleted/modified: {}", path);
Project project = projectsByPath.get(path);
if (project != null) {
if (kind == StandardWatchEventKinds.ENTRY_MODIFY) {
log.info("Project file modified, reloading ...");
this.tryLoadProject(path, projects.indexOf(project));
} else {
log.info("Project file deleted, removing ...");
projects.remove(project);
projectsByPath.remove(path);
synchronized (this) {
projectsById.remove(project.getID());
}
}
} else if (isModify) {
log.info("Project file modified, but we don't know about it: last load might have failed. Retrying");
this.tryLoadProject(path);
}
} else if (isCreate) {
log.info("New project found: {}", path);
this.tryLoadProject(path);
}
} else if (isPledge) {
if (isDelete) {
if (isDelete || isModify) {
LHProtos.Pledge pledge = pledgesByPath.get(path);
if (pledge != null) {
log.info("Pledge file deleted/modified: {}", path);
Expand All @@ -176,7 +180,7 @@ private void onDirectoryChanged(Path path, WatchEvent.Kind<Path> kind) {
log.error("Got delete event for a pledge we had not loaded, maybe missing project? {}", path);
}
}
if (isCreate) {
if (isCreate || isModify) {
this.tryLoadPledge(path);
}
}
Expand Down

0 comments on commit e84ba2b

Please sign in to comment.