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

Link cache collision in write-entry due to erroneous 'ino' #431

Open
b-gutzmann opened this issue Jan 16, 2025 · 1 comment
Open

Link cache collision in write-entry due to erroneous 'ino' #431

b-gutzmann opened this issue Jan 16, 2025 · 1 comment

Comments

@b-gutzmann
Copy link

I am trying to create an archive with two different files, but one file ends up being (incorrectly) hard linked to the other. I believe this is because node erroneously reports the same 'ino' number for these files. Potentially related to nodejs/node#12115

Here is the code I'm using

            const mfiles = [
                './dist/components/FeatureFilterViewWindow.scss',
                './dist/components/FieldTagsInput.scss'
            ]
            const stream = tar.create(
                {
                    gzip: false,
                    onwarn: (code, message, date) => {
                        console.warn(code, message, date);
                    },
                    filter: (path, stat) => {
                        console.log(path, stat);
                        return true;
                    }
                },
                mfiles
            );

            const writeStream = fs.createWriteStream(packageTarball);
            stream.pipe(writeStream).on('error', (e) => {
                console.error('error', e);
            }).on('finish', () => {
                console.log('finished');
            })

which prints

./dist/components/FeatureFilterViewWindow.scss Stats {
  dev: 204880295,
  mode: 33206,
  nlink: 2,
  uid: 0,
  gid: 0,
  rdev: 0,
  blksize: 4096,
  ino: 9570149211882252,
  size: 667,
  blocks: 8,
  atimeMs: 1737048571848.961,
  mtimeMs: 1724710432427.687,
  ctimeMs: 1736989116749.4336,
  birthtimeMs: 1734560418984.347,
  atime: 2025-01-16T17:29:31.849Z,
  mtime: 2024-08-26T22:13:52.428Z,
  ctime: 2025-01-16T00:58:36.749Z,
  birthtime: 2024-12-18T22:20:18.984Z
}
./dist/components/FieldTagsInput.scss Stats {
  dev: 204880295,
  mode: 33206,
  nlink: 2,
  uid: 0,
  gid: 0,
  rdev: 0,
  blksize: 4096,
  ino: 9570149211882252,
  size: 233,
  blocks: 0,
  atimeMs: 1737047555156.3042,
  mtimeMs: 1736987398798.4736,
  ctimeMs: 1736989157564.605,
  birthtimeMs: 1736987481606.987,
  atime: 2025-01-16T17:12:35.156Z,
  mtime: 2025-01-16T00:29:58.798Z,
  ctime: 2025-01-16T00:59:17.565Z,
  birthtime: 2025-01-16T00:31:21.607Z
}
finished

Note that the 'ino' numbers are identical.

which ends up creating an archive that looks like this in 7-zip
Image

I believe using the bigint option for fs.stat can fix the issue.

            mfiles.forEach(file => {
                console.log(file);
                console.log(fs.statSync(file, { bigint: true }));
            });

prints

./dist/components/FeatureFilterViewWindow.scss
BigIntStats {
  dev: 204880295n,
  mode: 33206n,
  nlink: 2n,
  uid: 0n,
  gid: 0n,
  rdev: 0n,
  blksize: 4096n,
  ino: 9570149211882252n,
  size: 667n,
  blocks: 8n,
  atimeMs: 1737048612767n,
  mtimeMs: 1724710432427n,
  ctimeMs: 1736989116749n,
  birthtimeMs: 1734560418984n,
  atimeNs: 1737048612767570500n,
  mtimeNs: 1724710432427686900n,
  ctimeNs: 1736989116749433700n,
  birthtimeNs: 1734560418984347000n,
  atime: 2025-01-16T17:30:12.767Z,
  mtime: 2024-08-26T22:13:52.427Z,
  ctime: 2025-01-16T00:58:36.749Z,
  birthtime: 2024-12-18T22:20:18.984Z
}
./dist/components/FieldTagsInput.scss
BigIntStats {
  dev: 204880295n,
  mode: 33206n,
  nlink: 2n,
  uid: 0n,
  gid: 0n,
  rdev: 0n,
  blksize: 4096n,
  ino: 9570149211882253n,
  size: 233n,
  blocks: 0n,
  atimeMs: 1737047555156n,
  mtimeMs: 1736987398798n,
  ctimeMs: 1736989157564n,
  birthtimeMs: 1736987481606n,
  atimeNs: 1737047555156304200n,
  mtimeNs: 1736987398798473700n,
  ctimeNs: 1736989157564605000n,
  birthtimeNs: 1736987481606987000n,
  atime: 2025-01-16T17:12:35.156Z,
  mtime: 2025-01-16T00:29:58.798Z,
  ctime: 2025-01-16T00:59:17.564Z,
  birthtime: 2025-01-16T00:31:21.606Z
}

where the 'ino' numbers are no longer identical.

node-tar version 7.4.3
Node v18.20.5
Windows 11 Enterprise 23H2

@b-gutzmann
Copy link
Author

I think that the relevant code is

`${this.stat.dev}:${this.stat.ino}` as LinkCacheKey

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant