Skip to content

Commit

Permalink
Don't reinstall packages that already exist
Browse files Browse the repository at this point in the history
  • Loading branch information
ElvishJerricco committed Oct 4, 2014
1 parent 42fe6ee commit e33e726
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
18 changes: 13 additions & 5 deletions bin/grin-install.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,24 @@ if not options.package then
end

local user, repo, tag = grin.packageNameComponents(options.package)
if grin.isPackageInstalled(grin.combine(user, repo, tag)) then
print("Package already installed")
return
end

local releaseInfo = grin.getReleaseInfoFromGithub(grin.combine(user, repo))
local release
for i,v in ipairs(releaseInfo) do
if v.tag_name == tag then
release = v
break
if tag then
for i,v in ipairs(releaseInfo) do
if v.tag_name == tag then
release = v
break
end
end
assert(release, "Tag not found " .. tag)
else
release = assert(releaseInfo[1], "No releases found")
end
assert(release, "Tag not found " .. tag)

local grinPrg = grin.resolveInPackage("ElvishJerricco/Grin", "grin")
shell.run(grinPrg, "-u", user, "-r", repo, "-t", release.tag_name,
Expand Down
13 changes: 12 additions & 1 deletion lib/grin
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ function getLatestInstalledVersion(pkg)
expect("string", pkg)
local jsonData = getReleaseInfo(pkg)

local user, repo, tag = packageNameComponents(pkg)
local _,_, user, repo = pkg:find("^([^/]+)/([^/]+)$")
assert(user and repo, "Invalid package name: " .. pkg)
local packageDir = combine(grinDir, "packages", user, repo)
for i,v in ipairs(jsonData) do
if fs.isDir(combine(packageDir, v.tag_name)) then
Expand All @@ -207,6 +208,16 @@ function forEach(func)
end
end

function isPackageInstalled(pkg)
expect("string", pkg)
local user, repo, tag = packageNameComponents(pkg)
if not tag then
return false
else
return fs.isDir(combine(grinDir, "packages", user, repo, tag))
end
end

local packageAPIs = {}
function getPackageAPI(pkg, name)
expect("string", pkg)
Expand Down

0 comments on commit e33e726

Please sign in to comment.