예제 #1
0
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)
}
예제 #2
0
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
}
예제 #3
0
파일: cache.go 프로젝트: rakoo/httpcache
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
}