|
597 | 597 | copyfile = function(v) |
598 | 598 | return "cp -f " .. path.normalize(v) |
599 | 599 | end, |
| 600 | + copyfileifnewer = function(v) |
| 601 | + return "cp -u " .. path.normalize(v) |
| 602 | + end, |
600 | 603 | copydir = function(v) |
601 | 604 | return "cp -rf " .. path.normalize(v) |
602 | 605 | end, |
|
675 | 678 | -- Just use COPY instead, it actually works. |
676 | 679 | return "copy /B /Y " .. v |
677 | 680 | end, |
| 681 | + copyfileifnewer = function(v) |
| 682 | + -- A trailing * on the destination suppresses xcopy's |
| 683 | + -- locale-dependent "File or Directory?" prompt (the old |
| 684 | + -- "echo F |" hack only works on English Windows). |
| 685 | + -- |
| 686 | + -- A trailing / on the destination marks it as a |
| 687 | + -- directory; the source filename is appended so xcopy |
| 688 | + -- sees a file-to-file copy. |
| 689 | + |
| 690 | + -- Check for trailing / before normalize strips it. |
| 691 | + local orig_dst = v:match('%S+%s*$') or '' |
| 692 | + local orig_dst_bare = orig_dst:gsub('"', '') |
| 693 | + local dst_is_dir = orig_dst_bare:sub(-1) == '/' |
| 694 | + |
| 695 | + v = path.translate(path.normalize(v), "\\") |
| 696 | + |
| 697 | + if dst_is_dir then |
| 698 | + local src = string.match(v, '^".-"') or string.match(v, '^%S+') |
| 699 | + local src_name = path.getname(src:gsub('"', '')) |
| 700 | + -- Append source filename inside or outside closing quote. |
| 701 | + -- Strip any trailing separator that survived translate. |
| 702 | + if v:sub(-1) == '"' then |
| 703 | + local base = v:sub(1, -2):gsub('[/\\]$', '') |
| 704 | + v = base .. '\\' .. src_name .. '"' |
| 705 | + else |
| 706 | + v = v:gsub('[/\\]$', '') .. '\\' .. src_name |
| 707 | + end |
| 708 | + end |
| 709 | + |
| 710 | + -- Put * inside the closing quote when the path is quoted. |
| 711 | + if v:sub(-1) == '"' then |
| 712 | + v = v:sub(1, -2) .. '*"' |
| 713 | + else |
| 714 | + v = v .. "*" |
| 715 | + end |
| 716 | + return "xcopy /D /Y " .. v |
| 717 | + end, |
678 | 718 | copydir = function(v) |
679 | 719 | v = path.translate(path.normalize(v)) |
680 | 720 | return "xcopy /Q /E /Y /I " .. v |
|
0 commit comments