Carrooi / Node-FsMock

[ABANDONED] Mock for fs module
MIT License
7 stars 2 forks source link

Folders are not considered to exist if path contains a trailing '/' #13

Closed eugirdor closed 9 years ago

eugirdor commented 9 years ago

Under the posix implementation (haven't tested Windows), any methods that work with directories do not work if the path contains a trailing '/'.

Given the two tests:

Passes /var/www:

it 'should return true when directory exists (w/o trailing /)', (done) ->
    fs.writeFileSync('/var/www/index.php', '')
        fs.exists('/var/www', (exists) ->
            expect(exists).to.be.true
            done()
        )

Fails /var/www/:

it 'should return true when directory exists (w/trailing /)', (done) ->
    fs.writeFileSync('/var/www/index.php', '')
    fs.exists('/var/www/', (exists) ->
        expect(exists).to.be.true
        done()
    )
davidkudera commented 9 years ago

Hello and thanks, do you want to create a pull request?

eugirdor commented 9 years ago

I don't have a fix for the issue currently. Somewhere in the code it needs to check if the path sans the trailing '/' exists and that it is a directory. If it is not a directory (i.e. /var/ww/index.php/) it needs to throw an ENOTDIR error, which does not happen either right now, you always get ENOENT instead.

I think the fix might need to be in two places, the way the code is structured right now. existsSync to fix the test I posted, but also in realpathSync to throw the appropriate error.

What do you think?

eugirdor commented 9 years ago

Those should probably be two separate pull requests. The issue with the wrong error being thrown is kind of moot until #12 gets fixed.