rrthomas/luaposix — Issue #27: posix.chmod textual option does not behave like chmod(1)
Author: hishamhm
Created: 2012-02-10 20:04:21+00:00
State: open

While debugging [LuaRocks issue #55](https://github.com/keplerproject/luarocks/issues/55), I found out that the second argument for posix.chmod() does not behave like the "chmod" command-line tool:

$ touch file
$ chmod 0777 file
$ ls -l file
-rwxrwxrwx 1 hisham users 0 Feb 10 17:32 file
$ chmod u=rwx,g=rx,o=rx file
$ ls -l file
-rwxr-xr-x 1 hisham users 0 Feb 10 17:32 file
$ chmod 0777 file
$ lua -e "require'posix';posix.chmod('file','u=rwx,g=rx,o=rx')"
$ ls -l file
-------r-x 1 hisham users 0 Feb 10 17:32 file
$ chmod 0777 file
$ chmod u=rwx,g+rx,o+rx file
$ ls -l file
-rwxrwxrwx 1 hisham users 0 Feb 10 17:32 file
$ chmod 0777 file
$ lua -e "require'posix';posix.chmod('file','u=rwx,g+rx,o+rx')"
$ ls -l file
-rwxr-xr-x 1 hisham users 0 Feb 10 17:32 file

Given that they share the same syntax, I assumed the semantics were supposed to be the same. But as you can see, in posix.chmod(), each "=" sign is resetting the entire value, while in chmod(1), the "u", "g" and "o" categories are handled separately.

I tried using this syntax in LuaRocks because I enable LuaPosix conditionally according to availability, and run os.execute("chmod ...") as a fallback. posix.chmod(file, "rwxr-xr-x") works as expected, but chmod(1) does not support that.

By any chance, do you know any syntax that works the same on both chmod(1) and LuaPosix 5.1.15? (That would spare me from leaking the abstraction in my code.)