diff options
| author | hisham <hisham@9ca3f7c1-7366-0410-b1a3-b5c78f85698c> | 2009-07-01 15:36:35 +0000 |
|---|---|---|
| committer | hisham <hisham@9ca3f7c1-7366-0410-b1a3-b5c78f85698c> | 2009-07-01 15:36:35 +0000 |
| commit | abfc6b6ca8cbf492c5e8b5ff3434b92f69076125 (patch) | |
| tree | 7705a5393100932063e64382e82a41219916df5f /src | |
| parent | dbe5ce95176fd764188c55520c735a5334cf709c (diff) | |
| download | luarocks-abfc6b6ca8cbf492c5e8b5ff3434b92f69076125.tar.gz luarocks-abfc6b6ca8cbf492c5e8b5ff3434b92f69076125.tar.bz2 luarocks-abfc6b6ca8cbf492c5e8b5ff3434b92f69076125.zip | |
add 'move' command
git-svn-id: http://luarocks.org/svn/luarocks/trunk@36 9ca3f7c1-7366-0410-b1a3-b5c78f85698c
Diffstat (limited to 'src')
| -rw-r--r-- | src/luarocks/fs/lua.lua | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua index 16af8ab1..91cabe51 100644 --- a/src/luarocks/fs/lua.lua +++ b/src/luarocks/fs/lua.lua | |||
| @@ -454,6 +454,10 @@ end | |||
| 454 | 454 | ||
| 455 | end | 455 | end |
| 456 | 456 | ||
| 457 | --------------------------------------------------------------------- | ||
| 458 | -- Other functions | ||
| 459 | --------------------------------------------------------------------- | ||
| 460 | |||
| 457 | --- Apply a patch. | 461 | --- Apply a patch. |
| 458 | -- @param patchname string: The filename of the patch. | 462 | -- @param patchname string: The filename of the patch. |
| 459 | function apply_patch(patchname, patchdata) | 463 | function apply_patch(patchname, patchdata) |
| @@ -466,6 +470,31 @@ function apply_patch(patchname, patchdata) | |||
| 466 | end | 470 | end |
| 467 | end | 471 | end |
| 468 | 472 | ||
| 473 | --- Move a file. | ||
| 474 | -- @param src string: Pathname of source | ||
| 475 | -- @param dest string: Pathname of destination | ||
| 476 | -- @return boolean or (boolean, string): true on success, false on failure, | ||
| 477 | -- plus an error message. | ||
| 478 | function move(src, dest) | ||
| 479 | assert(src and dest) | ||
| 480 | if fs.exists(dest) then | ||
| 481 | return false, "File already exists: "..dest | ||
| 482 | end | ||
| 483 | local ok, err = fs.copy(src, dest) | ||
| 484 | if not ok then | ||
| 485 | return false, err | ||
| 486 | end | ||
| 487 | ok = fs.delete(src) | ||
| 488 | if not ok then | ||
| 489 | return false, "Failed move: could not delete "..src.." after copy." | ||
| 490 | end | ||
| 491 | return true | ||
| 492 | end | ||
| 493 | |||
| 494 | --------------------------------------------------------------------- | ||
| 495 | -- TODO These still reference external binaries | ||
| 496 | --------------------------------------------------------------------- | ||
| 497 | |||
| 469 | --- Unpack an archive. | 498 | --- Unpack an archive. |
| 470 | -- Extract the contents of an archive, detecting its format by | 499 | -- Extract the contents of an archive, detecting its format by |
| 471 | -- filename extension. | 500 | -- filename extension. |
