Merge pull request #8302 from rafecolton/move_archive_package_to_pkg

Move archive package to pkg
This commit is contained in:
unclejack 2014-10-01 18:03:34 +03:00
commit 4424d15f99
36 changed files with 77 additions and 65 deletions

View File

@ -23,16 +23,17 @@ import (
"time"
"github.com/docker/docker/api"
"github.com/docker/docker/archive"
"github.com/docker/docker/dockerversion"
"github.com/docker/docker/engine"
"github.com/docker/docker/graph"
"github.com/docker/docker/nat"
"github.com/docker/docker/opts"
"github.com/docker/docker/pkg/archive"
"github.com/docker/docker/pkg/log"
flag "github.com/docker/docker/pkg/mflag"
"github.com/docker/docker/pkg/parsers"
"github.com/docker/docker/pkg/parsers/filters"
"github.com/docker/docker/pkg/promise"
"github.com/docker/docker/pkg/signal"
"github.com/docker/docker/pkg/term"
"github.com/docker/docker/pkg/timeutils"
@ -648,7 +649,7 @@ func (cli *DockerCli) CmdStart(args ...string) error {
v.Set("stdout", "1")
v.Set("stderr", "1")
cErr = utils.Go(func() error {
cErr = promise.Go(func() error {
return cli.hijack("POST", "/containers/"+cmd.Arg(0)+"/attach?"+v.Encode(), tty, in, cli.out, cli.err, nil, nil)
})
}
@ -2220,7 +2221,7 @@ func (cli *DockerCli) CmdRun(args ...string) error {
}
}
errCh = utils.Go(func() error {
errCh = promise.Go(func() error {
return cli.hijack("POST", "/containers/"+runResult.Get("Id")+"/attach?"+v.Encode(), config.Tty, in, out, stderr, hijacked, nil)
})
} else {
@ -2477,7 +2478,7 @@ func (cli *DockerCli) CmdExec(args ...string) error {
stderr = cli.err
}
}
errCh = utils.Go(func() error {
errCh = promise.Go(func() error {
return cli.hijack("POST", "/exec/"+execID+"/start", execConfig.Tty, in, out, stderr, hijacked, execConfig)
})

View File

@ -14,9 +14,9 @@ import (
"github.com/docker/docker/api"
"github.com/docker/docker/dockerversion"
"github.com/docker/docker/pkg/log"
"github.com/docker/docker/pkg/promise"
"github.com/docker/docker/pkg/stdcopy"
"github.com/docker/docker/pkg/term"
"github.com/docker/docker/utils"
)
func (cli *DockerCli) dial() (net.Conn, error) {
@ -78,7 +78,7 @@ func (cli *DockerCli) hijack(method, path string, setRawTerminal bool, in io.Rea
}
if stdout != nil || stderr != nil {
receiveStdout = utils.Go(func() (err error) {
receiveStdout = promise.Go(func() (err error) {
defer func() {
if in != nil {
if setRawTerminal && cli.isTerminalIn {
@ -104,7 +104,7 @@ func (cli *DockerCli) hijack(method, path string, setRawTerminal bool, in io.Rea
})
}
sendStdin := utils.Go(func() error {
sendStdin := promise.Go(func() error {
if in != nil {
io.Copy(rwc, in)
log.Debugf("[hijack] End of stdin")

View File

@ -1,3 +0,0 @@
This code provides helper functions for dealing with archive files.
**TODO**: Move this to either `pkg` or (if not possible) to `utils`.

View File

@ -18,11 +18,12 @@ import (
"syscall"
"time"
"github.com/docker/docker/archive"
"github.com/docker/docker/daemon"
imagepkg "github.com/docker/docker/image"
"github.com/docker/docker/pkg/archive"
"github.com/docker/docker/pkg/log"
"github.com/docker/docker/pkg/parsers"
"github.com/docker/docker/pkg/promise"
"github.com/docker/docker/pkg/symlink"
"github.com/docker/docker/pkg/system"
"github.com/docker/docker/pkg/tarsum"
@ -516,7 +517,7 @@ func (b *Builder) create() (*daemon.Container, error) {
func (b *Builder) run(c *daemon.Container) error {
var errCh chan error
if b.Verbose {
errCh = utils.Go(func() error {
errCh = promise.Go(func() error {
// FIXME: call the 'attach' job so that daemon.Attach can be made private
//
// FIXME (LK4D4): Also, maybe makes sense to call "logs" job, it is like attach

View File

@ -7,9 +7,9 @@ import (
"os/exec"
"strings"
"github.com/docker/docker/archive"
"github.com/docker/docker/daemon"
"github.com/docker/docker/engine"
"github.com/docker/docker/pkg/archive"
"github.com/docker/docker/pkg/parsers"
"github.com/docker/docker/registry"
"github.com/docker/docker/utils"

View File

@ -10,6 +10,7 @@ import (
"github.com/docker/docker/pkg/ioutils"
"github.com/docker/docker/pkg/jsonlog"
"github.com/docker/docker/pkg/log"
"github.com/docker/docker/pkg/promise"
"github.com/docker/docker/utils"
)
@ -246,7 +247,7 @@ func (daemon *Daemon) Attach(streamConfig *StreamConfig, openStdin, stdinOnce, t
}()
}
return utils.Go(func() error {
return promise.Go(func() error {
defer func() {
if cStdout != nil {
cStdout.Close()

View File

@ -16,17 +16,18 @@ import (
"github.com/docker/libcontainer/devices"
"github.com/docker/libcontainer/label"
"github.com/docker/docker/archive"
"github.com/docker/docker/daemon/execdriver"
"github.com/docker/docker/engine"
"github.com/docker/docker/image"
"github.com/docker/docker/links"
"github.com/docker/docker/nat"
"github.com/docker/docker/pkg/archive"
"github.com/docker/docker/pkg/broadcastwriter"
"github.com/docker/docker/pkg/ioutils"
"github.com/docker/docker/pkg/log"
"github.com/docker/docker/pkg/networkfs/etchosts"
"github.com/docker/docker/pkg/networkfs/resolvconf"
"github.com/docker/docker/pkg/promise"
"github.com/docker/docker/pkg/symlink"
"github.com/docker/docker/runconfig"
"github.com/docker/docker/utils"
@ -1119,7 +1120,7 @@ func (container *Container) waitForStart() error {
// process or until the process is running in the container
select {
case <-container.monitor.startSignal:
case err := <-utils.Go(container.monitor.Start):
case err := <-promise.Go(container.monitor.Start):
return err
}

View File

@ -15,7 +15,6 @@ import (
"github.com/docker/libcontainer/label"
"github.com/docker/docker/archive"
"github.com/docker/docker/daemon/execdriver"
"github.com/docker/docker/daemon/execdriver/execdrivers"
"github.com/docker/docker/daemon/execdriver/lxc"
@ -27,6 +26,7 @@ import (
"github.com/docker/docker/engine"
"github.com/docker/docker/graph"
"github.com/docker/docker/image"
"github.com/docker/docker/pkg/archive"
"github.com/docker/docker/pkg/broadcastwriter"
"github.com/docker/docker/pkg/graphdb"
"github.com/docker/docker/pkg/ioutils"

View File

@ -15,6 +15,7 @@ import (
"github.com/docker/docker/pkg/broadcastwriter"
"github.com/docker/docker/pkg/ioutils"
"github.com/docker/docker/pkg/log"
"github.com/docker/docker/pkg/promise"
"github.com/docker/docker/runconfig"
"github.com/docker/docker/utils"
)
@ -254,7 +255,7 @@ func (container *Container) Exec(execConfig *execConfig) error {
// We use a callback here instead of a goroutine and an chan for
// syncronization purposes
cErr := utils.Go(func() error { return container.monitorExec(execConfig, callback) })
cErr := promise.Go(func() error { return container.monitorExec(execConfig, callback) })
// Exec should not return until the process is actually running
select {

View File

@ -30,8 +30,8 @@ import (
"sync"
"syscall"
"github.com/docker/docker/archive"
"github.com/docker/docker/daemon/graphdriver"
"github.com/docker/docker/pkg/archive"
"github.com/docker/docker/pkg/log"
mountpk "github.com/docker/docker/pkg/mount"
"github.com/docker/docker/utils"

View File

@ -4,8 +4,8 @@ import (
"crypto/sha256"
"encoding/hex"
"fmt"
"github.com/docker/docker/archive"
"github.com/docker/docker/daemon/graphdriver"
"github.com/docker/docker/pkg/archive"
"io/ioutil"
"os"
"path"

View File

@ -6,7 +6,7 @@ import (
"os"
"path"
"github.com/docker/docker/archive"
"github.com/docker/docker/pkg/archive"
"github.com/docker/docker/pkg/mount"
)

View File

@ -4,7 +4,7 @@ import (
"fmt"
"time"
"github.com/docker/docker/archive"
"github.com/docker/docker/pkg/archive"
"github.com/docker/docker/pkg/ioutils"
"github.com/docker/docker/pkg/log"
"github.com/docker/docker/utils"

View File

@ -9,8 +9,8 @@ import (
"strings"
"syscall"
"github.com/docker/docker/archive"
"github.com/docker/docker/daemon/execdriver"
"github.com/docker/docker/pkg/archive"
"github.com/docker/docker/pkg/log"
"github.com/docker/docker/pkg/symlink"
"github.com/docker/docker/volumes"

View File

@ -7,8 +7,8 @@ import (
"os"
"path"
"github.com/docker/docker/archive"
"github.com/docker/docker/engine"
"github.com/docker/docker/pkg/archive"
"github.com/docker/docker/pkg/log"
"github.com/docker/docker/pkg/parsers"
)

View File

@ -12,10 +12,10 @@ import (
"syscall"
"time"
"github.com/docker/docker/archive"
"github.com/docker/docker/daemon/graphdriver"
"github.com/docker/docker/dockerversion"
"github.com/docker/docker/image"
"github.com/docker/docker/pkg/archive"
"github.com/docker/docker/pkg/log"
"github.com/docker/docker/pkg/truncindex"
"github.com/docker/docker/runconfig"

View File

@ -4,8 +4,8 @@ import (
"net/http"
"net/url"
"github.com/docker/docker/archive"
"github.com/docker/docker/engine"
"github.com/docker/docker/pkg/archive"
"github.com/docker/docker/utils"
)

View File

@ -7,9 +7,9 @@ import (
"os"
"path"
"github.com/docker/docker/archive"
"github.com/docker/docker/engine"
"github.com/docker/docker/image"
"github.com/docker/docker/pkg/archive"
"github.com/docker/docker/pkg/log"
)

View File

@ -7,8 +7,8 @@ import (
"os"
"path"
"github.com/docker/docker/archive"
"github.com/docker/docker/engine"
"github.com/docker/docker/pkg/archive"
"github.com/docker/docker/pkg/log"
"github.com/docker/docker/registry"
"github.com/docker/docker/utils"

View File

@ -9,7 +9,7 @@ import (
"strconv"
"time"
"github.com/docker/docker/archive"
"github.com/docker/docker/pkg/archive"
"github.com/docker/docker/pkg/log"
"github.com/docker/docker/runconfig"
"github.com/docker/docker/utils"

View File

@ -11,7 +11,7 @@ import (
"testing"
"time"
"github.com/docker/docker/archive"
"github.com/docker/docker/pkg/archive"
)
func TestBuildCacheADD(t *testing.T) {

View File

@ -2,11 +2,11 @@ package docker
import (
"errors"
"github.com/docker/docker/archive"
"github.com/docker/docker/daemon/graphdriver"
"github.com/docker/docker/dockerversion"
"github.com/docker/docker/graph"
"github.com/docker/docker/image"
"github.com/docker/docker/pkg/archive"
"github.com/docker/docker/utils"
"io"
"io/ioutil"

1
pkg/archive/README.md Normal file
View File

@ -0,0 +1 @@
This code provides helper functions for dealing with archive files.

View File

@ -18,10 +18,11 @@ import (
"github.com/docker/docker/vendor/src/code.google.com/p/go/src/pkg/archive/tar"
"github.com/docker/docker/pkg/fileutils"
"github.com/docker/docker/pkg/log"
"github.com/docker/docker/pkg/pools"
"github.com/docker/docker/pkg/promise"
"github.com/docker/docker/pkg/system"
"github.com/docker/docker/utils"
)
type (
@ -370,7 +371,7 @@ func TarWithOptions(srcPath string, options *TarOptions) (io.ReadCloser, error)
return nil
}
skip, err := utils.Matches(relFilePath, options.Excludes)
skip, err := fileutils.Matches(relFilePath, options.Excludes)
if err != nil {
log.Debugf("Error matching %s", relFilePath, err)
return err
@ -581,7 +582,7 @@ func CopyFileWithTar(src, dst string) (err error) {
}
r, w := io.Pipe()
errC := utils.Go(func() error {
errC := promise.Go(func() error {
defer w.Close()
srcF, err := os.Open(src)

View File

@ -0,0 +1,26 @@
package fileutils
import (
"github.com/docker/docker/pkg/log"
"path/filepath"
)
// Matches returns true if relFilePath matches any of the patterns
func Matches(relFilePath string, patterns []string) (bool, error) {
for _, exclude := range patterns {
matched, err := filepath.Match(exclude, relFilePath)
if err != nil {
log.Errorf("Error matching: %s (pattern: %s)", relFilePath, exclude)
return false, err
}
if matched {
if filepath.Clean(relFilePath) == "." {
log.Errorf("Can't exclude whole path, excluding pattern: %s", exclude)
continue
}
log.Debugf("Skipping excluded path: %s", relFilePath)
return true, nil
}
}
return false, nil
}

11
pkg/promise/promise.go Normal file
View File

@ -0,0 +1,11 @@
package promise
// Go is a basic promise implementation: it wraps calls a function in a goroutine,
// and returns a channel which will later return the function's return value.
func Go(f func() error) chan error {
ch := make(chan error, 1)
go func() {
ch <- f()
}()
return ch
}

View File

@ -21,6 +21,7 @@ import (
"syscall"
"github.com/docker/docker/dockerversion"
"github.com/docker/docker/pkg/fileutils"
"github.com/docker/docker/pkg/ioutils"
"github.com/docker/docker/pkg/log"
)
@ -30,16 +31,6 @@ type KeyValuePair struct {
Value string
}
// Go is a basic promise implementation: it wraps calls a function in a goroutine,
// and returns a channel which will later return the function's return value.
func Go(f func() error) chan error {
ch := make(chan error, 1)
go func() {
ch <- f()
}()
return ch
}
// Request a given URL and return an io.Reader
func Download(url string) (resp *http.Response, err error) {
if resp, err = http.Get(url); err != nil {
@ -503,7 +494,7 @@ func ValidateContextDirectory(srcPath string, excludes []string) error {
// skip this directory/file if it's not in the path, it won't get added to the context
if relFilePath, err := filepath.Rel(srcPath, filePath); err != nil {
return err
} else if skip, err := Matches(relFilePath, excludes); err != nil {
} else if skip, err := fileutils.Matches(relFilePath, excludes); err != nil {
return err
} else if skip {
if f.IsDir() {
@ -547,23 +538,3 @@ func StringsContainsNoCase(slice []string, s string) bool {
}
return false
}
// Matches returns true if relFilePath matches any of the patterns
func Matches(relFilePath string, patterns []string) (bool, error) {
for _, exclude := range patterns {
matched, err := filepath.Match(exclude, relFilePath)
if err != nil {
log.Errorf("Error matching: %s (pattern: %s)", relFilePath, exclude)
return false, err
}
if matched {
if filepath.Clean(relFilePath) == "." {
log.Errorf("Can't exclude whole path, excluding pattern: %s", exclude)
continue
}
log.Debugf("Skipping excluded path: %s", relFilePath)
return true, nil
}
}
return false, nil
}