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