| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
local assert = assert |
| 21 |
local os = os |
| 22 |
local os_execute = os.execute |
| 23 |
local os_remove = os.remove |
| 24 |
local filesys = require "lfs" |
| 25 |
local pathutil = require "texrunner.pathutil" |
| 26 |
local shellutil = require "texrunner.shellutil" |
| 27 |
local escape = shellutil.escape |
| 28 |
|
| 29 |
local copy_command |
| 30 |
if os.type == "windows" then |
| 31 |
function copy_command(from, to) |
| 32 |
|
| 33 |
return "copy " .. escape(from) .. " " .. escape(to) .. " > NUL" |
| 34 |
end |
| 35 |
else |
| 36 |
function copy_command(from, to) |
| 37 |
|
| 38 |
return "cp " .. escape(from) .. " " .. escape(to) |
| 39 |
end |
| 40 |
end |
| 41 |
|
| 42 |
local isfile = filesys.isfile or function(path) |
| 43 |
return filesys.attributes(path, "mode") == "file" |
| 44 |
end |
| 45 |
|
| 46 |
local isdir = filesys.isdir or function(path) |
| 47 |
return filesys.attributes(path, "mode") == "directory" |
| 48 |
end |
| 49 |
|
| 50 |
local function mkdir_rec(path) |
| 51 |
local succ, err = filesys.mkdir(path) |
| 52 |
if not succ then |
| 53 |
succ, err = mkdir_rec(pathutil.parentdir(path)) |
| 54 |
if succ then |
| 55 |
return filesys.mkdir(path) |
| 56 |
end |
| 57 |
end |
| 58 |
return succ, err |
| 59 |
end |
| 60 |
|
| 61 |
local function remove_rec(path) |
| 62 |
if isdir(path) then |
| 63 |
for file in filesys.dir(path) do |
| 64 |
if file ~= "." and file ~= ".." then |
| 65 |
local succ, err = remove_rec(pathutil.join(path, file)) |
| 66 |
if not succ then |
| 67 |
return succ, err |
| 68 |
end |
| 69 |
end |
| 70 |
end |
| 71 |
return filesys.rmdir(path) |
| 72 |
else |
| 73 |
return os_remove(path) |
| 74 |
end |
| 75 |
end |
| 76 |
|
| 77 |
return { |
| 78 |
copy_command = copy_command, |
| 79 |
isfile = isfile, |
| 80 |
isdir = isdir, |
| 81 |
mkdir_rec = mkdir_rec, |
| 82 |
remove_rec = remove_rec, |
| 83 |
} |