diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2012-10-16 18:34:11 -0300 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2012-10-16 18:34:11 -0300 |
commit | 479ee453640cac4e375b1800f2354963129e388c (patch) | |
tree | d237e04890289af00492e711fdfe20d94c193045 /src | |
parent | 742ee174c0db8448a8ef26944b0f93572c1c8b0c (diff) | |
download | luarocks-479ee453640cac4e375b1800f2354963129e388c.tar.gz luarocks-479ee453640cac4e375b1800f2354963129e388c.tar.bz2 luarocks-479ee453640cac4e375b1800f2354963129e388c.zip |
On Windows, we can't "os.rename" over an existing file. Closes #104.
Diffstat (limited to 'src')
-rw-r--r-- | src/luarocks/fs/unix.lua | 14 | ||||
-rw-r--r-- | src/luarocks/fs/win32.lua | 17 | ||||
-rw-r--r-- | src/luarocks/manif.lua | 2 |
3 files changed, 32 insertions, 1 deletions
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 | |||
93 | function copy_binary(filename, dest) | 93 | function copy_binary(filename, dest) |
94 | return fs.copy(filename, dest, "0755") | 94 | return fs.copy(filename, dest, "0755") |
95 | end | 95 | end |
96 | |||
97 | --- Move a file on top of the other. | ||
98 | -- The new file ceases to exist under its original name, | ||
99 | -- and takes over the name of the old file. | ||
100 | -- On Unix this is done through a single rename operation. | ||
101 | -- @param old_file The name of the original file, | ||
102 | -- which will be the new name of new_file. | ||
103 | -- @param new_file The name of the new file, | ||
104 | -- which will replace old_file. | ||
105 | -- @return boolean or (nil, string): True if succeeded, or nil and | ||
106 | -- an error message. | ||
107 | function replace_file(old_file, new_file) | ||
108 | return os.rename(new_file, old_file) | ||
109 | 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 | |||
112 | function get_permissions(filename) | 112 | function get_permissions(filename) |
113 | return "" | 113 | return "" |
114 | end | 114 | end |
115 | |||
116 | --- Move a file on top of the other. | ||
117 | -- The new file ceases to exist under its original name, | ||
118 | -- and takes over the name of the old file. | ||
119 | -- On Windows this is done by removing the original file and | ||
120 | -- renaming the new file to its original name. | ||
121 | -- @param old_file The name of the original file, | ||
122 | -- which will be the new name of new_file. | ||
123 | -- @param new_file The name of the new file, | ||
124 | -- which will replace old_file. | ||
125 | -- @return boolean or (nil, string): True if succeeded, or nil and | ||
126 | -- an error message. | ||
127 | function replace_file(old_file, new_file) | ||
128 | os.remove(old_file) | ||
129 | return os.rename(new_file, old_file) | ||
130 | end | ||
131 | |||
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) | |||
33 | local filename = dir.path(where, name) | 33 | local filename = dir.path(where, name) |
34 | local ok, err = persist.save_from_table(filename..".tmp", tbl) | 34 | local ok, err = persist.save_from_table(filename..".tmp", tbl) |
35 | if ok then | 35 | if ok then |
36 | ok, err = os.rename(filename..".tmp", filename) | 36 | ok, err = fs.replace_file(filename, filename..".tmp") |
37 | end | 37 | end |
38 | return ok, err | 38 | return ok, err |
39 | end | 39 | end |