func (pfs *physicalFS) New(name string, isDirectory bool) (fs.File, error) { fullpath := filepath.Join(pfs.currentRealDirectory, name) log.WithFields(log.Fields{"pfs": pfs, "name": name, "fullpath": fullpath, "isDirectory": isDirectory}).Debug("localFS::physicalFS::New called") createMode := os.FileMode(0770) if isDirectory { // try to create it and else fail err := os.Mkdir(fullpath, createMode) if err != nil { return nil, err } } pfile := physicalFile.New(name, pfs.currentRealDirectory, isDirectory, 0, time.Now(), createMode) if !isDirectory { // create an empty file w, err := pfile.Write() if err != nil { return nil, err } w.Close() } return pfile, nil }
func (pfs *physicalFS) List() ([]fs.File, error) { items, err := ioutil.ReadDir(pfs.currentRealDirectory) if err != nil { return nil, err } var files []fs.File for _, item := range items { files = append(files, physicalFile.New(item.Name(), pfs.currentRealDirectory, item.IsDir(), item.Size(), item.ModTime(), item.Mode())) } return files, nil }
func (pfs *physicalFS) Get(filename string) (fs.File, error) { var fullpath string if filename[0] == '/' { fullpath = filepath.Join(pfs.homeRealDirectory, filename) } else { fullpath = filepath.Join(pfs.currentRealDirectory, filename) } log.WithFields(log.Fields{"pfs": pfs, "filename": filename, "fullpath": fullpath}).Debug("localFS::physicalFS::Get called") f, err := os.Stat(path.Clean(fullpath)) if err != nil { return nil, err } return physicalFile.New(filepath.Base(fullpath), filepath.Dir(fullpath), f.IsDir(), f.Size(), f.ModTime(), f.Mode()), nil }