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

lfs.dir does not raise an error for not existing path on Windows #39

Open
moteus opened this issue Apr 28, 2014 · 8 comments
Open

lfs.dir does not raise an error for not existing path on Windows #39

moteus opened this issue Apr 28, 2014 · 8 comments

Comments

@moteus
Copy link
Contributor

moteus commented Apr 28, 2014

lfs.dir with not existing path raise error on *nix but not on Windows.
I think error path not found/file not found shold be considered not as error but just as empty resultset.
At least it should be same on all platforms.

@mpeterv mpeterv changed the title lfs.dir with not existing path raise error. lfs.dir does not raise an error for not existing path on Windows Apr 26, 2016
@mpeterv
Copy link
Contributor

mpeterv commented Apr 26, 2016

Confirmed on Win10/VS2015, it returns an empty iterator. I think that current behaviour on other platforms (raising an error) is preferable.

@moteus
Copy link
Contributor Author

moteus commented Apr 26, 2016

I vote it should raise error if there some real error e.g. access denied. But if path does not exists it shuld returns empty iterator.

@mpeterv
Copy link
Contributor

mpeterv commented Apr 26, 2016

IMO if a directory you are trying to iterate over doesn't exist it's a real error, too, and it shouldn't be silently ignored. Let's see if there are any more opinions.

@Tieske
Copy link
Member

Tieske commented Apr 27, 2016

I vote for consitent behaviour across platforms, so thow an error if it doesn't exist

@hishamhm
Copy link
Member

I think it should throw an error if the path does not exist; at least this is what I would expect to happen in any filesystem library. Returning an empty iterator makes it indistiguishable from an empty directory.

@n1tehawk
Copy link
Contributor

The key problem here is that the dir_iter_factory() doesn't really access the directory for Win32 (and thus also performs no checking), and leaves it up to the actual iterator function (dir_iter()) to enumerate directory entries using the Windows FindFirst/FindNext paradigm.

To properly raise an error on invalid paths, the function should verify that the parameter really points to a directory. I've successfully implemented some proof-of-concept code in n1tehawk@9f70724.

Regards, NiteHawk

@sonoro1234
Copy link

sonoro1234 commented Feb 20, 2021

Any updates on this?

Another place where errors can happen is in calling the iterator function:
When there is a fail in win32 it returns nil, error making it imposible to distinguish from end of directory. (for f in just breaks)
In Linux there is no check of errno and just returns nil (even worse than win32)

My proposal would be to return false, errno on both platforms (as done in luapower/fs) so we can detect it as

for f,err in lsf.dir(path) do
    if not f then
       print("error",err)
       break
    end
    print("item is",f)
end

@sonoro1234
Copy link

See #132 (comment)

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

No branches or pull requests

6 participants