Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
boilr
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nimrod
boilr
Commits
c9b0aae1
Commit
c9b0aae1
authored
8 years ago
by
Tamer Tas
Browse files
Options
Downloads
Patches
Plain Diff
pkg/cmd/download: remove zip/download/extract implementation
parent
71b4d0a9
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
pkg/cmd/download.go
+0
-79
0 additions, 79 deletions
pkg/cmd/download.go
with
0 additions
and
79 deletions
pkg/cmd/download.go
+
0
−
79
View file @
c9b0aae1
package
cmd
import
(
"archive/zip"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"path/filepath"
"strings"
cli
"github.com/spf13/cobra"
"github.com/tmrts/boilr/pkg/boilr"
"github.com/tmrts/boilr/pkg/cmd/util"
"github.com/tmrts/boilr/pkg/host"
"github.com/tmrts/boilr/pkg/util/exit"
"github.com/tmrts/boilr/pkg/util/git"
...
...
@@ -22,78 +15,6 @@ import (
"github.com/tmrts/boilr/pkg/util/validate"
)
func
downloadZip
(
URL
,
targetDir
string
)
error
{
f
,
err
:=
ioutil
.
TempFile
(
""
,
"boilr-download"
)
if
err
!=
nil
{
return
err
}
defer
f
.
Close
()
defer
os
.
RemoveAll
(
f
.
Name
())
resp
,
err
:=
http
.
Get
(
URL
)
if
err
!=
nil
{
return
err
}
defer
resp
.
Body
.
Close
()
if
_
,
err
:=
io
.
Copy
(
f
,
resp
.
Body
);
err
!=
nil
{
return
err
}
if
err
:=
f
.
Close
();
err
!=
nil
{
return
err
}
r
,
err
:=
zip
.
OpenReader
(
f
.
Name
())
if
err
!=
nil
{
return
err
}
defer
r
.
Close
()
extractFile
:=
func
(
f
*
zip
.
File
,
dest
string
)
error
{
rc
,
err
:=
f
.
Open
()
if
err
!=
nil
{
return
err
}
defer
rc
.
Close
()
// splits the first token of f.Name since it's zip file name
path
:=
filepath
.
Join
(
dest
,
strings
.
SplitAfterN
(
f
.
Name
,
"/"
,
2
)[
1
])
if
f
.
FileInfo
()
.
IsDir
()
{
err
:=
os
.
MkdirAll
(
path
,
f
.
Mode
())
if
err
!=
nil
{
return
err
}
}
else
{
f
,
err
:=
os
.
OpenFile
(
path
,
os
.
O_WRONLY
|
os
.
O_CREATE
|
os
.
O_TRUNC
,
f
.
Mode
())
if
err
!=
nil
{
return
err
}
defer
f
.
Close
()
if
_
,
err
:=
io
.
Copy
(
f
,
rc
);
err
!=
nil
{
return
err
}
}
return
nil
}
for
_
,
f
:=
range
r
.
File
{
if
err
:=
extractFile
(
f
,
targetDir
);
err
!=
nil
{
return
err
}
}
// TODO Wrap this function in a validation wrapper from top to bottom
if
_
,
err
:=
util
.
ValidateTemplate
(
targetDir
);
err
!=
nil
{
return
err
}
return
nil
}
// Download contains the cli-command for downloading templates from github.
var
Download
=
&
cli
.
Command
{
Use
:
"download <template-repo> <template-tag>"
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment