From 742ee174c0db8448a8ef26944b0f93572c1c8b0c Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Mon, 8 Oct 2012 21:10:15 -0300 Subject: Add check based on @avnik's pull request. Closes #95. --- Makefile | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 4c18cd34..0e3871e5 100644 --- a/Makefile +++ b/Makefile @@ -125,7 +125,12 @@ install_bins: built install_luas: built mkdir -p "$(DESTDIR)$(LUADIR)/luarocks" - cd src/luarocks && for f in $(LUAROCKS_FILES); do d="$(DESTDIR)$(LUADIR)/luarocks"/`dirname "$$f"`; mkdir -p "$$d"; cp "$$f" "$$d"; done + cd src/luarocks && for f in $(LUAROCKS_FILES); \ + do \ + d="$(DESTDIR)$(LUADIR)/luarocks"/`dirname "$$f"` && \ + mkdir -p "$$d" && \ + cp "$$f" "$$d" || exit 1; \ + done install_site_config: built mkdir -p "$(DESTDIR)$(LUADIR)/luarocks" -- cgit v1.2.3-55-g6feb From 479ee453640cac4e375b1800f2354963129e388c Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Tue, 16 Oct 2012 18:34:11 -0300 Subject: On Windows, we can't "os.rename" over an existing file. Closes #104. --- src/luarocks/fs/unix.lua | 14 ++++++++++++++ src/luarocks/fs/win32.lua | 17 +++++++++++++++++ src/luarocks/manif.lua | 2 +- 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/luarocks/fs/unix.lua b/src/luarocks/fs/unix.lua index e0d40970..cfd20c70 100644 --- a/src/luarocks/fs/unix.lua +++ b/src/luarocks/fs/unix.lua @@ -93,3 +93,17 @@ end function copy_binary(filename, dest) return fs.copy(filename, dest, "0755") end + +--- Move a file on top of the other. +-- The new file ceases to exist under its original name, +-- and takes over the name of the old file. +-- On Unix this is done through a single rename operation. +-- @param old_file The name of the original file, +-- which will be the new name of new_file. +-- @param new_file The name of the new file, +-- which will replace old_file. +-- @return boolean or (nil, string): True if succeeded, or nil and +-- an error message. +function replace_file(old_file, new_file) + return os.rename(new_file, old_file) +end diff --git a/src/luarocks/fs/win32.lua b/src/luarocks/fs/win32.lua index cbf5fc60..2c78d9b6 100644 --- a/src/luarocks/fs/win32.lua +++ b/src/luarocks/fs/win32.lua @@ -112,3 +112,20 @@ end function get_permissions(filename) return "" end + +--- Move a file on top of the other. +-- The new file ceases to exist under its original name, +-- and takes over the name of the old file. +-- On Windows this is done by removing the original file and +-- renaming the new file to its original name. +-- @param old_file The name of the original file, +-- which will be the new name of new_file. +-- @param new_file The name of the new file, +-- which will replace old_file. +-- @return boolean or (nil, string): True if succeeded, or nil and +-- an error message. +function replace_file(old_file, new_file) + os.remove(old_file) + return os.rename(new_file, old_file) +end + diff --git a/src/luarocks/manif.lua b/src/luarocks/manif.lua index 2c745f0b..65a6beba 100644 --- a/src/luarocks/manif.lua +++ b/src/luarocks/manif.lua @@ -33,7 +33,7 @@ local function save_table(where, name, tbl) local filename = dir.path(where, name) local ok, err = persist.save_from_table(filename..".tmp", tbl) if ok then - ok, err = os.rename(filename..".tmp", filename) + ok, err = fs.replace_file(filename, filename..".tmp") end return ok, err end -- cgit v1.2.3-55-g6feb