diff options
-rw-r--r-- | src/luarocks/cmd/write_rockspec.lua | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/src/luarocks/cmd/write_rockspec.lua b/src/luarocks/cmd/write_rockspec.lua index cf9181e6..701b079e 100644 --- a/src/luarocks/cmd/write_rockspec.lua +++ b/src/luarocks/cmd/write_rockspec.lua | |||
@@ -158,8 +158,13 @@ local function detect_description() | |||
158 | return summary, detailed | 158 | return summary, detailed |
159 | end | 159 | end |
160 | 160 | ||
161 | local function detect_mit_license(data) | 161 | local licenses = { |
162 | local strip_copyright = (data:gsub("Copyright [^\n]*\n", "")) | 162 | [78656] = "MIT", |
163 | [49311] = "ISC", | ||
164 | } | ||
165 | |||
166 | local function detect_license(data) | ||
167 | local strip_copyright = (data:gsub("^Copyright [^\n]*\n", "")) | ||
163 | local sum = 0 | 168 | local sum = 0 |
164 | for i = 1, #strip_copyright do | 169 | for i = 1, #strip_copyright do |
165 | local num = string.byte(strip_copyright:sub(i,i)) | 170 | local num = string.byte(strip_copyright:sub(i,i)) |
@@ -167,7 +172,7 @@ local function detect_mit_license(data) | |||
167 | sum = sum + num | 172 | sum = sum + num |
168 | end | 173 | end |
169 | end | 174 | end |
170 | return sum == 78656 | 175 | return licenses[sum] |
171 | end | 176 | end |
172 | 177 | ||
173 | local function check_license() | 178 | local function check_license() |
@@ -175,8 +180,9 @@ local function check_license() | |||
175 | if not fd then return nil end | 180 | if not fd then return nil end |
176 | local data = fd:read("*a") | 181 | local data = fd:read("*a") |
177 | fd:close() | 182 | fd:close() |
178 | if detect_mit_license(data) then | 183 | local license = detect_license(data) |
179 | return "MIT", data | 184 | if license then |
185 | return license, data | ||
180 | end | 186 | end |
181 | return nil, data | 187 | return nil, data |
182 | end | 188 | end |