runtime_unix.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. //go:build linux
  2. /*
  3. Copyright 2020 Docker Compose CLI authors
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. */
  14. package locker
  15. import (
  16. "os"
  17. "path/filepath"
  18. "strconv"
  19. )
  20. // Based on https://github.com/adrg/xdg
  21. // Licensed under MIT License (MIT)
  22. // Copyright (c) 2014 Adrian-George Bostan <[email protected]>
  23. func osDependentRunDir() (string, error) {
  24. run := filepath.Join("run", "user", strconv.Itoa(os.Getuid()))
  25. if _, err := os.Stat(run); err == nil {
  26. return run, nil
  27. }
  28. // /run/user/$uid is set by pam_systemd, but might not be present, especially in containerized environments
  29. home, err := os.UserHomeDir()
  30. if err != nil {
  31. return "", err
  32. }
  33. return filepath.Join(home, ".docker", "docker-compose"), nil
  34. }