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

ufs.createWriteStream fails when folder exists but file does not #428

Closed
iamogbz opened this issue Mar 16, 2020 · 2 comments · Fixed by #783
Closed

ufs.createWriteStream fails when folder exists but file does not #428

iamogbz opened this issue Mar 16, 2020 · 2 comments · Fixed by #783
Labels

Comments

@iamogbz
Copy link

iamogbz commented Mar 16, 2020

Description

Creating a folder and then writing directly to a file in the folder is a normal usecase that unionfs does not support.

Steps to reproduce

With file

const fs = require('fs')

const { vol } = require('memfs')
const { ufs } = require('unionfs')

ufs.use(vol).use(fs)

const runExampleWith = fsInstance => {
    try {
        fsInstance.mkdirSync('example', { recursive: true })
        const stream = fsInstance.createWriteStream('example/file.txt')
        stream.write('test', () => stream.end())
    } finally {
        fsInstance.rmdirSync('example', { recursive: true })
    }
}

Using the default node fs works

runExampleWith(fs)

Using memfs directly works

runExampleWith(vol)

Using the combined ufs fails with

runExampleWith(ufs)
// Error: ENOENT: no such file or directory, open 'example/file.txt'

Cause

Union fs checks file exists before attempting to use the file systems

fs.statSync(path); //we simply stat first to exit early for mocked fs'es

Suggestion

import {dirname} from 'path' 
// ...
fs.statSync(dirname(path)); //we simply stat first to exit early for mocked fs'es

Related

@ddziara
Copy link

ddziara commented Nov 16, 2020

I've just encountered the problem.

Copy link

🎉 This issue has been resolved in version 4.5.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging a pull request may close this issue.

2 participants