archive.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package daemon // import "github.com/docker/docker/daemon"
  2. import (
  3. "io"
  4. "os"
  5. "github.com/docker/docker/api/types"
  6. "github.com/docker/docker/errdefs"
  7. )
  8. // ContainerCopy performs a deprecated operation of archiving the resource at
  9. // the specified path in the container identified by the given name.
  10. func (daemon *Daemon) ContainerCopy(name string, res string) (io.ReadCloser, error) {
  11. ctr, err := daemon.GetContainer(name)
  12. if err != nil {
  13. return nil, err
  14. }
  15. data, err := daemon.containerCopy(ctr, res)
  16. if err == nil {
  17. return data, nil
  18. }
  19. if os.IsNotExist(err) {
  20. return nil, containerFileNotFound{res, name}
  21. }
  22. return nil, errdefs.System(err)
  23. }
  24. // ContainerStatPath stats the filesystem resource at the specified path in the
  25. // container identified by the given name.
  26. func (daemon *Daemon) ContainerStatPath(name string, path string) (stat *types.ContainerPathStat, err error) {
  27. ctr, err := daemon.GetContainer(name)
  28. if err != nil {
  29. return nil, err
  30. }
  31. stat, err = daemon.containerStatPath(ctr, path)
  32. if err == nil {
  33. return stat, nil
  34. }
  35. if os.IsNotExist(err) {
  36. return nil, containerFileNotFound{path, name}
  37. }
  38. return nil, errdefs.System(err)
  39. }
  40. // ContainerArchivePath creates an archive of the filesystem resource at the
  41. // specified path in the container identified by the given name. Returns a
  42. // tar archive of the resource and whether it was a directory or a single file.
  43. func (daemon *Daemon) ContainerArchivePath(name string, path string) (content io.ReadCloser, stat *types.ContainerPathStat, err error) {
  44. ctr, err := daemon.GetContainer(name)
  45. if err != nil {
  46. return nil, nil, err
  47. }
  48. content, stat, err = daemon.containerArchivePath(ctr, path)
  49. if err == nil {
  50. return content, stat, nil
  51. }
  52. if os.IsNotExist(err) {
  53. return nil, nil, containerFileNotFound{path, name}
  54. }
  55. return nil, nil, errdefs.System(err)
  56. }
  57. // ContainerExtractToDir extracts the given archive to the specified location
  58. // in the filesystem of the container identified by the given name. The given
  59. // path must be of a directory in the container. If it is not, the error will
  60. // be an errdefs.InvalidParameter. If noOverwriteDirNonDir is true then it will
  61. // be an error if unpacking the given content would cause an existing directory
  62. // to be replaced with a non-directory and vice versa.
  63. func (daemon *Daemon) ContainerExtractToDir(name, path string, copyUIDGID, noOverwriteDirNonDir bool, content io.Reader) error {
  64. ctr, err := daemon.GetContainer(name)
  65. if err != nil {
  66. return err
  67. }
  68. err = daemon.containerExtractToDir(ctr, path, copyUIDGID, noOverwriteDirNonDir, content)
  69. if err == nil {
  70. return nil
  71. }
  72. if os.IsNotExist(err) {
  73. return containerFileNotFound{path, name}
  74. }
  75. return errdefs.System(err)
  76. }