2019-11-22 20:01:38 +00:00
|
|
|
// Copyright © 2019 Ettore Di Giacinto <mudler@gentoo.org>
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation; either version 2 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License along
|
|
|
|
// with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
2019-11-23 14:42:05 +00:00
|
|
|
"path"
|
2019-11-22 20:01:38 +00:00
|
|
|
"path/filepath"
|
|
|
|
|
2019-11-23 14:42:05 +00:00
|
|
|
. "github.com/mudler/luet/pkg/logger"
|
|
|
|
|
2019-11-22 20:01:38 +00:00
|
|
|
"github.com/mudler/luet/pkg/compiler"
|
|
|
|
"github.com/mudler/luet/pkg/helpers"
|
|
|
|
)
|
|
|
|
|
|
|
|
type LocalClient struct {
|
2019-11-22 22:12:03 +00:00
|
|
|
RepoData RepoData
|
2019-11-22 20:01:38 +00:00
|
|
|
}
|
|
|
|
|
2019-11-22 22:12:03 +00:00
|
|
|
func NewLocalClient(r RepoData) *LocalClient {
|
|
|
|
return &LocalClient{RepoData: r}
|
2019-11-22 20:01:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *LocalClient) DownloadArtifact(artifact compiler.Artifact) (compiler.Artifact, error) {
|
2019-11-23 14:42:05 +00:00
|
|
|
artifactName := path.Base(artifact.GetPath())
|
|
|
|
Info("Downloading artifact", artifactName, "from", c.RepoData.Uri)
|
2019-11-22 20:01:38 +00:00
|
|
|
file, err := ioutil.TempFile(os.TempDir(), "localclient")
|
|
|
|
if err != nil {
|
2019-11-22 22:12:03 +00:00
|
|
|
return nil, err
|
2019-11-22 20:01:38 +00:00
|
|
|
}
|
|
|
|
//defer os.Remove(file.Name())
|
|
|
|
|
2019-11-23 14:42:05 +00:00
|
|
|
err = helpers.CopyFile(filepath.Join(c.RepoData.Uri, artifactName), file.Name())
|
2019-11-22 20:01:38 +00:00
|
|
|
|
|
|
|
return compiler.NewPackageArtifact(file.Name()), nil
|
|
|
|
}
|
|
|
|
func (c *LocalClient) DownloadFile(name string) (string, error) {
|
2019-11-23 14:42:05 +00:00
|
|
|
Info("Downloading file", name, "from", c.RepoData.Uri)
|
2019-11-22 20:01:38 +00:00
|
|
|
|
|
|
|
file, err := ioutil.TempFile(os.TempDir(), "localclient")
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
//defer os.Remove(file.Name())
|
|
|
|
|
2019-11-22 22:12:03 +00:00
|
|
|
err = helpers.CopyFile(filepath.Join(c.RepoData.Uri, name), file.Name())
|
2019-11-22 20:01:38 +00:00
|
|
|
|
|
|
|
return file.Name(), err
|
|
|
|
}
|