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

Stats object returned by fs.stats does not have stats.isSymbolicLink function #797

Closed
robogeek opened this issue Jul 20, 2022 · 1 comment · Fixed by #807
Closed

Stats object returned by fs.stats does not have stats.isSymbolicLink function #797

robogeek opened this issue Jul 20, 2022 · 1 comment · Fixed by #807
Labels
bug Something isn't working needs repro Needs an example to reproduce

Comments

@robogeek
Copy link

Version

0.1.4

Platform

Linux davidpc 5.15.0-41-generic #44-Ubuntu SMP Wed Jun 22 14:20:53 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

What steps will reproduce the bug?

I initially found this issue running code which uses Chokidar, but have also replicated it with code that simply uses fs.stat

import { stat } from 'fs';
import { stat as stat_p } from 'fs/promises';

import { inspect } from 'util';

const fn = process.argv[2];

stat(fn, (err, stats) => {
    if (err) console.error(err);
    else {
        console.log(inspect(stats));
        console.log(inspect(stats.isSymbolicLink));
    }
});

try {
    const stats = await stat_p(fn);
    console.log(inspect(stats));
    console.log(inspect(stats.isSymbolicLink));
} catch (err) {
    console.error(err);
}

Gives the output:

$ bun stat.mjs stat.mjs 
{ [Function]
  dev: 2053,
  ino: 18356089,
  mode: 33204,
  nlink: 1,
  uid: 1000,
  gid: 1000,
  rdev: 0,
  size: 472,
  blksize: 4096,
  blocks: 8,
  atime: Tue Jul 19 2022 23:08:10 GMT-0700 (Pacific Daylight Time),
  mtime: Tue Jul 19 2022 23:08:10 GMT-0700 (Pacific Daylight Time),
  ctime: Tue Jul 19 2022 23:08:10 GMT-0700 (Pacific Daylight Time),
  birthtime: Wed Dec 31 1969 16:00:00 GMT-0800 (Pacific Standard Time),
  atime_ms: 719,
  mtime_ms: 711,
  ctime_ms: 711,
  birthtime_ms: 0,
  isFile: [Function: isFile],
  isDirectory: [Function: isDirectory],
  finalize: undefined }
undefined
{ [Function]
  dev: 2053,
  ino: 18356089,
  mode: 33204,
  nlink: 1,
  uid: 1000,
  gid: 1000,
  rdev: 0,
  size: 472,
  blksize: 4096,
  blocks: 8,
  atime: Tue Jul 19 2022 23:08:10 GMT-0700 (Pacific Daylight Time),
  mtime: Tue Jul 19 2022 23:08:10 GMT-0700 (Pacific Daylight Time),
  ctime: Tue Jul 19 2022 23:08:10 GMT-0700 (Pacific Daylight Time),
  birthtime: Wed Dec 31 1969 16:00:00 GMT-0800 (Pacific Standard Time),
  atime_ms: 719,
  mtime_ms: 711,
  ctime_ms: 711,
  birthtime_ms: 0,
  isFile: [Function: isFile],
  isDirectory: [Function: isDirectory],
  finalize: undefined }
undefined

The Chokidar example is this:

const { inspect } = require('util');
const chokidar = require('chokidar');

chokidar.watch(process.argv[2])
.on('error', async (error) => {
    console.error(error);
})
.on('add', (fpath, stats) => {
    console.log(`add ${fpath} ${inspect(stats)}`);
})
.on('change', (fpath, stats) => {
    console.log(`change ${fpath} ${inspect(stats)}`);
});

The output is:

242 |   }
243 | 
244 |   filterPath(entry) {
245 |     const {stats} = entry;
246 |     console.log(`filterPath ${inspect(stats)}`);
247 |     if (stats && stats.isSymbolicLink()) return this.filterDir(entry);
                     ^
 TypeError: stats.isSymbolicLink is not a function. (In 'stats.isSymbolicLink()', 'stats.isSymbolicLink' is undefined)
      at filterPath (/home/david/Projects/akasharender/stacked-directories/node_modules/chokidar/index.js:247:17)
      at /home/david/Projects/akasharender/stacked-directories/node_modules/readdirp/index.js:141:79

The console.log also shows that the stats object does not have the isSymbolicLink function.

How often does it reproduce? Is there a required condition?

Every time

What is the expected behavior?

In the Node.js documentation, isSymbolicLink has been included in the Stats object since v10.10.0

It's clear that this function should be included in the object.

What do you see instead?

As noted above, the Stats object does not have the isSymbolicLink function

Additional information

No response

@robogeek robogeek added bug Something isn't working needs repro Needs an example to reproduce labels Jul 20, 2022
@sno2
Copy link
Collaborator

sno2 commented Jul 20, 2022

I'd like to work on this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs repro Needs an example to reproduce
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants