1
1
local dependencies = require " bsrocks.rocks.dependencies"
2
2
local download = require " bsrocks.downloaders"
3
3
local fileWrapper = require " bsrocks.lib.files"
4
+ local log = require " bsrocks.lib.utils" .log
5
+ local patchspec = require " bsrocks.rocks.patchspec"
4
6
local rockspec = require " bsrocks.rocks.rockspec"
5
7
local serialize = require " bsrocks.lib.serialize"
6
8
local settings = require " bsrocks.lib.settings"
7
- local utils = require " bsrocks.lib.utils "
9
+ local tree = require " bsrocks.downloaders.tree "
8
10
9
11
local installDirectory = settings .installDirectory
10
- local servers = settings .servers
11
- local patchServers = settings .patchServers
12
12
13
13
local fetched = false
14
14
local installed = {}
15
15
16
- local function save (rockS )
17
- local files = rockspec .extractFiles (rockS )
16
+ local function save (rockS , patchS )
17
+ local blacklist = {}
18
+ if patchspec and patchspec .remove then
19
+ for _ , v in ipairs (patchspec .remove ) do blacklist [v ] = true end
20
+ end
18
21
22
+ local files = rockspec .extractFiles (rockS , blacklist )
19
23
local downloaded = download (rockS .source , files )
20
24
21
25
if not downloaded then
22
- error (" Cannot find downloader for " .. rockS .source .url )
26
+ error (" Cannot find downloader for " .. rockS .source .url , 0 )
27
+ end
28
+
29
+ if patchS then
30
+ local patchFiles = rockspec .extractFiles (patchS )
31
+ local downloadPatch = tree (patchFiles .server .. ' /' .. rockS .name , patchFiles )
32
+
33
+ files = applyPatches (downloaded , downloadPatch , patchS .patches or {}, patchS .added or {}, patchS .removed or {})
23
34
end
24
35
25
36
rockspec .saveFiles (rockS , downloaded , installDirectory )
@@ -49,21 +60,30 @@ local function getInstalled()
49
60
end
50
61
51
62
local function install (name , version , constraints )
52
- local server , manifest = rockspec .findRock (servers , name )
63
+ -- Do the cheapest action ASAP
64
+ local versions = getInstalled ()
65
+ local current = versions [name ]
66
+ if current and (version == nil or current .version == version ) then
67
+ error (" Already installed" , 0 )
68
+ end
69
+
70
+ local server , manifest = rockspec .findRock (name )
71
+
53
72
if not server then
54
- error (" Cannot find '" .. name .. " '" )
73
+ error (" Cannot find '" .. name .. " '" , 0 )
55
74
end
56
75
76
+ local patchspec = patchspec .findPatchspec (name )
57
77
if not version then
58
- version = rockspec .latestVersion (manifest , name , constraints )
78
+ if patchspec then
79
+ version = patchspec .version
80
+ else
81
+ version = rockspec .latestVersion (manifest , name , constraints )
82
+ end
59
83
end
60
84
61
- local versions = getInstalled ()
62
- local current = versions [name ]
63
- if current then
64
- if current .version == version then
65
- error (" Already installed" )
66
- end
85
+ if current and current .version == version then
86
+ error (" Already installed" , 0 )
67
87
end
68
88
69
89
local rockspec = rockspec .fetchRockspec (server , name , version )
@@ -77,15 +97,15 @@ local function install(name, version, constraints)
77
97
if current then
78
98
local version = dependencies .parseVersion (current .version )
79
99
if not dependencies .matchConstraints (version , dependency .constraints ) then
80
- print (" Should update " .. dependency .name .. " ( got " .. current .version .. " , need " .. deps .. " )" )
100
+ log (" Should update " .. dependency .name .. " ( got " .. current .version .. " , need " .. deps .. " )" )
81
101
end
82
102
else
83
- print (" Installing dependency " .. name )
103
+ log (" Installing dependency " .. name )
84
104
install (name , nil , dependency .constraints )
85
105
end
86
106
end
87
107
88
- save (rockspec )
108
+ save (rockspec , patchspec )
89
109
end
90
110
91
111
return {
0 commit comments