From 3d33ab1f2192af8018e17415ef3ef8eab4de513c Mon Sep 17 00:00:00 2001 From: Tobias Ulmer Date: Tue, 8 Oct 2013 14:27:52 +0200 Subject: [PATCH] Replace chmod tool by function call and document it Swap arguments to be the same as chmod(2) Signed-off-by: Tobias Ulmer --- generic/e2lib.lua | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/generic/e2lib.lua b/generic/e2lib.lua index 1c1c902..3a954b9 100644 --- a/generic/e2lib.lua +++ b/generic/e2lib.lua @@ -1982,14 +1982,26 @@ function e2lib.svn(argv) return e2lib.call_tool_argv("svn", argv) end ---- call the chmod command --- @param mode string: the new mode --- @param path string: path --- @return bool --- @return the last line ouf captured output -function e2lib.chmod(mode, path) - local args = string.format("'%s' '%s'", mode, path) - return e2lib.call_tool("chmod", args) +--- Change permission mode of file. +-- @param path Path to file. +-- @param mode Permission mode, may be "644" or "ugo+rwx" (string). +-- @return True on success, false on error. +-- @return Error object on failure. +function e2lib.chmod(path, mode) + local rc, re, errstring, pmode + + pmode, re = e2lib.parse_mode(mode) + if not pmode then + return false, re + end + + rc, errstring = le2lib.chmod(path, pmode) + if not rc then + return false, err.new("changing permission mode on %q failed: %s", + path, errstring) + end + + return true end --- Close all file descriptors equal or larger than "fd". -- 2.39.5