diff --git a/clite/commands.js b/clite/commands.js index 9faa5a0..b8664c2 100644 --- a/clite/commands.js +++ b/clite/commands.js @@ -2163,6 +2163,137 @@ Options: return main(args); }); +clite.commands.load('chown',function(args,env,io) { + var stdlib = io.include('stdlib'); + var stdio = io.include('stdio'); + var clite = io.include('clite'); + + let user = null; + let group = null; + + let uid = -1; + let gid = -1; + + function help() { + stdio.printf(` +chown - change the owner of files +Usage: chown [OPTION] [:GROUP] + +Options: +-? Print this help information +`); + } + + function recurseDir(path) { + let fd = stdio.open(path,stdio.flags.O_SEARCH|stdio.flags.O_DIRECTORY|stdio.flags.O_SYNC); + if (!fd) { + stdio.fprintf(io.stderr,'could not recurse into directory: %s\n',path); + return; + } + let e = null; + while ((e = stdio.read(fd)) != null) { + let p = path+'/'+e; + let r = stdio.chown(p,uid,gid); + if (!r) + stdio.fprintf(io.stderr,'could not change ownership of file: %s\n',path); + } + stdio.close(fd); + } + + function main(args) { + let files = []; + let recurse = false; + for (var i=1; i 1) { + if (ug.length > 2) { + stdio.write(io.stderr,'no valid user specified\n'); + return 1; + } + + user = ug[0]; + group = ug[1]; + + if (user == '') + user = null; + if (group == '') + group = null; + } + + if (user) { + let pw = stdlib.getpwnam(user); + if (!pw) { + stdio.write(io.stderr,'invalid user specified\n'); + return 1; + } + uid = pw.pw_uid; + } + + if (group) { + let gr = stdlib.getgrnam(group); + if (!gr) { + stdio.write(io.stderr,'invalid group specified\n'); + return 1; + } + gid = gr.gr_gid; + } + + if (uid < 0 && gid < 0) { + stdio.write(io.stderr,'no valid user or group specified\n'); + return 1; + } + + for (var i=0; i