It's the only place where it's used.
Signed-off-by: David Calavera <david.calavera@gmail.com>
| ... | ... |
@@ -322,3 +322,68 @@ func (daemon *Daemon) containerExtractToDir(container *Container, path string, n |
| 322 | 322 |
|
| 323 | 323 |
return nil |
| 324 | 324 |
} |
| 325 |
+ |
|
| 326 |
+func (daemon *Daemon) containerCopy(container *Container, resource string) (rc io.ReadCloser, err error) {
|
|
| 327 |
+ container.Lock() |
|
| 328 |
+ |
|
| 329 |
+ defer func() {
|
|
| 330 |
+ if err != nil {
|
|
| 331 |
+ // Wait to unlock the container until the archive is fully read |
|
| 332 |
+ // (see the ReadCloseWrapper func below) or if there is an error |
|
| 333 |
+ // before that occurs. |
|
| 334 |
+ container.Unlock() |
|
| 335 |
+ } |
|
| 336 |
+ }() |
|
| 337 |
+ |
|
| 338 |
+ if err := daemon.Mount(container); err != nil {
|
|
| 339 |
+ return nil, err |
|
| 340 |
+ } |
|
| 341 |
+ |
|
| 342 |
+ defer func() {
|
|
| 343 |
+ if err != nil {
|
|
| 344 |
+ // unmount any volumes |
|
| 345 |
+ container.unmountVolumes(true) |
|
| 346 |
+ // unmount the container's rootfs |
|
| 347 |
+ daemon.Unmount(container) |
|
| 348 |
+ } |
|
| 349 |
+ }() |
|
| 350 |
+ |
|
| 351 |
+ if err := container.mountVolumes(); err != nil {
|
|
| 352 |
+ return nil, err |
|
| 353 |
+ } |
|
| 354 |
+ |
|
| 355 |
+ basePath, err := container.GetResourcePath(resource) |
|
| 356 |
+ if err != nil {
|
|
| 357 |
+ return nil, err |
|
| 358 |
+ } |
|
| 359 |
+ stat, err := os.Stat(basePath) |
|
| 360 |
+ if err != nil {
|
|
| 361 |
+ return nil, err |
|
| 362 |
+ } |
|
| 363 |
+ var filter []string |
|
| 364 |
+ if !stat.IsDir() {
|
|
| 365 |
+ d, f := filepath.Split(basePath) |
|
| 366 |
+ basePath = d |
|
| 367 |
+ filter = []string{f}
|
|
| 368 |
+ } else {
|
|
| 369 |
+ filter = []string{filepath.Base(basePath)}
|
|
| 370 |
+ basePath = filepath.Dir(basePath) |
|
| 371 |
+ } |
|
| 372 |
+ archive, err := archive.TarWithOptions(basePath, &archive.TarOptions{
|
|
| 373 |
+ Compression: archive.Uncompressed, |
|
| 374 |
+ IncludeFiles: filter, |
|
| 375 |
+ }) |
|
| 376 |
+ if err != nil {
|
|
| 377 |
+ return nil, err |
|
| 378 |
+ } |
|
| 379 |
+ |
|
| 380 |
+ reader := ioutils.NewReadCloserWrapper(archive, func() error {
|
|
| 381 |
+ err := archive.Close() |
|
| 382 |
+ container.unmountVolumes(true) |
|
| 383 |
+ daemon.Unmount(container) |
|
| 384 |
+ container.Unlock() |
|
| 385 |
+ return err |
|
| 386 |
+ }) |
|
| 387 |
+ daemon.logContainerEvent(container, "copy") |
|
| 388 |
+ return reader, nil |
|
| 389 |
+} |
| ... | ... |
@@ -20,7 +20,6 @@ import ( |
| 20 | 20 |
"github.com/docker/docker/daemon/logger/jsonfilelog" |
| 21 | 21 |
"github.com/docker/docker/daemon/network" |
| 22 | 22 |
derr "github.com/docker/docker/errors" |
| 23 |
- "github.com/docker/docker/pkg/archive" |
|
| 24 | 23 |
"github.com/docker/docker/pkg/broadcaster" |
| 25 | 24 |
"github.com/docker/docker/pkg/fileutils" |
| 26 | 25 |
"github.com/docker/docker/pkg/ioutils" |
| ... | ... |
@@ -306,71 +305,6 @@ func validateID(id string) error {
|
| 306 | 306 |
return nil |
| 307 | 307 |
} |
| 308 | 308 |
|
| 309 |
-func (daemon *Daemon) containerCopy(container *Container, resource string) (rc io.ReadCloser, err error) {
|
|
| 310 |
- container.Lock() |
|
| 311 |
- |
|
| 312 |
- defer func() {
|
|
| 313 |
- if err != nil {
|
|
| 314 |
- // Wait to unlock the container until the archive is fully read |
|
| 315 |
- // (see the ReadCloseWrapper func below) or if there is an error |
|
| 316 |
- // before that occurs. |
|
| 317 |
- container.Unlock() |
|
| 318 |
- } |
|
| 319 |
- }() |
|
| 320 |
- |
|
| 321 |
- if err := daemon.Mount(container); err != nil {
|
|
| 322 |
- return nil, err |
|
| 323 |
- } |
|
| 324 |
- |
|
| 325 |
- defer func() {
|
|
| 326 |
- if err != nil {
|
|
| 327 |
- // unmount any volumes |
|
| 328 |
- container.unmountVolumes(true) |
|
| 329 |
- // unmount the container's rootfs |
|
| 330 |
- daemon.Unmount(container) |
|
| 331 |
- } |
|
| 332 |
- }() |
|
| 333 |
- |
|
| 334 |
- if err := container.mountVolumes(); err != nil {
|
|
| 335 |
- return nil, err |
|
| 336 |
- } |
|
| 337 |
- |
|
| 338 |
- basePath, err := container.GetResourcePath(resource) |
|
| 339 |
- if err != nil {
|
|
| 340 |
- return nil, err |
|
| 341 |
- } |
|
| 342 |
- stat, err := os.Stat(basePath) |
|
| 343 |
- if err != nil {
|
|
| 344 |
- return nil, err |
|
| 345 |
- } |
|
| 346 |
- var filter []string |
|
| 347 |
- if !stat.IsDir() {
|
|
| 348 |
- d, f := filepath.Split(basePath) |
|
| 349 |
- basePath = d |
|
| 350 |
- filter = []string{f}
|
|
| 351 |
- } else {
|
|
| 352 |
- filter = []string{filepath.Base(basePath)}
|
|
| 353 |
- basePath = filepath.Dir(basePath) |
|
| 354 |
- } |
|
| 355 |
- archive, err := archive.TarWithOptions(basePath, &archive.TarOptions{
|
|
| 356 |
- Compression: archive.Uncompressed, |
|
| 357 |
- IncludeFiles: filter, |
|
| 358 |
- }) |
|
| 359 |
- if err != nil {
|
|
| 360 |
- return nil, err |
|
| 361 |
- } |
|
| 362 |
- |
|
| 363 |
- reader := ioutils.NewReadCloserWrapper(archive, func() error {
|
|
| 364 |
- err := archive.Close() |
|
| 365 |
- container.unmountVolumes(true) |
|
| 366 |
- daemon.Unmount(container) |
|
| 367 |
- container.Unlock() |
|
| 368 |
- return err |
|
| 369 |
- }) |
|
| 370 |
- daemon.logContainerEvent(container, "copy") |
|
| 371 |
- return reader, nil |
|
| 372 |
-} |
|
| 373 |
- |
|
| 374 | 309 |
// Returns true if the container exposes a certain port |
| 375 | 310 |
func (container *Container) exposes(p nat.Port) bool {
|
| 376 | 311 |
_, exists := container.Config.ExposedPorts[p] |