utils.go 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. package main
  2. import (
  3. "io"
  4. "os"
  5. "os/exec"
  6. "time"
  7. "github.com/docker/docker/pkg/integration"
  8. "github.com/docker/docker/pkg/integration/cmd"
  9. )
  10. func getPrefixAndSlashFromDaemonPlatform() (prefix, slash string) {
  11. if daemonPlatform == "windows" {
  12. return "c:", `\`
  13. }
  14. return "", "/"
  15. }
  16. // TODO: update code to call cmd.RunCmd directly, and remove this function
  17. func runCommandWithOutput(execCmd *exec.Cmd) (string, int, error) {
  18. result := cmd.RunCmd(transformCmd(execCmd))
  19. return result.Combined(), result.ExitCode, result.Error
  20. }
  21. // TODO: update code to call cmd.RunCmd directly, and remove this function
  22. func runCommandWithStdoutStderr(execCmd *exec.Cmd) (string, string, int, error) {
  23. result := cmd.RunCmd(transformCmd(execCmd))
  24. return result.Stdout(), result.Stderr(), result.ExitCode, result.Error
  25. }
  26. // TODO: update code to call cmd.RunCmd directly, and remove this function
  27. func runCommand(execCmd *exec.Cmd) (exitCode int, err error) {
  28. result := cmd.RunCmd(transformCmd(execCmd))
  29. return result.ExitCode, result.Error
  30. }
  31. // Temporary shim for migrating commands to the new function
  32. func transformCmd(execCmd *exec.Cmd) cmd.Cmd {
  33. return cmd.Cmd{
  34. Command: execCmd.Args,
  35. Env: execCmd.Env,
  36. Dir: execCmd.Dir,
  37. Stdin: execCmd.Stdin,
  38. Stdout: execCmd.Stdout,
  39. }
  40. }
  41. func runCommandPipelineWithOutput(cmds ...*exec.Cmd) (output string, exitCode int, err error) {
  42. return integration.RunCommandPipelineWithOutput(cmds...)
  43. }
  44. func convertSliceOfStringsToMap(input []string) map[string]struct{} {
  45. return integration.ConvertSliceOfStringsToMap(input)
  46. }
  47. func compareDirectoryEntries(e1 []os.FileInfo, e2 []os.FileInfo) error {
  48. return integration.CompareDirectoryEntries(e1, e2)
  49. }
  50. func listTar(f io.Reader) ([]string, error) {
  51. return integration.ListTar(f)
  52. }
  53. func randomTmpDirPath(s string, platform string) string {
  54. return integration.RandomTmpDirPath(s, platform)
  55. }
  56. func consumeWithSpeed(reader io.Reader, chunkSize int, interval time.Duration, stop chan bool) (n int, err error) {
  57. return integration.ConsumeWithSpeed(reader, chunkSize, interval, stop)
  58. }
  59. func parseCgroupPaths(procCgroupData string) map[string]string {
  60. return integration.ParseCgroupPaths(procCgroupData)
  61. }
  62. func runAtDifferentDate(date time.Time, block func()) {
  63. integration.RunAtDifferentDate(date, block)
  64. }