mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Move isUrl to utils.IsURL
This commit is contained in:
parent
eaa2183d77
commit
f4a4cfd2cc
2 changed files with 12 additions and 12 deletions
|
@ -164,10 +164,6 @@ func (b *buildFile) CmdCopy(args string) error {
|
||||||
return fmt.Errorf("COPY has been deprecated. Please use ADD instead")
|
return fmt.Errorf("COPY has been deprecated. Please use ADD instead")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *buildFile) isUrl(str string) bool {
|
|
||||||
return strings.HasPrefix(str, "http://") || strings.HasPrefix(str, "https://")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *buildFile) addRemote(container *Container, orig, dest string) error {
|
func (b *buildFile) addRemote(container *Container, orig, dest string) error {
|
||||||
file, err := utils.Download(orig, ioutil.Discard)
|
file, err := utils.Download(orig, ioutil.Discard)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -238,7 +234,7 @@ func (b *buildFile) CmdAdd(args string) error {
|
||||||
}
|
}
|
||||||
defer container.Unmount()
|
defer container.Unmount()
|
||||||
|
|
||||||
if b.isUrl(orig) {
|
if utils.IsURL(orig) {
|
||||||
if err := b.addRemote(container, orig, dest); err != nil {
|
if err := b.addRemote(container, orig, dest); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,7 +70,7 @@ type progressReader struct {
|
||||||
readProgress int // How much has been read so far (bytes)
|
readProgress int // How much has been read so far (bytes)
|
||||||
lastUpdate int // How many bytes read at least update
|
lastUpdate int // How many bytes read at least update
|
||||||
template string // Template to print. Default "%v/%v (%v)"
|
template string // Template to print. Default "%v/%v (%v)"
|
||||||
sf *StreamFormatter
|
sf *StreamFormatter
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *progressReader) Read(p []byte) (n int, err error) {
|
func (r *progressReader) Read(p []byte) (n int, err error) {
|
||||||
|
@ -103,7 +103,7 @@ func (r *progressReader) Close() error {
|
||||||
return io.ReadCloser(r.reader).Close()
|
return io.ReadCloser(r.reader).Close()
|
||||||
}
|
}
|
||||||
func ProgressReader(r io.ReadCloser, size int, output io.Writer, template []byte, sf *StreamFormatter) *progressReader {
|
func ProgressReader(r io.ReadCloser, size int, output io.Writer, template []byte, sf *StreamFormatter) *progressReader {
|
||||||
tpl := string(template)
|
tpl := string(template)
|
||||||
if tpl == "" {
|
if tpl == "" {
|
||||||
tpl = string(sf.FormatProgress("", "%v/%v (%v)"))
|
tpl = string(sf.FormatProgress("", "%v/%v (%v)"))
|
||||||
}
|
}
|
||||||
|
@ -585,7 +585,7 @@ func (sf *StreamFormatter) FormatStatus(format string, a ...interface{}) []byte
|
||||||
sf.used = true
|
sf.used = true
|
||||||
str := fmt.Sprintf(format, a...)
|
str := fmt.Sprintf(format, a...)
|
||||||
if sf.json {
|
if sf.json {
|
||||||
b, err := json.Marshal(&JSONMessage{Status:str});
|
b, err := json.Marshal(&JSONMessage{Status: str})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return sf.FormatError(err)
|
return sf.FormatError(err)
|
||||||
}
|
}
|
||||||
|
@ -597,7 +597,7 @@ func (sf *StreamFormatter) FormatStatus(format string, a ...interface{}) []byte
|
||||||
func (sf *StreamFormatter) FormatError(err error) []byte {
|
func (sf *StreamFormatter) FormatError(err error) []byte {
|
||||||
sf.used = true
|
sf.used = true
|
||||||
if sf.json {
|
if sf.json {
|
||||||
if b, err := json.Marshal(&JSONMessage{Error:err.Error()}); err == nil {
|
if b, err := json.Marshal(&JSONMessage{Error: err.Error()}); err == nil {
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
return []byte("{\"error\":\"format error\"}")
|
return []byte("{\"error\":\"format error\"}")
|
||||||
|
@ -608,10 +608,10 @@ func (sf *StreamFormatter) FormatError(err error) []byte {
|
||||||
func (sf *StreamFormatter) FormatProgress(action, str string) []byte {
|
func (sf *StreamFormatter) FormatProgress(action, str string) []byte {
|
||||||
sf.used = true
|
sf.used = true
|
||||||
if sf.json {
|
if sf.json {
|
||||||
b, err := json.Marshal(&JSONMessage{Status: action, Progress:str})
|
b, err := json.Marshal(&JSONMessage{Status: action, Progress: str})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
return []byte(action + " " + str + "\r")
|
return []byte(action + " " + str + "\r")
|
||||||
|
@ -620,3 +620,7 @@ func (sf *StreamFormatter) FormatProgress(action, str string) []byte {
|
||||||
func (sf *StreamFormatter) Used() bool {
|
func (sf *StreamFormatter) Used() bool {
|
||||||
return sf.used
|
return sf.used
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func IsURL(str string) bool {
|
||||||
|
return strings.HasPrefix(str, "http://") || strings.HasPrefix(str, "https://")
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue