From 871f0e73c0677fea54e761d91fe5f88675655683 Mon Sep 17 00:00:00 2001 From: James Shubin Date: Wed, 21 Feb 2024 14:39:43 -0500 Subject: [PATCH] lang, lib, util: Rename fs to be more unique Trying to do a big refactor and this will help. --- lang/gapi/gapi.go | 8 ++++---- lang/interpret_test.go | 6 +++--- lang/lang_test.go | 2 +- lib/run.go | 2 +- util/afero_test.go | 6 +++--- util/fs.go | 15 ++++++++------- 6 files changed, 20 insertions(+), 19 deletions(-) diff --git a/lang/gapi/gapi.go b/lang/gapi/gapi.go index 3d909fcf..197d8314 100644 --- a/lang/gapi/gapi.go +++ b/lang/gapi/gapi.go @@ -201,9 +201,9 @@ func (obj *GAPI) Cli(cliInfo *gapi.CliInfo) (*gapi.Deploy, error) { readOnlyOsFs := afero.NewReadOnlyFs(osFs) // can't be readonly to dl! //bp := afero.NewBasePathFs(osFs, base) // TODO: can this prevent parent dir access? afs := &afero.Afero{Fs: readOnlyOsFs} // wrap so that we're implementing ioutil - localFs := &util.Fs{Afero: afs} // always the local fs + localFs := &util.AferoFs{Afero: afs} // always the local fs downloadAfs := &afero.Afero{Fs: osFs} - downloadFs := &util.Fs{Afero: downloadAfs} // TODO: use with a parent path preventer? + downloadFs := &util.AferoFs{Afero: downloadAfs} // TODO: use with a parent path preventer? // the fs input here is the local fs we're reading to get the files from // this is different from the fs variable which is our output dest!!! @@ -716,9 +716,9 @@ func (obj *GAPI) Get(getInfo *gapi.GetInfo) error { readOnlyOsFs := afero.NewReadOnlyFs(osFs) // can't be readonly to dl! //bp := afero.NewBasePathFs(osFs, base) // TODO: can this prevent parent dir access? afs := &afero.Afero{Fs: readOnlyOsFs} // wrap so that we're implementing ioutil - localFs := &util.Fs{Afero: afs} // always the local fs + localFs := &util.AferoFs{Afero: afs} // always the local fs downloadAfs := &afero.Afero{Fs: osFs} - downloadFs := &util.Fs{Afero: downloadAfs} // TODO: use with a parent path preventer? + downloadFs := &util.AferoFs{Afero: downloadAfs} // TODO: use with a parent path preventer? // the fs input here is the local fs we're reading to get the files from // this is different from the fs variable which is our output dest!!! diff --git a/lang/interpret_test.go b/lang/interpret_test.go index e8cdc4d8..d542695e 100644 --- a/lang/interpret_test.go +++ b/lang/interpret_test.go @@ -290,7 +290,7 @@ func TestAstFunc1(t *testing.T) { } mmFs := afero.NewMemMapFs() afs := &afero.Afero{Fs: mmFs} // wrap so that we're implementing ioutil - fs := &util.Fs{Afero: afs} + fs := &util.AferoFs{Afero: afs} // use this variant, so that we don't copy the dir name // this is the equivalent to running `rsync -a src/ /` @@ -797,7 +797,7 @@ func TestAstFunc2(t *testing.T) { } mmFs := afero.NewMemMapFs() afs := &afero.Afero{Fs: mmFs} // wrap so that we're implementing ioutil - fs := &util.Fs{Afero: afs} + fs := &util.AferoFs{Afero: afs} // implementation of the Local API (we only expect just this single one) localAPI := (&local.API{ @@ -1599,7 +1599,7 @@ func TestAstFunc3(t *testing.T) { } mmFs := afero.NewMemMapFs() afs := &afero.Afero{Fs: mmFs} // wrap so that we're implementing ioutil - fs := &util.Fs{Afero: afs} + fs := &util.AferoFs{Afero: afs} // implementation of the Local API (we only expect just this single one) localAPI := (&local.API{ diff --git a/lang/lang_test.go b/lang/lang_test.go index 7d329398..4e1ede25 100644 --- a/lang/lang_test.go +++ b/lang/lang_test.go @@ -98,7 +98,7 @@ func runInterpret(t *testing.T, code string) (_ *pgraph.Graph, reterr error) { } mmFs := afero.NewMemMapFs() afs := &afero.Afero{Fs: mmFs} // wrap so that we're implementing ioutil - fs := &util.Fs{Afero: afs} + fs := &util.AferoFs{Afero: afs} output, err := inputs.ParseInput(code, fs) // raw code can be passed in if err != nil { diff --git a/lib/run.go b/lib/run.go index f542d681..1cff95a5 100644 --- a/lib/run.go +++ b/lib/run.go @@ -62,7 +62,7 @@ func run(c *cli.Context, name string, gapiObj gapi.GAPI) error { // create a memory backed temporary filesystem for storing runtime data mmFs := afero.NewMemMapFs() afs := &afero.Afero{Fs: mmFs} // wrap so that we're implementing ioutil - standaloneFs := &util.Fs{Afero: afs} + standaloneFs := &util.AferoFs{Afero: afs} obj.DeployFs = standaloneFs cliInfo := &gapi.CliInfo{ diff --git a/util/afero_test.go b/util/afero_test.go index b57111f5..a3b79f35 100644 --- a/util/afero_test.go +++ b/util/afero_test.go @@ -157,7 +157,7 @@ func TestCopyDiskToFs1(t *testing.T) { mmFs := afero.NewMemMapFs() afs := &afero.Afero{Fs: mmFs} // wrap so that we're implementing ioutil - fs := &Fs{afs} + fs := &AferoFs{afs} if err := CopyDiskToFs(fs, dir+f+"/", "/", false); err != nil { t.Errorf("copying to fs failed: %+v", err) @@ -218,7 +218,7 @@ func TestCopyDiskToFs2(t *testing.T) { mmFs := afero.NewMemMapFs() afs := &afero.Afero{Fs: mmFs} // wrap so that we're implementing ioutil - fs := &Fs{afs} + fs := &AferoFs{afs} src := dir + f + "/" dst := "/dest/" @@ -282,7 +282,7 @@ func TestCopyDiskContentsToFs1(t *testing.T) { mmFs := afero.NewMemMapFs() afs := &afero.Afero{Fs: mmFs} // wrap so that we're implementing ioutil - fs := &Fs{afs} + fs := &AferoFs{afs} if err := CopyDiskContentsToFs(fs, dir+f+"/", "/", false); err != nil { t.Errorf("copying to fs failed: %+v", err) diff --git a/util/fs.go b/util/fs.go index d41e76ec..cb5ddb9a 100644 --- a/util/fs.go +++ b/util/fs.go @@ -23,14 +23,15 @@ import ( "github.com/spf13/afero" ) -// Fs is a simple wrapper to a file system to be used for standalone deploys. -// This is basically a pass-through so that we fulfill the same interface that -// the deploy mechanism uses. To use this, wrap it with the implied field name, -// which will prevent `go vet` warnings, eg: `fs := &util.Fs{Afero: afs}`. -// NOTE: This struct is here, since I don't know where else to put it for now. -type Fs struct { +// AferoFs is a simple wrapper to a file system to be used for standalone +// deploys. This is basically a pass-through so that we fulfill the same +// interface that the deploy mechanism uses. To use this, wrap it with the +// implied field name, which will prevent `go vet` warnings, eg: +// `fs := &util.AferoFs{Afero: afs}`. NOTE: This struct is here, since I don't +// know where else to put it for now. +type AferoFs struct { *afero.Afero } // URI returns the unique URI of this filesystem. It returns the root path. -func (obj *Fs) URI() string { return fmt.Sprintf("%s://"+"/", obj.Name()) } +func (obj *AferoFs) URI() string { return fmt.Sprintf("%s://"+"/", obj.Name()) }