Skip to content

Commit cd1b748

Browse files
CHE-6575. Invoke File Watcher 'create' consumer when item is created
Signed-off-by: Roman Nikitenko <rnikiten@redhat.com>
1 parent e74205e commit cd1b748

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

wsagent/che-core-api-project/src/main/java/org/eclipse/che/api/vfs/watcher/FileWatcherByPathMatcher.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212

1313
import static com.google.common.collect.Sets.newConcurrentHashSet;
1414
import static java.nio.file.Files.exists;
15+
import static org.eclipse.che.api.vfs.watcher.FileWatcherUtils.toInternalPath;
1516

1617
import com.google.inject.Inject;
18+
import java.io.File;
1719
import java.nio.file.Path;
1820
import java.nio.file.PathMatcher;
1921
import java.util.Iterator;
@@ -23,6 +25,7 @@
2325
import java.util.concurrent.ConcurrentHashMap;
2426
import java.util.concurrent.atomic.AtomicInteger;
2527
import java.util.function.Consumer;
28+
import javax.inject.Named;
2629
import javax.inject.Singleton;
2730
import org.slf4j.Logger;
2831
import org.slf4j.LoggerFactory;
@@ -44,8 +47,12 @@ public class FileWatcherByPathMatcher implements Consumer<Path> {
4447
/** Registered path -> Path watch operation IDs */
4548
private final Map<Path, Set<Integer>> pathWatchRegistrations = new ConcurrentHashMap<>();
4649

50+
private final File root;
51+
4752
@Inject
48-
public FileWatcherByPathMatcher(FileWatcherByPathValue watcher) {
53+
public FileWatcherByPathMatcher(
54+
@Named("che.user.workspaces.storage") File root, FileWatcherByPathValue watcher) {
55+
this.root = root;
4956
this.watcher = watcher;
5057
}
5158

@@ -57,6 +64,7 @@ public void accept(Path path) {
5764
}
5865
paths.values().forEach(it -> it.remove(path));
5966
paths.entrySet().removeIf(it -> it.getValue().isEmpty());
67+
return;
6068
}
6169

6270
for (PathMatcher matcher : matchers.keySet()) {
@@ -74,6 +82,7 @@ public void accept(Path path) {
7482
watcher.watch(path, operation.create, operation.modify, operation.delete);
7583
pathWatchRegistrations.putIfAbsent(path, newConcurrentHashSet());
7684
pathWatchRegistrations.get(path).add(pathWatcherOperationId);
85+
operation.create.accept(toInternalPath(root.toPath(), path));
7786
}
7887
}
7988
}

0 commit comments

Comments
 (0)