func vfsCreateWrite(fs vfs.VFS, filePath string) (vfs.WFile, error) { if err := vfs.MkdirAll(fs, path.Dir(filePath), 0700); err != nil { return nil, err } return fs.OpenFile(filePath, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0600) }
func (m *Manager) Create(name string, overwrite bool) (io.WriteCloser, error) { flags := os.O_WRONLY | os.O_CREATE if !overwrite { flags |= os.O_EXCL } f, err := m.fs.OpenFile(name, flags, 0644) if err != nil && vfs.IsNotExist(err) { // Try to create the directory if err2 := vfs.MkdirAll(m.fs, path.Dir(name), 0755); err2 == nil { f, err = m.fs.OpenFile(name, flags, 0644) } } return f, err }
func (c *cache) vfsWrite(path string, r io.Reader) error { if err := vfs.MkdirAll(c.fs, pathutil.Dir(path), 0700); err != nil { return err } f, err := c.fs.OpenFile(path, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0600) if err != nil { return err } defer f.Close() if _, err := io.Copy(f, r); err != nil { return err } return nil }