2013-07-08 23:29:38 -04:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
2018-01-22 18:32:33 -05:00
|
|
|
"context"
|
2013-07-08 23:29:38 -04:00
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"log"
|
|
|
|
"os"
|
2015-11-06 06:14:53 -05:00
|
|
|
"path"
|
2013-07-08 23:29:38 -04:00
|
|
|
"path/filepath"
|
2014-04-29 15:27:34 -04:00
|
|
|
"strings"
|
2017-03-28 21:29:55 -04:00
|
|
|
|
2018-01-19 19:18:44 -05:00
|
|
|
"github.com/hashicorp/packer/helper/multistep"
|
2017-04-04 16:39:01 -04:00
|
|
|
"github.com/hashicorp/packer/packer"
|
2018-12-12 09:45:00 -05:00
|
|
|
"github.com/hashicorp/packer/packer/tmp"
|
2017-03-28 21:29:55 -04:00
|
|
|
"github.com/mitchellh/go-fs"
|
|
|
|
"github.com/mitchellh/go-fs/fat"
|
2013-07-08 23:29:38 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// StepCreateFloppy will create a floppy disk with the given files.
|
|
|
|
type StepCreateFloppy struct {
|
2016-10-11 17:43:50 -04:00
|
|
|
Files []string
|
2016-09-28 00:31:42 -04:00
|
|
|
Directories []string
|
2013-07-08 23:56:23 -04:00
|
|
|
|
|
|
|
floppyPath string
|
2014-04-29 15:27:34 -04:00
|
|
|
|
|
|
|
FilesAdded map[string]bool
|
2013-07-08 23:29:38 -04:00
|
|
|
}
|
|
|
|
|
2019-03-29 11:50:02 -04:00
|
|
|
func (s *StepCreateFloppy) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
2016-09-28 00:31:42 -04:00
|
|
|
if len(s.Files) == 0 && len(s.Directories) == 0 {
|
2013-07-08 23:29:38 -04:00
|
|
|
log.Println("No floppy files specified. Floppy disk will not be made.")
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
2014-04-29 15:27:34 -04:00
|
|
|
s.FilesAdded = make(map[string]bool)
|
|
|
|
|
2013-08-31 15:17:59 -04:00
|
|
|
ui := state.Get("ui").(packer.Ui)
|
2013-07-08 23:29:38 -04:00
|
|
|
ui.Say("Creating floppy disk...")
|
|
|
|
|
|
|
|
// Create a temporary file to be our floppy drive
|
2018-12-12 09:45:00 -05:00
|
|
|
floppyF, err := tmp.File("packer")
|
2013-07-08 23:29:38 -04:00
|
|
|
if err != nil {
|
2013-08-31 15:17:59 -04:00
|
|
|
state.Put("error",
|
|
|
|
fmt.Errorf("Error creating temporary file for floppy: %s", err))
|
2013-07-08 23:29:38 -04:00
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
defer floppyF.Close()
|
|
|
|
|
2013-07-08 23:56:23 -04:00
|
|
|
// Set the path so we can remove it later
|
|
|
|
s.floppyPath = floppyF.Name()
|
|
|
|
|
2014-04-29 15:27:34 -04:00
|
|
|
log.Printf("Floppy path: %s", s.floppyPath)
|
2013-07-08 23:29:38 -04:00
|
|
|
|
|
|
|
// Set the size of the file to be a floppy sized
|
|
|
|
if err := floppyF.Truncate(1440 * 1024); err != nil {
|
2013-08-31 15:17:59 -04:00
|
|
|
state.Put("error", fmt.Errorf("Error creating floppy: %s", err))
|
2013-07-08 23:29:38 -04:00
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
|
|
|
// BlockDevice backed by the file for our filesystem
|
|
|
|
log.Println("Initializing block device backed by temporary file")
|
|
|
|
device, err := fs.NewFileDisk(floppyF)
|
|
|
|
if err != nil {
|
2013-08-31 15:17:59 -04:00
|
|
|
state.Put("error", fmt.Errorf("Error creating floppy: %s", err))
|
2013-07-08 23:29:38 -04:00
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
|
|
|
// Format the block device so it contains a valid FAT filesystem
|
|
|
|
log.Println("Formatting the block device with a FAT filesystem...")
|
|
|
|
formatConfig := &fat.SuperFloppyConfig{
|
|
|
|
FATType: fat.FAT12,
|
|
|
|
Label: "packer",
|
|
|
|
OEMName: "packer",
|
|
|
|
}
|
2014-04-17 17:34:55 -04:00
|
|
|
if err := fat.FormatSuperFloppy(device, formatConfig); err != nil {
|
2013-08-31 15:17:59 -04:00
|
|
|
state.Put("error", fmt.Errorf("Error creating floppy: %s", err))
|
2013-07-08 23:29:38 -04:00
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
|
|
|
// The actual FAT filesystem
|
|
|
|
log.Println("Initializing FAT filesystem on block device")
|
|
|
|
fatFs, err := fat.New(device)
|
|
|
|
if err != nil {
|
2013-08-31 15:17:59 -04:00
|
|
|
state.Put("error", fmt.Errorf("Error creating floppy: %s", err))
|
2013-07-08 23:29:38 -04:00
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
2016-03-05 02:40:16 -05:00
|
|
|
// Get the root directory to the filesystem and create a cache for any directories within
|
2013-07-08 23:29:38 -04:00
|
|
|
log.Println("Reading the root directory from the filesystem")
|
|
|
|
rootDir, err := fatFs.RootDir()
|
|
|
|
if err != nil {
|
2013-08-31 15:17:59 -04:00
|
|
|
state.Put("error", fmt.Errorf("Error creating floppy: %s", err))
|
2013-07-08 23:29:38 -04:00
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
2016-03-05 02:40:16 -05:00
|
|
|
cache := fsDirectoryCache(rootDir)
|
|
|
|
|
|
|
|
// Utility functions for walking through a directory grabbing all files flatly
|
|
|
|
globFiles := func(files []string, list chan string) {
|
2016-10-11 17:43:50 -04:00
|
|
|
for _, filename := range files {
|
2017-03-28 21:29:55 -04:00
|
|
|
if strings.ContainsAny(filename, "*?[") {
|
2016-10-11 17:43:50 -04:00
|
|
|
matches, _ := filepath.Glob(filename)
|
|
|
|
if err != nil {
|
|
|
|
continue
|
|
|
|
}
|
2016-03-05 02:40:16 -05:00
|
|
|
|
2016-10-11 17:43:50 -04:00
|
|
|
for _, match := range matches {
|
2016-03-05 02:40:16 -05:00
|
|
|
list <- match
|
|
|
|
}
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
list <- filename
|
|
|
|
}
|
|
|
|
close(list)
|
|
|
|
}
|
|
|
|
|
|
|
|
var crawlDirectoryFiles []string
|
|
|
|
crawlDirectory := func(path string, info os.FileInfo, err error) error {
|
2017-01-26 19:32:21 -05:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-03-05 02:40:16 -05:00
|
|
|
if !info.IsDir() {
|
|
|
|
crawlDirectoryFiles = append(crawlDirectoryFiles, path)
|
|
|
|
ui.Message(fmt.Sprintf("Adding file: %s", path))
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
crawlDirectoryFiles = []string{}
|
|
|
|
|
|
|
|
// Collect files and copy them flatly...because floppy_files is broken on purpose.
|
|
|
|
var filelist chan string
|
|
|
|
filelist = make(chan string)
|
|
|
|
go globFiles(s.Files, filelist)
|
|
|
|
|
|
|
|
ui.Message("Copying files flatly from floppy_files")
|
|
|
|
for {
|
|
|
|
filename, ok := <-filelist
|
2016-10-11 17:43:50 -04:00
|
|
|
if !ok {
|
|
|
|
break
|
|
|
|
}
|
2016-03-05 02:40:16 -05:00
|
|
|
|
2016-10-11 17:43:50 -04:00
|
|
|
finfo, err := os.Stat(filename)
|
2016-03-05 02:40:16 -05:00
|
|
|
if err != nil {
|
|
|
|
state.Put("error", fmt.Errorf("Error trying to stat : %s : %s", filename, err))
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
|
|
|
// walk through directory adding files to the root of the fs
|
|
|
|
if finfo.IsDir() {
|
|
|
|
ui.Message(fmt.Sprintf("Copying directory: %s", filename))
|
|
|
|
|
|
|
|
err := filepath.Walk(filename, crawlDirectory)
|
|
|
|
if err != nil {
|
|
|
|
state.Put("error", fmt.Errorf("Error adding file from floppy_files : %s : %s", filename, err))
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
2016-10-11 17:43:50 -04:00
|
|
|
for _, crawlfilename := range crawlDirectoryFiles {
|
2018-01-19 14:34:01 -05:00
|
|
|
if err = s.Add(cache, crawlfilename); err != nil {
|
|
|
|
state.Put("error", fmt.Errorf("Error adding file from floppy_files : %s : %s", filename, err))
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
2016-03-05 02:40:16 -05:00
|
|
|
s.FilesAdded[crawlfilename] = true
|
|
|
|
}
|
|
|
|
|
|
|
|
crawlDirectoryFiles = []string{}
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// add just a single file
|
|
|
|
ui.Message(fmt.Sprintf("Copying file: %s", filename))
|
2018-01-19 14:34:01 -05:00
|
|
|
if err = s.Add(cache, filename); err != nil {
|
|
|
|
state.Put("error", fmt.Errorf("Error adding file from floppy_files : %s : %s", filename, err))
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
2016-03-05 02:40:16 -05:00
|
|
|
s.FilesAdded[filename] = true
|
|
|
|
}
|
|
|
|
ui.Message("Done copying files from floppy_files")
|
2013-07-08 23:29:38 -04:00
|
|
|
|
2015-11-06 06:14:53 -05:00
|
|
|
// Collect all paths (expanding wildcards) into pathqueue
|
2016-09-12 13:07:35 -04:00
|
|
|
ui.Message("Collecting paths from floppy_dirs")
|
2015-11-06 06:14:53 -05:00
|
|
|
var pathqueue []string
|
2016-10-11 17:43:50 -04:00
|
|
|
for _, filename := range s.Directories {
|
2017-03-28 21:29:55 -04:00
|
|
|
if strings.ContainsAny(filename, "*?[") {
|
2016-10-11 17:43:50 -04:00
|
|
|
matches, err := filepath.Glob(filename)
|
2015-11-06 06:14:53 -05:00
|
|
|
if err != nil {
|
|
|
|
state.Put("error", fmt.Errorf("Error adding path %s to floppy: %s", filename, err))
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
2016-10-11 17:43:50 -04:00
|
|
|
for _, filename := range matches {
|
2015-11-06 06:14:53 -05:00
|
|
|
pathqueue = append(pathqueue, filename)
|
|
|
|
}
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
pathqueue = append(pathqueue, filename)
|
|
|
|
}
|
2016-09-12 13:07:35 -04:00
|
|
|
ui.Message(fmt.Sprintf("Resulting paths from floppy_dirs : %v", pathqueue))
|
2015-11-06 06:14:53 -05:00
|
|
|
|
|
|
|
// Go over each path in pathqueue and copy it.
|
2016-10-11 17:43:50 -04:00
|
|
|
for _, src := range pathqueue {
|
2016-03-05 02:40:16 -05:00
|
|
|
ui.Message(fmt.Sprintf("Recursively copying : %s", src))
|
|
|
|
err = s.Add(cache, src)
|
2015-11-06 06:14:53 -05:00
|
|
|
if err != nil {
|
|
|
|
state.Put("error", fmt.Errorf("Error adding path %s to floppy: %s", src, err))
|
2013-07-08 23:29:38 -04:00
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
}
|
2016-09-12 13:07:35 -04:00
|
|
|
ui.Message("Done copying paths from floppy_dirs")
|
2013-07-08 23:29:38 -04:00
|
|
|
|
|
|
|
// Set the path to the floppy so it can be used later
|
2013-08-31 15:17:59 -04:00
|
|
|
state.Put("floppy_path", s.floppyPath)
|
2013-07-08 23:29:38 -04:00
|
|
|
|
2013-07-09 00:24:09 -04:00
|
|
|
return multistep.ActionContinue
|
2013-07-08 23:29:38 -04:00
|
|
|
}
|
|
|
|
|
2016-03-05 02:40:16 -05:00
|
|
|
func (s *StepCreateFloppy) Add(dircache directoryCache, src string) error {
|
2016-10-11 17:43:50 -04:00
|
|
|
finfo, err := os.Stat(src)
|
2014-04-29 15:27:34 -04:00
|
|
|
if err != nil {
|
2015-11-06 06:14:53 -05:00
|
|
|
return fmt.Errorf("Error adding path to floppy: %s", err)
|
2014-04-29 15:27:34 -04:00
|
|
|
}
|
|
|
|
|
2015-11-06 06:14:53 -05:00
|
|
|
// add a file
|
|
|
|
if !finfo.IsDir() {
|
|
|
|
inputF, err := os.Open(src)
|
2016-10-11 17:43:50 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2015-11-06 06:14:53 -05:00
|
|
|
defer inputF.Close()
|
2014-04-29 15:27:34 -04:00
|
|
|
|
2016-10-11 17:43:50 -04:00
|
|
|
d, err := dircache("")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2014-04-29 15:27:34 -04:00
|
|
|
|
2016-10-11 20:16:26 -04:00
|
|
|
entry, err := d.AddFile(path.Base(filepath.ToSlash(src)))
|
2016-10-11 17:43:50 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2014-04-29 15:27:34 -04:00
|
|
|
|
2016-10-11 17:43:50 -04:00
|
|
|
fatFile, err := entry.File()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2014-04-29 15:27:34 -04:00
|
|
|
|
2016-10-11 17:43:50 -04:00
|
|
|
_, err = io.Copy(fatFile, inputF)
|
2015-11-06 06:14:53 -05:00
|
|
|
s.FilesAdded[src] = true
|
|
|
|
return err
|
|
|
|
}
|
2014-04-29 15:27:34 -04:00
|
|
|
|
2015-11-06 06:14:53 -05:00
|
|
|
// add a directory and it's subdirectories
|
|
|
|
basedirectory := filepath.Join(src, "..")
|
|
|
|
visit := func(pathname string, fi os.FileInfo, err error) error {
|
2016-10-11 17:43:50 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2015-11-06 06:14:53 -05:00
|
|
|
if fi.Mode().IsDir() {
|
2016-10-11 17:43:50 -04:00
|
|
|
base, err := removeBase(basedirectory, pathname)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
_, err = dircache(filepath.ToSlash(base))
|
2014-04-29 15:27:34 -04:00
|
|
|
return err
|
|
|
|
}
|
2016-10-11 20:16:26 -04:00
|
|
|
directory, filename := filepath.Split(filepath.ToSlash(pathname))
|
2014-04-29 15:27:34 -04:00
|
|
|
|
2016-10-11 20:16:26 -04:00
|
|
|
base, err := removeBase(basedirectory, filepath.FromSlash(directory))
|
2016-10-11 17:43:50 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2014-04-29 15:27:34 -04:00
|
|
|
|
2015-11-06 06:14:53 -05:00
|
|
|
inputF, err := os.Open(pathname)
|
2016-10-11 17:43:50 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2015-11-06 06:14:53 -05:00
|
|
|
defer inputF.Close()
|
2014-04-29 15:27:34 -04:00
|
|
|
|
2016-10-11 17:43:50 -04:00
|
|
|
wd, err := dircache(filepath.ToSlash(base))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2014-04-29 15:27:34 -04:00
|
|
|
|
2016-10-11 17:43:50 -04:00
|
|
|
entry, err := wd.AddFile(filename)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2014-04-29 15:27:34 -04:00
|
|
|
|
2016-10-11 17:43:50 -04:00
|
|
|
fatFile, err := entry.File()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2013-07-08 23:29:38 -04:00
|
|
|
|
2016-10-11 17:43:50 -04:00
|
|
|
_, err = io.Copy(fatFile, inputF)
|
2016-03-05 02:40:16 -05:00
|
|
|
s.FilesAdded[pathname] = true
|
2013-07-08 23:29:38 -04:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2015-11-06 06:14:53 -05:00
|
|
|
return filepath.Walk(src, visit)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *StepCreateFloppy) Cleanup(multistep.StateBag) {
|
|
|
|
if s.floppyPath != "" {
|
|
|
|
log.Printf("Deleting floppy disk: %s", s.floppyPath)
|
|
|
|
os.Remove(s.floppyPath)
|
2013-07-08 23:29:38 -04:00
|
|
|
}
|
2015-11-06 06:14:53 -05:00
|
|
|
}
|
2013-07-08 23:29:38 -04:00
|
|
|
|
2015-11-06 06:14:53 -05:00
|
|
|
// removeBase will take a regular os.PathSeparator-separated path and remove the
|
|
|
|
// prefix directory base from it. Both paths are converted to their absolute
|
|
|
|
// formats before the stripping takes place.
|
2016-10-11 17:43:50 -04:00
|
|
|
func removeBase(base string, path string) (string, error) {
|
2015-11-06 06:14:53 -05:00
|
|
|
var idx int
|
|
|
|
var err error
|
|
|
|
|
2016-10-11 17:43:50 -04:00
|
|
|
if res, err := filepath.Abs(path); err == nil {
|
2015-11-06 06:14:53 -05:00
|
|
|
path = res
|
2013-07-08 23:29:38 -04:00
|
|
|
}
|
2015-11-06 06:14:53 -05:00
|
|
|
path = filepath.Clean(path)
|
2013-07-08 23:29:38 -04:00
|
|
|
|
2016-10-11 17:43:50 -04:00
|
|
|
if base, err = filepath.Abs(base); err != nil {
|
|
|
|
return path, err
|
2013-07-08 23:29:38 -04:00
|
|
|
}
|
|
|
|
|
2016-10-11 17:43:50 -04:00
|
|
|
c1, c2 := strings.Split(base, string(os.PathSeparator)), strings.Split(path, string(os.PathSeparator))
|
2015-11-06 06:14:53 -05:00
|
|
|
for idx = 0; idx < len(c1); idx++ {
|
2016-10-11 17:43:50 -04:00
|
|
|
if len(c1[idx]) == 0 && len(c2[idx]) != 0 {
|
|
|
|
break
|
|
|
|
}
|
2015-11-06 06:14:53 -05:00
|
|
|
if c1[idx] != c2[idx] {
|
|
|
|
return "", fmt.Errorf("Path %s is not prefixed by Base %s", path, base)
|
|
|
|
}
|
|
|
|
}
|
2016-10-11 17:43:50 -04:00
|
|
|
return strings.Join(c2[idx:], string(os.PathSeparator)), nil
|
2015-11-06 06:14:53 -05:00
|
|
|
}
|
2014-04-29 15:27:34 -04:00
|
|
|
|
2015-11-06 06:14:53 -05:00
|
|
|
// fsDirectoryCache returns a function that can be used to grab the fs.Directory
|
|
|
|
// entry associated with a given path. If an fs.Directory entry is not found
|
|
|
|
// then it will be created relative to the rootDirectory argument that is
|
|
|
|
// passed.
|
2016-10-11 17:43:50 -04:00
|
|
|
type directoryCache func(string) (fs.Directory, error)
|
|
|
|
|
2016-03-05 02:40:16 -05:00
|
|
|
func fsDirectoryCache(rootDirectory fs.Directory) directoryCache {
|
2015-11-06 06:14:53 -05:00
|
|
|
var cache map[string]fs.Directory
|
|
|
|
|
|
|
|
cache = make(map[string]fs.Directory)
|
|
|
|
cache[""] = rootDirectory
|
|
|
|
|
2016-10-11 17:43:50 -04:00
|
|
|
Input, Output, Error := make(chan string), make(chan fs.Directory), make(chan error)
|
2015-11-06 06:14:53 -05:00
|
|
|
go func(Error chan error) {
|
|
|
|
for {
|
2016-10-11 20:16:26 -04:00
|
|
|
input := <-Input
|
|
|
|
if len(input) > 0 {
|
|
|
|
input = path.Clean(input)
|
|
|
|
}
|
2015-11-06 06:14:53 -05:00
|
|
|
|
|
|
|
// found a directory, so yield it
|
2016-10-11 17:43:50 -04:00
|
|
|
res, ok := cache[input]
|
2015-11-06 06:14:53 -05:00
|
|
|
if ok {
|
|
|
|
Output <- res
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
component := strings.Split(input, "/")
|
|
|
|
|
|
|
|
// directory not cached, so start at the root and walk each component
|
|
|
|
// creating them if they're not in cache
|
|
|
|
var entry fs.Directory
|
2016-11-01 17:08:04 -04:00
|
|
|
for i := range component {
|
2015-11-06 06:14:53 -05:00
|
|
|
|
|
|
|
// join all of our components into a key
|
|
|
|
path := strings.Join(component[:i], "/")
|
|
|
|
|
|
|
|
// check if parent directory is cached
|
2016-10-11 17:43:50 -04:00
|
|
|
res, ok = cache[path]
|
2015-11-06 06:14:53 -05:00
|
|
|
if !ok {
|
|
|
|
// add directory into cache
|
2016-10-11 17:43:50 -04:00
|
|
|
directory, err := entry.AddDirectory(component[i-1])
|
|
|
|
if err != nil {
|
|
|
|
Error <- err
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
res, err = directory.Dir()
|
|
|
|
if err != nil {
|
|
|
|
Error <- err
|
|
|
|
continue
|
|
|
|
}
|
2015-11-06 06:14:53 -05:00
|
|
|
cache[path] = res
|
|
|
|
}
|
|
|
|
// cool, found a directory
|
|
|
|
entry = res
|
|
|
|
}
|
|
|
|
|
|
|
|
// finally create our directory
|
2016-10-11 17:43:50 -04:00
|
|
|
directory, err := entry.AddDirectory(component[len(component)-1])
|
|
|
|
if err != nil {
|
|
|
|
Error <- err
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
res, err = directory.Dir()
|
|
|
|
if err != nil {
|
|
|
|
Error <- err
|
|
|
|
continue
|
|
|
|
}
|
2015-11-06 06:14:53 -05:00
|
|
|
cache[input] = res
|
|
|
|
|
|
|
|
// ..and yield it
|
|
|
|
Output <- entry
|
|
|
|
}
|
|
|
|
}(Error)
|
|
|
|
|
2016-10-11 17:43:50 -04:00
|
|
|
getFilesystemDirectory := func(input string) (fs.Directory, error) {
|
2015-11-06 06:14:53 -05:00
|
|
|
Input <- input
|
|
|
|
select {
|
2016-10-11 17:43:50 -04:00
|
|
|
case res := <-Output:
|
|
|
|
return res, nil
|
|
|
|
case err := <-Error:
|
|
|
|
return *new(fs.Directory), err
|
2015-11-06 06:14:53 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return getFilesystemDirectory
|
2013-07-08 23:29:38 -04:00
|
|
|
}
|