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

Odd behaviour of lfs.attributes and lfs.mkdir on Windows #79

Open
blasti opened this issue Aug 18, 2016 · 2 comments
Open

Odd behaviour of lfs.attributes and lfs.mkdir on Windows #79

blasti opened this issue Aug 18, 2016 · 2 comments

Comments

@blasti
Copy link

blasti commented Aug 18, 2016

Assume your are on Windows 7 with some HDD v:/. There is also a folder v:/rel.
Try this:

    print(lfs.attributes( "v:", "mode" ))
    print(lfs.attributes( "v://", "mode" ))
    print(lfs.attributes( "v:/", "mode" ))
    print(lfs.attributes( "v:/rel", "mode" ))
    print(lfs.attributes( "v:/rel/", "mode" ))
    print(lfs.attributes( "v:/rel//", "mode" ))
    print(lfs.mkdir("v:/s"))
    print(lfs.mkdir("v:/s/"))
    print(lfs.mkdir("v:/t/"))
    print(lfs.mkdir("v:/t"))

Result:

nil     cannot obtain information from file 'v:': No such file or directory
directory
directory
directory
nil     cannot obtain information from file 'v:/rel/': No such file or directory
nil     cannot obtain information from file 'v:/rel//': No such file or directory
true
nil     File exists
true
nil     File exists

So lfs.attributes does accept "/" at the end of a path, except it is the root directory.
Then you can even use "//".
But lfs.mkdir doesnt care at all.
Spend hours to find this bug in my code.
How is the situation on Linux? I didnt even try it yet.
Do I have to write a wrapper around each lfs function which expects a filepath, to find out what filepath does mean for each function and each platform?

@mpeterv
Copy link
Contributor

mpeterv commented Aug 18, 2016

stat() is bugged on Windows w.r.t. trailing slashes. Only lfs.attributes and lfs.symlinkattributes should be affected.

@blasti
Copy link
Author

blasti commented Aug 18, 2016

ok, i tried above stuff on Debian:

Lua 5.1.5  Copyright (C) 1994-2012 Lua.org, PUC-Rio
> l=require"lfs"
> return l.attributes("/", "mode")
directory
> return l.attributes("//", "mode")
directory
> return l.attributes("///", "mode")
directory
> return l.attributes("/bin", "mode")
directory
> return l.attributes("/bin/", "mode")
directory
> return l.mkdir "t"
true
> return l.mkdir "t/"
nil File exists
> return l.mkdir "u/"
true
> return l.mkdir "u"
nil File exists
> 

Looks much more sane here.

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

2 participants