filesys.go 2.5 KB

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