From 8baf006c896396be682c8bcb2d8733f150136340 Mon Sep 17 00:00:00 2001 From: payonel Date: Fri, 15 Apr 2016 20:07:50 -0700 Subject: [PATCH] cp -P added to support preserving symlinks. Also, -r enables -P --- .../resources/assets/opencomputers/loot/OpenOS/bin/cp.lua | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/cp.lua b/src/main/resources/assets/opencomputers/loot/OpenOS/bin/cp.lua index bbeed1f81..9caba103b 100644 --- a/src/main/resources/assets/opencomputers/loot/OpenOS/bin/cp.lua +++ b/src/main/resources/assets/opencomputers/loot/OpenOS/bin/cp.lua @@ -9,11 +9,14 @@ if #args < 2 then io.write(" -r: copy directories recursively.\n") io.write(" -u: copy only when the SOURCE file differs from the destination\n") io.write(" file or when the destination file is missing.\n") + io.write(" -P: preserve attributes, e.g. symbolic links.\n") io.write(" -v: verbose output.\n") io.write(" -x: stay on original source file system.\n") return 1 end +options.P = options.P or options.r + local from = {} for i = 1, #args - 1 do table.insert(from, shell.resolve(args[i])) @@ -66,6 +69,10 @@ end local function recurse(fromPath, toPath, origin) status(fromPath, toPath) + local isLink, target = fs.isLink(fromPath) + if isLink and options.P then + return fs.link(target, toPath) + end if fs.isDirectory(fromPath) then if not options.r then io.write("omitting directory `" .. fromPath .. "'\n")