Skip to content

vfs: ZipProvider.rename() fails with ENOENT for implicit directories #65751

Description

@trivikr

Version

main

Platform

macOS

Subsystem

vfs

What steps will reproduce the bug?

import { ZipBuffer, ZipEntry, createZipArchive } from 'node:zlib';
import { ZipProvider, create } from 'node:vfs';

const zipEntry = await ZipEntry.create('dir/file.txt', Buffer.from('hello'));
const zipArchive = createZipArchive([zipEntry]);
const archive = Buffer.concat(await Array.fromAsync(zipArchive));

const fs = create(new ZipProvider(new ZipBuffer(archive))).promises;
await fs.rename('/dir', '/renamed-dir');
console.log(await fs.readFile('/renamed-dir/file.txt', 'utf8'));

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

Always

What is the expected behavior? Why is that the expected behavior?

Renaming the implicit /dir directory moves its descendant entries. The program prints hello.

What do you see instead?

ZipProvider.rename() only looks for an explicit dir archive entry, so it treats the implicit directory as missing. The program throws ENOENT.

Additional information

fs equivalent which prints hello

import { mkdtemp, mkdir, writeFile, rename, readFile } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import { join } from 'node:path';

const root = await mkdtemp(join(tmpdir(), 'rename-repro-'));
await mkdir(join(root, 'dir'));
await writeFile(join(root, 'dir/file.txt'), 'hello');

await rename(join(root, 'dir'), join(root, 'renamed-dir'));
console.log(await readFile(join(root, 'renamed-dir/file.txt'), 'utf8'));

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

vfsIssues and PRs related to the virtual filesystem subsystem.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions