Skip to content

Hardlink is sometimes written before the file it references to #448

@3bl3gamer

Description

@3bl3gamer

When there are two files pointing to same inode:

mkdir files
touch files/file0
ln files/file0 files/file1

node-tar writes them to tarball as regular file + hardlink:

const tar = require("tar")
const fs = require("fs")

tar
    .create({}, ["files"])
    .pipe(fs.createWriteStream("tarball.tar"))

But sometimes (with ~10% chance) these records are placed in the wrong order (link goes before the file):

> node index.js; and tar --list --verbose -f tarball.tar
drwxr-xr-x zblzgamer/1000    0 2025-12-09 14:56 files/
hrw-r--r-- zblzgamer/1000    0 2025-12-09 14:56 files/file0 link to files/file1
-rw-r--r-- zblzgamer/1000    0 2025-12-09 14:56 files/file1

tar decompresses this tarball partially and with error:

> tar -xf tarball.tar --directory=extracted
tar: files/file0: Cannot hard link to ‘files/file1’: No such file or directory
tar: Exiting with failure status due to previous errors

> find extracted
extracted
extracted/files
extracted/files/file1

node-tar version: 7.5.2

node version: v25.2.1

OS: Arch Linux

FS: btrfs

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions