This commit is contained in:
Andrea Luzzardi 2013-01-28 14:30:05 -08:00
parent 192446e796
commit 333abbf85a
4 changed files with 20 additions and 22 deletions

View File

@ -1,6 +1,7 @@
package docker package docker
import ( import (
"bytes"
"encoding/json" "encoding/json"
"errors" "errors"
"io" "io"
@ -9,10 +10,9 @@ import (
"os" "os"
"os/exec" "os/exec"
"path" "path"
"strings"
"syscall" "syscall"
"time" "time"
"strings"
"bytes"
) )
type Container struct { type Container struct {
@ -33,8 +33,8 @@ type Container struct {
stdout *writeBroadcaster stdout *writeBroadcaster
stderr *writeBroadcaster stderr *writeBroadcaster
stdoutLog *bytes.Buffer stdoutLog *bytes.Buffer
stderrLog *bytes.Buffer stderrLog *bytes.Buffer
} }
type Config struct { type Config struct {
@ -56,8 +56,8 @@ func createContainer(id string, root string, command string, args []string, laye
lxcConfigPath: path.Join(root, "config.lxc"), lxcConfigPath: path.Join(root, "config.lxc"),
stdout: newWriteBroadcaster(), stdout: newWriteBroadcaster(),
stderr: newWriteBroadcaster(), stderr: newWriteBroadcaster(),
stdoutLog: new(bytes.Buffer), stdoutLog: new(bytes.Buffer),
stderrLog: new(bytes.Buffer), stderrLog: new(bytes.Buffer),
} }
container.stdout.AddWriter(NopWriteCloser(container.stdoutLog)) container.stdout.AddWriter(NopWriteCloser(container.stdoutLog))
container.stderr.AddWriter(NopWriteCloser(container.stderrLog)) container.stderr.AddWriter(NopWriteCloser(container.stderrLog))
@ -83,8 +83,8 @@ func loadContainer(containerPath string) (*Container, error) {
return nil, err return nil, err
} }
container := &Container{ container := &Container{
stdout: newWriteBroadcaster(), stdout: newWriteBroadcaster(),
stderr: newWriteBroadcaster(), stderr: newWriteBroadcaster(),
stdoutLog: new(bytes.Buffer), stdoutLog: new(bytes.Buffer),
stderrLog: new(bytes.Buffer), stderrLog: new(bytes.Buffer),
} }
@ -98,7 +98,6 @@ func loadContainer(containerPath string) (*Container, error) {
return container, nil return container, nil
} }
func (container *Container) Cmd() *exec.Cmd { func (container *Container) Cmd() *exec.Cmd {
return container.cmd return container.cmd
} }
@ -135,7 +134,7 @@ func (container *Container) SetUserData(key, value string) error {
return container.saveUserData(data) return container.saveUserData(data)
} }
func (container *Container) GetUserData(key string) (string) { func (container *Container) GetUserData(key string) string {
data, err := container.loadUserData() data, err := container.loadUserData()
if err != nil { if err != nil {
return "" return ""
@ -146,7 +145,6 @@ func (container *Container) GetUserData(key string) (string) {
return "" return ""
} }
func (container *Container) save() (err error) { func (container *Container) save() (err error) {
data, err := json.Marshal(container) data, err := json.Marshal(container)
if err != nil { if err != nil {
@ -226,7 +224,6 @@ func (container *Container) StdoutLog() io.Reader {
return strings.NewReader(container.stdoutLog.String()) return strings.NewReader(container.stdoutLog.String())
} }
func (container *Container) StderrPipe() (io.ReadCloser, error) { func (container *Container) StderrPipe() (io.ReadCloser, error) {
reader, writer := io.Pipe() reader, writer := io.Pipe()
container.stderr.AddWriter(writer) container.stderr.AddWriter(writer)

View File

@ -3,13 +3,13 @@ package docker
import ( import (
"errors" "errors"
"fmt" "fmt"
"io"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
"syscall" "syscall"
"time" "time"
"io"
"io/ioutil"
) )
type Filesystem struct { type Filesystem struct {
@ -104,7 +104,6 @@ func (fs *Filesystem) Tar() (io.Reader, error) {
return Tar(fs.RootFS) return Tar(fs.RootFS)
} }
func (fs *Filesystem) EnsureMounted() error { func (fs *Filesystem) EnsureMounted() error {
if !fs.IsMounted() { if !fs.IsMounted() {
if err := fs.Mount(); err != nil { if err := fs.Mount(); err != nil {
@ -130,9 +129,12 @@ type Change struct {
func (change *Change) String() string { func (change *Change) String() string {
var kind string var kind string
switch change.Kind { switch change.Kind {
case ChangeModify: kind = "C" case ChangeModify:
case ChangeAdd: kind = "A" kind = "C"
case ChangeDelete: kind = "D" case ChangeAdd:
kind = "A"
case ChangeDelete:
kind = "D"
} }
return fmt.Sprintf("%s %s", kind, change.Path) return fmt.Sprintf("%s %s", kind, change.Path)
} }

View File

@ -1,10 +1,10 @@
package docker package docker
import ( import (
"sync"
"time"
"fmt" "fmt"
"github.com/dotcloud/docker/future" "github.com/dotcloud/docker/future"
"sync"
"time"
) )
type State struct { type State struct {
@ -17,7 +17,6 @@ type State struct {
stateChangeCond *sync.Cond stateChangeCond *sync.Cond
} }
func newState() *State { func newState() *State {
lock := new(sync.Mutex) lock := new(sync.Mutex)
return &State{ return &State{

View File

@ -4,8 +4,8 @@ import (
"bytes" "bytes"
"container/list" "container/list"
"io" "io"
"sync"
"os/exec" "os/exec"
"sync"
) )
// Tar generates a tar archive from a filesystem path, and returns it as a stream. // Tar generates a tar archive from a filesystem path, and returns it as a stream.