filesys_unix.go 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // +build !windows
  2. package system // import "github.com/docker/docker/pkg/system"
  3. import (
  4. "io/ioutil"
  5. "os"
  6. "path/filepath"
  7. )
  8. // MkdirAllWithACL is a wrapper for os.MkdirAll on unix systems.
  9. func MkdirAllWithACL(path string, perm os.FileMode, sddl string) error {
  10. return os.MkdirAll(path, perm)
  11. }
  12. // MkdirAll creates a directory named path along with any necessary parents,
  13. // with permission specified by attribute perm for all dir created.
  14. func MkdirAll(path string, perm os.FileMode) error {
  15. return os.MkdirAll(path, perm)
  16. }
  17. // IsAbs is a platform-specific wrapper for filepath.IsAbs.
  18. func IsAbs(path string) bool {
  19. return filepath.IsAbs(path)
  20. }
  21. // The functions below here are wrappers for the equivalents in the os and ioutils packages.
  22. // They are passthrough on Unix platforms, and only relevant on Windows.
  23. // CreateSequential creates the named file with mode 0666 (before umask), truncating
  24. // it if it already exists. If successful, methods on the returned
  25. // File can be used for I/O; the associated file descriptor has mode
  26. // O_RDWR.
  27. // If there is an error, it will be of type *PathError.
  28. func CreateSequential(name string) (*os.File, error) {
  29. return os.Create(name)
  30. }
  31. // OpenSequential opens the named file for reading. If successful, methods on
  32. // the returned file can be used for reading; the associated file
  33. // descriptor has mode O_RDONLY.
  34. // If there is an error, it will be of type *PathError.
  35. func OpenSequential(name string) (*os.File, error) {
  36. return os.Open(name)
  37. }
  38. // OpenFileSequential is the generalized open call; most users will use Open
  39. // or Create instead. It opens the named file with specified flag
  40. // (O_RDONLY etc.) and perm, (0666 etc.) if applicable. If successful,
  41. // methods on the returned File can be used for I/O.
  42. // If there is an error, it will be of type *PathError.
  43. func OpenFileSequential(name string, flag int, perm os.FileMode) (*os.File, error) {
  44. return os.OpenFile(name, flag, perm)
  45. }
  46. // TempFileSequential creates a new temporary file in the directory dir
  47. // with a name beginning with prefix, opens the file for reading
  48. // and writing, and returns the resulting *os.File.
  49. // If dir is the empty string, TempFile uses the default directory
  50. // for temporary files (see os.TempDir).
  51. // Multiple programs calling TempFile simultaneously
  52. // will not choose the same file. The caller can use f.Name()
  53. // to find the pathname of the file. It is the caller's responsibility
  54. // to remove the file when no longer needed.
  55. func TempFileSequential(dir, prefix string) (f *os.File, err error) {
  56. return ioutil.TempFile(dir, prefix)
  57. }