Skip to content

Commit

Permalink
feat: handle dir creation during fs watch (#7573)
Browse files Browse the repository at this point in the history
Signed-off-by: Philippe Martin <phmartin@redhat.com>
  • Loading branch information
feloy committed Jun 12, 2024
1 parent 464d2ae commit 13491a1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
31 changes: 31 additions & 0 deletions packages/main/src/plugin/filesystem-monitoring.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,34 @@ test('should send event into onDid when a file is watched into an existing direc
expect(unlinkListener).toHaveBeenCalledWith(Uri.file(watchedFile));
});
});

test('should send event onDidCreate when a directory is created into a watched directory', async () => {
watcher = new FileSystemWatcherImpl(rootdir);

const readyListener = vi.fn();
watcher.onReady(readyListener);

const createListener = vi.fn();
watcher.onDidCreate(createListener);
const changeListener = vi.fn();
watcher.onDidChange(changeListener);
const unlinkListener = vi.fn();
watcher.onDidDelete(unlinkListener);

await vi.waitFor(async () => {
expect(readyListener).toHaveBeenCalled();
});

expect(createListener).toHaveBeenCalledWith(Uri.file(rootdir));
expect(changeListener).not.toHaveBeenCalled();
expect(unlinkListener).not.toHaveBeenCalled();

const createdDir = path.join(rootdir, 'dir');
await promises.mkdir(createdDir);

await vi.waitFor(async () => {
expect(createListener).toHaveBeenCalledWith(Uri.file(createdDir));
});
expect(changeListener).not.toHaveBeenCalled();
expect(unlinkListener).not.toHaveBeenCalled();
});
5 changes: 5 additions & 0 deletions packages/main/src/plugin/filesystem-monitoring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ export class FileSystemWatcherImpl implements containerDesktopAPI.FileSystemWatc
this._onDidCreate.fire(uri);
});

this.watcher.on('addDir', (addedPath: string) => {
const uri: containerDesktopAPI.Uri = Uri.file(addedPath);
this._onDidCreate.fire(uri);
});

this.watcher.on('change', (addedPath: string) => {
const uri: containerDesktopAPI.Uri = Uri.file(addedPath);
this._onDidChange.fire(uri);
Expand Down

0 comments on commit 13491a1

Please sign in to comment.