Skip to content
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

fs.watch for symbolic links #3469

Closed
tipiirai opened this issue Jun 30, 2023 · 3 comments · Fixed by #3481
Closed

fs.watch for symbolic links #3469

tipiirai opened this issue Jun 30, 2023 · 3 comments · Fixed by #3481
Labels
bug Something isn't working node.js Compatibility with Node.js APIs

Comments

@tipiirai
Copy link

What version of Bun is running?

0.6.11

What platform is your computer?

Darwin 20.6.0 arm64 arm

What steps can reproduce the bug?

fs.watch for symbolic links to directories does not emit changes. Works on Node.

What is the expected behavior?

No response

What do you see instead?

No response

Additional information

Thanks for the awesome project!

@tipiirai tipiirai added the bug Something isn't working label Jun 30, 2023
@paperdave paperdave added the node.js Compatibility with Node.js APIs label Jun 30, 2023
@Hanaasagi
Copy link
Collaborator

Hanaasagi commented Jul 1, 2023

Symbolic files also have this problem. Here are the steps to reproduce it:

  1. Create file and symlink
$ touch testfile && ln -s testfile testlink
  1. Run following code
const fs = require("fs");

// const file = "testfile";
const file = "testlink";

fs.watch(file, (eventType, filename) => {
  console.log(eventType, filename);
});

Error and traceback.

35 |       listener = () => {
36 |       };
37 |     this.#listener = listener;
38 |     try {
39 |
40 |       this.#watcher = fs.watch(path, options || {}, this.#onEvent.bind(this));
                         ^
error: NotDir Failed to watch filename
      at new FSWatcher (node:fs:40:22)
      at watch2 (node:fs:159:9)
      at /home/kumiko/zig/bun/x.js:6:0
      at globalThis (/home/kumiko/zig/bun/x.js:8:1)

  • bun 0.6.12
  • Linux 6.3.9-arch1-1

switch (stat.kind) {
.sym_link => {
var file = try std.fs.openFileAbsoluteZ(absolute_path_z, .{ .mode = .read_only });
result.fd = file.handle;
const _stat = try file.stat();
result.is_file = _stat.kind == .directory;
},

I think Line 805 should be changed to

                result.is_file = _stat.kind != .directory;

@cirospaciari
Copy link
Collaborator

Symbolic files also have this problem. Here are the steps to reproduce it:

  1. Create file and symlink
$ touch testfile && ln -s testfile testlink
  1. Run following code
const fs = require("fs");

// const file = "testfile";
const file = "testlink";

fs.watch(file, (eventType, filename) => {
  console.log(eventType, filename);
});

Error and traceback.

35 |       listener = () => {
36 |       };
37 |     this.#listener = listener;
38 |     try {
39 |
40 |       this.#watcher = fs.watch(path, options || {}, this.#onEvent.bind(this));
                         ^
error: NotDir Failed to watch filename
      at new FSWatcher (node:fs:40:22)
      at watch2 (node:fs:159:9)
      at /home/kumiko/zig/bun/x.js:6:0
      at globalThis (/home/kumiko/zig/bun/x.js:8:1)
  • bun 0.6.12
  • Linux 6.3.9-arch1-1

switch (stat.kind) {
.sym_link => {
var file = try std.fs.openFileAbsoluteZ(absolute_path_z, .{ .mode = .read_only });
result.fd = file.handle;
const _stat = try file.stat();
result.is_file = _stat.kind == .directory;
},

I think Line 805 should be changed to

                result.is_file = _stat.kind != .directory;

That was a big oopsie on my part, sorry about that.

@tipiirai
Copy link
Author

Thank you @cirospaciari !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working node.js Compatibility with Node.js APIs
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants