From d472ed81229e1aa25a294e6dcc11441cb0b3d769 Mon Sep 17 00:00:00 2001 From: Nathan Baulch Date: Thu, 17 Oct 2024 20:58:16 +1100 Subject: [PATCH] Normalize whitespace --- .github/ISSUE_TEMPLATE/custom.md | 1 - .golangci.yml | 1 - CHANGELOG.md | 12 +++---- README.md | 16 +++------ backend/azure/doc.go | 1 - backend/ftp/dataconn.go | 1 - backend/ftp/dataconn_test.go | 6 ---- backend/ftp/doc.go | 1 - backend/ftp/file.go | 4 --- backend/ftp/fileSystem.go | 1 - backend/ftp/file_test.go | 12 ------- backend/ftp/location_test.go | 2 -- backend/gs/doc.go | 1 - backend/gs/file.go | 5 --- backend/gs/location_test.go | 1 - backend/mem/file.go | 2 -- backend/mem/fileSystem.go | 10 ------ backend/mem/file_test.go | 34 ------------------- backend/mem/location.go | 13 ------- backend/mem/location_test.go | 13 ------- backend/mem/readwriteseeker.go | 1 - backend/os/file.go | 2 -- backend/os/file_test.go | 3 -- backend/s3/doc.go | 1 - backend/s3/file.go | 1 - backend/s3/fileSystem_test.go | 1 - backend/s3/file_test.go | 6 ---- backend/s3/options.go | 1 - backend/sftp/doc.go | 1 - backend/sftp/file.go | 5 --- backend/sftp/fileSystem.go | 1 - backend/sftp/file_test.go | 2 -- backend/sftp/location.go | 4 --- backend/sftp/location_test.go | 2 -- backend/sftp/options.go | 3 -- backend/sftp/options_test.go | 4 --- backend/testsuite/backend_integration_test.go | 6 ---- backend/testsuite/io_integration_test.go | 12 +++---- docs/azure.md | 3 -- docs/backend.md | 3 +- docs/delete_options.md | 6 ++-- docs/ftp.md | 7 +--- docs/gs.md | 8 ++--- docs/mem.md | 11 +++--- docs/options.md | 5 ++- docs/os.md | 5 ++- docs/s3.md | 4 --- docs/sftp.md | 18 ++++------ docs/utils.md | 7 ++-- docs/vfscp.md | 4 +-- docs/vfssimple.md | 9 +++-- utils/utils.go | 2 -- utils/utils_test.go | 7 ---- vfscp/vfscp.go | 1 - vfssimple/vfssimple_test.go | 1 + 55 files changed, 45 insertions(+), 249 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/custom.md b/.github/ISSUE_TEMPLATE/custom.md index 48d5f81f..d24be768 100644 --- a/.github/ISSUE_TEMPLATE/custom.md +++ b/.github/ISSUE_TEMPLATE/custom.md @@ -7,4 +7,3 @@ assignees: '' --- - diff --git a/.golangci.yml b/.golangci.yml index e461b062..bf53581e 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -47,7 +47,6 @@ run: # If false (default) - golangci-lint acquires file lock on start. allow-parallel-runners: false - # output configuration options output: # colored-line-number|line-number|json|tab|checkstyle|code-climate|junit-xml|github-actions diff --git a/CHANGELOG.md b/CHANGELOG.md index c85150bb..55f8d380 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,7 +47,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Fixed #187 - Update to latest jlaffaye/ftp library to fix issue where FTPS connections were failing due to a bug in the library. Also updated dataconn to continue even if it fails to MakeDir. - ## [6.14.1] - 2024-05-28 ### Fixed - Fixed #185 - location.Exists was checking if a list entry was a directory but it was was only checking the first entry. @@ -107,7 +106,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [6.11.0] - 2024-01-22 ### Added -- Added support for hmac-sha1 and hmac-sha1-96 and removed hmac-ripemd160 +- Added support for hmac-sha1 and hmac-sha1-96 and removed hmac-ripemd160 ## [6.10.0] - 2023-12-28 ### Fixed @@ -216,11 +215,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Upgrade steps -With v6.0.0, sftp.Options struct changed to accept an array of Key Exchange algorithms rather than a string. To update, change the syntax of the auth commands. +With v6.0.0, sftp.Options struct changed to accept an array of Key Exchange algorithms rather than a string. To update, change the syntax of the auth commands. ``` "keyExchanges":"diffie-hellman-group-a256" ``` -becomes +becomes ``` "keyExchanges":["diffie-hellman-group-a256"] ``` @@ -315,7 +314,7 @@ not just GCS. ## [5.3.0] - 2019-08-24 ### Added -- ACL can now be passed in as an s3.Option value. See +- ACL can now be passed in as an s3.Option value. See https://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html#canned-acl for values. ## [5.2.3] - 2019-08-07 @@ -347,7 +346,6 @@ created in the UI or by createing a zero-length object ending with "/". These o - updated README to include "Touch()" definition under the File interface rather than the Location interface - updated README to exclude "in-memory-backend" from the list of ideas - ## [5.1.0] - 2019-07-08 ### Added - Added Touch() method to File interface and implemented in each backend. @@ -378,7 +376,7 @@ than a brand new file with new location. Since File may represent a non-existen 1. Added the Retry() method to the FileSystem interface, along with a no-op default retryer. 2. Integrated the newly defined retryer interface into the GCS implementation of VFS and now allow the retry method to be injected as a FileSystem option. -3. Integrated the request.Retryer from the s3 client as an injectable implementation for the S3 vfs.Option. +3. Integrated the request.Retryer from the s3 client as an injectable implementation for the S3 vfs.Option. ### Upgrade steps diff --git a/README.md b/README.md index b9b23c3d..5b3148cb 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,6 @@ Package vfs provides a pluggable, extensible, and opinionated set of file system functionality for Go across a number of file system types such as os, Azure, S3, GCS and SFTP. - ### Philosophy When building our platform, initially we wrote a library that was something to @@ -30,7 +29,7 @@ the effect of } ``` -Not only was ugly but because the behaviors of each "file system" were +Not only was ugly but because the behaviors of each "file system" were different and we had to constantly alter the file locations and pass a bucket string (even if the file system didn't know what a bucket was). @@ -57,7 +56,6 @@ file system backends. * mockable file system * pluggability so that third-party implementations of our interfaces could be used - ### Install Pre 1.17: @@ -137,13 +135,12 @@ will first delegate actual copying in the following: 3. finally, if neither 1 or 2, io.Copy will do it's own buffered copy In case 3, and most implementations of cases 1 and 2, if reader is empty, Write() never gets called. What that means for -vfs is there is no way for us to ensure that an empty file does or doesn't get written on an io.Copy(). For instance +vfs is there is no way for us to ensure that an empty file does or doesn't get written on an io.Copy(). For instance OS always creates a file, regardless of calling Write() whereas S3 must Write() and Close(). As such, vfs cannot guarantee copy behavior except in our own CopyToFile, MoveToFile, CopyToLocation, and MoveToLocation functions. If you need to ensure a file gets copied/moved with io.Copy(), you must do so yourself OR use vfs's [utils.TouchCopy](docs/utils.md) - ### Third-party Backends * none so far @@ -160,7 +157,7 @@ Feel free to send a pull request if you want to add your backend to the list. * [in-memory backend](docs/mem.md) * [sftp backend](docs/sftp.md) * [ftp backend](docs/ftp.md) - * [azure backend](docs/azure.md) + * [azure backend](docs/azure.md) * [utils](docs/utils.md) ### Ideas @@ -169,7 +166,6 @@ Things to add: * Provide better List() functionality with more abstracted filtering and paging (iterator?) Return File structs vs URIs? * Add better/any context.Context() support - ### Contributors Brought to you by the Enterprise Pipeline team at C2FO: @@ -198,13 +194,11 @@ https://github.com/c2fo/ 4. Push to the branch (`git push origin feature/fooBar`) 5. Create a new Pull Request - ### License Distributed under the MIT license. See `http://github.com/c2fo/vfs/License.md for more information. - ### Definitions ###### absolute path @@ -305,7 +299,7 @@ type File interface { // // For file:///some/path/to/file.txt, it would return file.txt Name() string - + // Touch creates a zero-length file on the vfs.File if no File exists. Update File's last modified timestamp. // Returns error if unable to touch File. Touch() error @@ -345,7 +339,7 @@ type FileSystem interface { NewLocation(volume string, absLocPath string) (Location, error) // Name returns the name of the FileSystem ie: Amazon S3, os, Google Cloud Storage, etc. - Name() string + Name() string // Scheme returns the uri scheme used by the FileSystem: s3, file, gs, etc. Scheme() string diff --git a/backend/azure/doc.go b/backend/azure/doc.go index 8b40c6b3..45f0b537 100644 --- a/backend/azure/doc.go +++ b/backend/azure/doc.go @@ -28,7 +28,6 @@ azure can be augmented with the following implementation-specific methods. Back would have to be cast as azure.Filesystem to use the following: func DoSomething() { - ... // cast if fs was created using backend.Backend(). Not necessary if created directly from azure.NewFilesystem(). diff --git a/backend/ftp/dataconn.go b/backend/ftp/dataconn.go index 81ec7579..c5e09718 100644 --- a/backend/ftp/dataconn.go +++ b/backend/ftp/dataconn.go @@ -28,7 +28,6 @@ func (dc *dataConn) Delete(path string) error { return singleOpInvalidDataconnType } return dc.c.Delete(path) - } // GetEntry attempts to retrieve the ftp entry for diff --git a/backend/ftp/dataconn_test.go b/backend/ftp/dataconn_test.go index 905d4295..ee6ff6ff 100644 --- a/backend/ftp/dataconn_test.go +++ b/backend/ftp/dataconn_test.go @@ -39,11 +39,9 @@ func (s *dataConnSuite) SetupTest() { }, path: filepath, } - } func (s *dataConnSuite) TestGetDataConn_alreadyExists() { - // dataconn already exists s.ftpFile.fileSystem.dataconn = &dataConn{ mode: types.OpenRead, @@ -54,7 +52,6 @@ func (s *dataConnSuite) TestGetDataConn_alreadyExists() { } func (s *dataConnSuite) TestGetDataConn_openForRead() { - // dataconn is nil - open for read s.client.EXPECT(). RetrFrom(s.ftpFile.Path(), uint64(0)). @@ -77,7 +74,6 @@ func (s *dataConnSuite) TestGetDataConn_errorClientSetup() { } func (s *dataConnSuite) TestGetDataConn_ReadError() { - // dataconn is nil - error calling client.RetrFrom someErr := errors.New("some error") @@ -92,7 +88,6 @@ func (s *dataConnSuite) TestGetDataConn_ReadError() { } func (s *dataConnSuite) TestGetDataConn_WriteLocationNotExists() { - // dataconn is nil - opebrewn for write - location doesnt exist - success s.client.EXPECT(). List("/"). @@ -178,7 +173,6 @@ func (s *dataConnSuite) TestGetDataConn_writeSuccess() { } func (s *dataConnSuite) TestGetDataConn_reaedAfterWriteError() { - // open dataconn for read after dataconn for write exists - error on dataconn.Close fakedconn := NewFakeDataConn(types.OpenWrite) closeErr := errors.New("some close err") diff --git a/backend/ftp/doc.go b/backend/ftp/doc.go index c03ae68b..27a19ed9 100644 --- a/backend/ftp/doc.go +++ b/backend/ftp/doc.go @@ -37,7 +37,6 @@ These methods are chainable: (*FileSystem) WithOptions(opts vfs.Options) *FileSystem func DoSomething() { - // cast if fs was created using backend.Backend(). Not necessary if created directly from ftp.NewFilesystem(). fs := backend.Backend(ftp.Scheme) fs = fs.(*ftp.Filesystem) diff --git a/backend/ftp/file.go b/backend/ftp/file.go index 45b69377..112ef0cb 100644 --- a/backend/ftp/file.go +++ b/backend/ftp/file.go @@ -40,7 +40,6 @@ type File struct { // LastModified returns the LastModified property of ftp file. func (f *File) LastModified() (*time.Time, error) { - entry, err := f.stat(context.TODO()) if err != nil { return nil, err @@ -151,7 +150,6 @@ func getTempFilename(origName string) string { // Size returns the size of the remote file. func (f *File) Size() (uint64, error) { - entry, err := f.stat(context.TODO()) if err != nil { return 0, err @@ -181,7 +179,6 @@ func (f *File) MoveToFile(t vfs.File) error { if f.fileSystem.Scheme() == t.Location().FileSystem().Scheme() && f.authority.UserInfo().Username() == t.(*File).authority.UserInfo().Username() && f.authority.HostPortStr() == t.(*File).authority.HostPortStr() { - // ensure destination exists before moving exists, err := t.Location().Exists() if err != nil { @@ -287,7 +284,6 @@ func (f *File) CopyToFile(file vfs.File) (err error) { //nolint:gocyclo return err } - } // CopyToLocation creates a copy of *File, using the file's current path as the new file's diff --git a/backend/ftp/fileSystem.go b/backend/ftp/fileSystem.go index 2511725a..d6ecc07a 100644 --- a/backend/ftp/fileSystem.go +++ b/backend/ftp/fileSystem.go @@ -120,7 +120,6 @@ func (fs *FileSystem) Client(ctx context.Context, authority utils.Authority) (ty // WithOptions sets options for client and returns the filesystem (chainable) func (fs *FileSystem) WithOptions(opts vfs.Options) *FileSystem { - // only set options if vfs.Options is ftp.Options if opts, ok := opts.(Options); ok { fs.options = opts diff --git a/backend/ftp/file_test.go b/backend/ftp/file_test.go index fbe4ddfe..eb0ffb6e 100644 --- a/backend/ftp/file_test.go +++ b/backend/ftp/file_test.go @@ -50,7 +50,6 @@ func clientGetterReturnsError(_ context.Context, _ utils.Authority, _ Options) ( } func (ts *fileTestSuite) TestRead() { - // set up ftpfile fp := "/some/path.txt" client := mocks.NewClient(ts.T()) @@ -100,7 +99,6 @@ func (ts *fileTestSuite) TestRead() { } func (ts *fileTestSuite) TestClose() { - // set up ftpfile fp := "/some/path.txt" client := mocks.NewClient(ts.T()) @@ -505,7 +503,6 @@ func (ts *fileTestSuite) TestCopyToFile() { err = sourceFile.CopyToFile(targetFile) ts.Error(err, "error is expected") ts.ErrorIs(err, closeErr, "error is expected kind of error") - } func (ts *fileTestSuite) TestCopyToLocation() { @@ -1018,7 +1015,6 @@ func (ts *fileTestSuite) TestDelete() { func (ts *fileTestSuite) TestLastModified() { now := time.Now() entry := &_ftp.Entry{ - Name: ts.testFile.Name(), Type: _ftp.EntryTypeFile, Time: now, @@ -1083,7 +1079,6 @@ func (ts *fileTestSuite) TestName() { func (ts *fileTestSuite) TestSize() { contentLength := uint64(100) entry := &_ftp.Entry{ - Name: ts.testFile.Name(), Type: _ftp.EntryTypeFile, Size: contentLength, @@ -1195,35 +1190,28 @@ func (f *FakeDataConn) List(p string) ([]*_ftp.Entry, error) { Type: _ftp.EntryTypeFolder, }, }, f.singleOpErr - } return nil, errors.New("550") - } func (f *FakeDataConn) MakeDir(p string) error { return f.singleOpErr - } func (f *FakeDataConn) Rename(from, to string) error { return f.singleOpErr - } func (f *FakeDataConn) IsSetTimeSupported() bool { return false - } func (f *FakeDataConn) SetTime(p string, t time.Time) error { return f.singleOpErr - } func (f *FakeDataConn) IsTimePreciseInList() bool { return f.mlst - } func (f *FakeDataConn) Read(p []byte) (int, error) { diff --git a/backend/ftp/location_test.go b/backend/ftp/location_test.go index 71889758..8262e2aa 100644 --- a/backend/ftp/location_test.go +++ b/backend/ftp/location_test.go @@ -359,7 +359,6 @@ func (lt *locationTestSuite) TestVolume() { } func (lt *locationTestSuite) TestPath() { - loc, err := lt.ftpfs.NewLocation("host.com", "/path/") lt.NoError(err) lt.Equal("/path/", loc.Path(), "Path() should return the path on location.") @@ -479,7 +478,6 @@ func (lt *locationTestSuite) TestExists() { } func (lt *locationTestSuite) TestChangeDir() { - loc := &Location{fileSystem: lt.ftpfs, path: "/", Authority: utils.Authority{}} err1 := loc.ChangeDir("../") diff --git a/backend/gs/doc.go b/backend/gs/doc.go index 657bb978..2f2ad195 100644 --- a/backend/gs/doc.go +++ b/backend/gs/doc.go @@ -28,7 +28,6 @@ gs can be augmented with the following implementation-specific methods. Backend would have to be cast as gs.Filesystem to use the following: func DoSomething() { - ... // cast if fs was created using backend.Backend(). Not necessary if created directly from gs.NewFilesystem(). diff --git a/backend/gs/file.go b/backend/gs/file.go index 87fd7ee8..ed8600f0 100644 --- a/backend/gs/file.go +++ b/backend/gs/file.go @@ -98,7 +98,6 @@ func (f *File) Close() error { } func (f *File) tempToGCS() error { - handle, err := f.getObjectHandle() if err != nil { return err @@ -498,7 +497,6 @@ func (f *File) Delete(opts ...options.DeleteOption) error { // Touch creates a zero-length file on the vfs.File if no File exists. Update File's last modified timestamp. // Returns error if unable to touch File. func (f *File) Touch() error { - // check if file exists exists, err := f.Exists() if err != nil { @@ -532,7 +530,6 @@ func (f *File) Touch() error { } func (f *File) updateLastModifiedByAttrUpdate() error { - // save original metadata (in case it was set already) objAttrs, err := f.getObjectAttrs() if err != nil { @@ -582,7 +579,6 @@ func (f *File) isBucketVersioningEnabled() (bool, error) { } func (f *File) createEmptyFile() error { - handle, err := f.getObjectHandle() if err != nil { return err @@ -659,7 +655,6 @@ func (f *File) URI() string { } func (f *File) copyToLocalTempReader(tmpFile *os.File) error { - handle, err := f.getObjectHandle() if err != nil { return err diff --git a/backend/gs/location_test.go b/backend/gs/location_test.go index 6b45ead0..8d12df05 100644 --- a/backend/gs/location_test.go +++ b/backend/gs/location_test.go @@ -322,5 +322,4 @@ func (lt *locationTestSuite) TestDeleteFile() { func TestLocation(t *testing.T) { suite.Run(t, new(locationTestSuite)) - } diff --git a/backend/mem/file.go b/backend/mem/file.go index bd6b9e87..50e767f6 100644 --- a/backend/mem/file.go +++ b/backend/mem/file.go @@ -426,7 +426,6 @@ func (f *File) MoveToFile(file vfs.File) error { // Delete removes the file from the FileSystem. Sets it path in the fsMap to nil, // and also nils the file's members func (f *File) Delete(_ ...options.DeleteOption) error { - if ex, _ := f.Exists(); !ex { return fs.ErrNotExist } @@ -488,7 +487,6 @@ func (f *File) Size() (uint64, error) { f.readWriteSeeker = NewReadWriteSeekerWithData(f.memFile.contents) return uint64(len(f.readWriteSeeker.Bytes())), nil - } // Touch takes a in-memory vfs.File, makes it existent, and updates the lastModified diff --git a/backend/mem/fileSystem.go b/backend/mem/fileSystem.go index e39f8ddd..1fd837da 100644 --- a/backend/mem/fileSystem.go +++ b/backend/mem/fileSystem.go @@ -39,7 +39,6 @@ func (fs *FileSystem) Retry() vfs.Retry { // true for other functions as well and existence only poses a problem in the context of deletion // or copying FROM a non-existent file. func (fs *FileSystem) NewFile(volume, absFilePath string) (vfs.File, error) { - err := utils.ValidateAbsoluteFilePath(absFilePath) if err != nil { return nil, err @@ -80,7 +79,6 @@ func (fs *FileSystem) NewFile(volume, absFilePath string) (vfs.File, error) { // A location always exists. If a file is created on a location that has not yet // been made in the fsMap, then the location will be created with the file func (fs *FileSystem) NewLocation(volume, absLocPath string) (vfs.Location, error) { - err := utils.ValidateAbsoluteLocationPath(absLocPath) if err != nil { return nil, err @@ -92,7 +90,6 @@ func (fs *FileSystem) NewLocation(volume, absLocPath string) (vfs.Location, erro exists: false, volume: volume, }, nil - } // Name returns the name of the underlying FileSystem @@ -107,18 +104,15 @@ func (fs *FileSystem) Scheme() string { // NewFileSystem is used to initialize the file system struct for an in-memory FileSystem. func NewFileSystem() *FileSystem { - return &FileSystem{ sync.Mutex{}, make(map[string]objMap), } - } func init() { // Even though the map is being made here, a call to backend.Register(Scheme, NewFileSystem()) - } // getKeys is used to get a list of absolute paths on a specified volume. These paths are a mixture of files and locations @@ -133,11 +127,9 @@ func (o objMap) getKeys() []string { // fileHere returns a list of file pointers found at the absolute location path provided. // If none are there, returns an empty slice func (o objMap) filesHere(absLocPath string) []*memFile { - paths := o.getKeys() fileList := make([]*memFile, 0) for i := range paths { - object := o[paths[i]] // retrieve the object if ok := object != nil && object.isFile; ok { // if the object is a file, cast its interface, i, to a file and append to the slice file := object.i.(*memFile) @@ -152,11 +144,9 @@ func (o objMap) filesHere(absLocPath string) []*memFile { // fileNamesHere returns a list of base names of files found at the absolute location path provided. // If none are there, returns an empty slice func (o objMap) fileNamesHere(absLocPath string) []string { - paths := o.getKeys() fileList := make([]string, 0) for i := range paths { - object := o[paths[i]] // retrieve the object if object != nil && object.isFile { // if the object is a file, cast its interface, i, to a file and append the name to the slice file := object.i.(*memFile) diff --git a/backend/mem/file_test.go b/backend/mem/file_test.go index f6235989..a794deff 100644 --- a/backend/mem/file_test.go +++ b/backend/mem/file_test.go @@ -46,11 +46,9 @@ func (s *memFileTest) TeardownTest() { // TestZBR ensures that we can always read zero bytes func (s *memFileTest) TestZBR() { - byteSlice := make([]byte, 0) _, err := s.testFile.Read(byteSlice) s.ErrorIs(err, io.EOF, "read of 0 bytes failed") - } // TestRARO ensures that read after read w/file still open (and without a seek) will incur an error @@ -94,7 +92,6 @@ func (s *memFileTest) TestRARC() { // the file before reading again, so it should reset it. s.NoError(err, "read after read failed!") s.Equal(byteSlice, byteSlice2) - } // TestNewFileSameName creates two files with the same name and ensures @@ -122,7 +119,6 @@ func (s *memFileTest) TestNewFileSameName() { // TestDelete deletes the receiver file, then creates another file and deletes it. // Succeeds only on both successful deletions func (s *memFileTest) TestDelete() { - newFile, err := s.fileSystem.NewFile("", "/home/bar.txt") s.NoError(err, "unexpected creation error") s.NoError(newFile.Touch(), "unexpected error touching file") @@ -168,7 +164,6 @@ func (s *memFileTest) TestExists2() { // TestNewFile creates a file and then checks that it exists in our system the the path expected func (s *memFileTest) TestNewFile() { - file, err := s.fileSystem.NewFile("", "/test_file/foo.txt") s.NoError(err, "unexpected error creating file") s.NoError(file.Touch(), "unexpected error touching file") @@ -176,7 +171,6 @@ func (s *memFileTest) TestNewFile() { returnedFile, err := s.fileSystem.NewFile(file.Location().Volume(), filePath) // checking our system map for a match to the given fileName s.NoError(err, "unexpected error retrieving file") s.True(returnedFile.Name() == "foo.txt") // casting the object to a file so we can call "Name()" - } // TestSeek2 tests to ensure that we can seek to any part of the file, if it exists @@ -226,12 +220,10 @@ func (s *memFileTest) TestSeek2() { s.NoError(err, "unexpected error creating a new file") _, err = f.Seek(0, 0) s.ErrorIs(err, fs.ErrNotExist, "expected Seek error") - } // TestNameToURI creates a file then pulls it out of the fsMap using its name and ensures its file and location URIs are correct func (s *memFileTest) TestNameToURI() { - name := "/test_files/examples/foo.txt" file, err := s.fileSystem.NewFile("C", name) s.NoError(err, "unexpected error creating file") @@ -247,7 +239,6 @@ func (s *memFileTest) TestNameToURI() { s.True(existence) s.Equal("mem://C/test_files/examples/", returnedFile.Location().URI()) s.Equal("mem://C/test_files/examples/foo.txt", returnedFile.URI()) - } // TestOpenFile ensures that reading after a write without seeking or closing a file throws an error @@ -290,14 +281,12 @@ func (s *memFileTest) TestSeek() { found2, err := file.Exists() s.NoError(err, "exists error not expected") s.False(found2) - } // TestCopyToLocation copies a file to a location that has // been passed in. Succeeds on existence of original file and its // contents in new location func (s *memFileTest) TestCopyToLocation() { - newFile, err := s.fileSystem.NewFile("", "/home/foo.txt") s.NoError(err, "unexpected error creating file") expectedText := "hello world!" @@ -323,14 +312,12 @@ func (s *memFileTest) TestCopyToLocation() { _, err = s.testFile.Read(readSlice2) s.NoError(err, "unexpected read error") s.EqualValues(string(readSlice2), string(readSlice1)) - } // TestCopyToLocationOW copies a file to a location that has // a file with the same name. Succeeds only on overwrite of file // in specified location func (s *memFileTest) TestCopyToLocationOW() { - newFile, err := s.fileSystem.NewFile("C", "/home/test.txt") s.NoError(err, "unexpected error creating a file") s.NoError(newFile.Touch(), "unexpected error touching file") @@ -354,12 +341,10 @@ func (s *memFileTest) TestCopyToLocationOW() { _, err = copiedFile.Read(readSlice) s.NoError(err, "unexpected read error") s.EqualValues("hello world!", string(readSlice)) - } // TestCopyToNilFile ensures that an error is thrown for trying to copy to a nil file func (s *memFileTest) TestCopyToNilFile() { - newFile, err := s.fileSystem.NewFile("", "nilFile.txt") s.Error(err, "expected error creating file (bad path)") err = s.testFile.CopyToFile(newFile) @@ -369,7 +354,6 @@ func (s *memFileTest) TestCopyToNilFile() { // TestCopyToLocationOS copies a file from the in-memory FileSystem over // to a location on the OS FileSystem and checks for success func (s *memFileTest) TestCopyToLocationOS() { - expectedText := "hello world!" _, err := s.testFile.Write([]byte(expectedText)) s.NoError(err, "unexpected write error") @@ -415,7 +399,6 @@ func (s *memFileTest) TestCopyToLocationOS() { // TestCopyToFile tests "CopyToFile()" between two files both in the in-memory FileSystem func (s *memFileTest) TestCopyToFile() { - expectedText := "hello world" otherFile, err := s.fileSystem.NewFile("", "/test.txt") s.NoError(err, "unexpected error creating file") @@ -437,12 +420,10 @@ func (s *memFileTest) TestCopyToFile() { _, err = otherFile.Read(readSlice2) s.NoError(err, "unexpected read error") s.EqualValues(string(readSlice1), string(readSlice2)) - } // TestCopyToFileOS tests "CopyToFile()" between one file in the in-memory FileSystem and the other in the os FileSystem func (s *memFileTest) TestCopyToFileOS() { - expectedText := "Hello World!" var osFile vfs.File var err error @@ -469,7 +450,6 @@ func (s *memFileTest) TestCopyToFileOS() { size2, err := osFile.Size() s.NoError(err, "unexpected error retrieving size") s.Equal(size1, size2) - } // TestEmptyCopy to file creates two files, @@ -478,7 +458,6 @@ func (s *memFileTest) TestCopyToFileOS() { // he non-empty one. Succeeds on the non-empty // file becoming empty func (s *memFileTest) TestEmptyCopyToFile() { - expectedText := "" expectedSlice := make([]byte, 0) otherFile, err := s.fileSystem.NewFile("", "/some/path/otherfile.txt") @@ -501,12 +480,10 @@ func (s *memFileTest) TestEmptyCopyToFile() { _, err = otherFile.Read(expectedSlice) s.ErrorIs(err, io.EOF, "expected EOF error") s.Equal(expectedText, string(expectedSlice)) - } // TestMoveToLocation ensures that we can move files to specified locations func (s *memFileTest) TestMoveToLocation() { - newFile, err := s.fileSystem.NewFile("", "/otherDir/foo.txt") s.NoError(err, "unexpected error creating file") s.NoError(newFile.Touch(), "unexpected error touching file") @@ -522,12 +499,10 @@ func (s *memFileTest) TestMoveToLocation() { str2 := file.Path() s.Equal(path.Base(str1), path.Base(str2)) s.Equal("/test_files/", file.Location().Path()) - } // TestMoveToLocation2 creates two files with the same name in different places and moves one to the other func (s *memFileTest) TestMoveToLocation2() { - expectedText := "Who ya calling pinhead?" newFile, err := s.fileSystem.NewFile("", "/otherDir/foo.txt") s.NoError(err, "unexpected error creating file") @@ -550,13 +525,11 @@ func (s *memFileTest) TestMoveToLocation2() { _, err = file.Read(readSlice) s.NoError(err, "unexpected read error") s.Equal(expectedText, string(readSlice)) - } // TestMoveToFile creates a newFile and moves the testFile to it. // Test succeeds if the moved file has the correct data. They share the same name, so this is effectively a "CopyToFile" call func (s *memFileTest) TestMoveToFile() { - expectedSlice := []byte("Hello World!") newFile, err := s.fileSystem.NewFile("", "/samples/test.txt") s.NoError(err, "unexpected error creating file") @@ -581,12 +554,10 @@ func (s *memFileTest) TestMoveToFile() { s.Equal(string(expectedSlice), string(newFileSlice)) s.Equal("/samples/test.txt", newFile.Path()) - } // TestMoveToFile2 ensures that if a call is made on a files who don't share the same name, a new file is produced with the caller's name func (s *memFileTest) TestMoveToFile2() { - expectedSlice := []byte("Hello World!") newFile, err := s.fileSystem.NewFile("", "/samples/diffName.txt") s.NoError(err, "file creation was not successful so it does not exist") @@ -606,7 +577,6 @@ func (s *memFileTest) TestMoveToFile2() { s.NoError(err, "read unexpectedly failed") s.Equal(string(expectedSlice), string(newFileSlice)) s.Equal("/samples/diffName.txt", newFile.Path()) - } // TestWrite writes a string to a file and checks for success by comparing the number of bytes @@ -703,7 +673,6 @@ func (s *memFileTest) TestLastModified() { secondTime := *t s.True(secondTime.UnixNano() > firstTime.UnixNano()) - } // TestName creates a file and names it and then asserts that the given name and the return of Name() match. @@ -731,7 +700,6 @@ func (s *memFileTest) TestSize() { size2, err := otherFile.Size() s.NoError(err, "unexpected error retrieving size") s.True(size1 > size2) - } // TestPath makes sure that locations return the correct paths, along with leading and trailing slashes @@ -764,13 +732,11 @@ func (s *memFileTest) TestURI() { // TestStringer tests the implementation of io.Stringer func (s *memFileTest) TestStringer() { - file, err := s.fileSystem.NewFile("", "/test_files/lots/of/directories/here/we/go/test.txt") s.NoError(err, "unexpected error creating file") s.NoError(file.Touch(), "unexpected error touching file") str := file.String() s.Equal("mem:///test_files/lots/of/directories/here/we/go/test.txt", str) - } func (s *memFileTest) TestFileNewWrite() { diff --git a/backend/mem/location.go b/backend/mem/location.go index 551bed73..c22fb14b 100644 --- a/backend/mem/location.go +++ b/backend/mem/location.go @@ -24,14 +24,12 @@ type Location struct { // String implements io.Stringer by returning the location's URI as a string func (l *Location) String() string { - return l.URI() } // List finds all of the files living at the current location and returns them in a slice of strings. // If there are no files at location, then an empty slice will be returned func (l *Location) List() ([]string, error) { - locPath := l.Path() // setting mapRef to this value for code readability mapRef := l.fileSystem.fsMap @@ -50,7 +48,6 @@ func (l *Location) List() ([]string, error) { // returns all file base names whose full paths contain that substring // Returns empty slice if nothing found func (l *Location) ListByPrefix(prefix string) ([]string, error) { - list := make([]string, 0) str := path.Join(l.Path(), prefix) mapRef := l.fileSystem.fsMap @@ -74,7 +71,6 @@ func (l *Location) ListByPrefix(prefix string) ([]string, error) { // found that matched the regular expression. Returns an // empty slice upon nothing found func (l *Location) ListByRegex(regex *regexp.Regexp) ([]string, error) { - list := make([]string, 0) str := l.Path() mapRef := l.fileSystem.fsMap @@ -96,16 +92,13 @@ func (l *Location) Volume() string { // Path returns the full, absolute path of the location with leading and trailing slashes func (l *Location) Path() string { - // just to be sure that we return a trailing and leading slash str := utils.EnsureTrailingSlash(path.Clean(l.name)) return utils.EnsureLeadingSlash(str) - } // Exists always returns true on locations func (l *Location) Exists() (bool, error) { - l.exists = true return true, nil } @@ -136,7 +129,6 @@ func (l *Location) NewLocation(relLocPath string) (vfs.Location, error) { exists: false, volume: l.Volume(), }, nil - } // ChangeDir simply changes the directory of the location @@ -147,19 +139,15 @@ func (l *Location) ChangeDir(relLocPath string) error { } l.name = path.Join(l.name, relLocPath) return nil - } // FileSystem returns the type of file system location exists on, if it exists at all func (l *Location) FileSystem() vfs.FileSystem { - return l.fileSystem - } // NewFile creates a vfs.File given its relative path and tags it onto "l's" path func (l *Location) NewFile(relFilePath string) (vfs.File, error) { - if relFilePath == "" { return nil, errors.New("cannot use empty name for file") } @@ -227,6 +215,5 @@ func (l *Location) DeleteFile(relFilePath string, _ ...options.DeleteOption) err // URI returns the URI of the location if the location exists func (l *Location) URI() string { - return utils.GetLocationURI(l) } diff --git a/backend/mem/location_test.go b/backend/mem/location_test.go index b6d3db2a..483c1be2 100644 --- a/backend/mem/location_test.go +++ b/backend/mem/location_test.go @@ -34,7 +34,6 @@ func (s *memLocationTest) SetupTest() { // TestFSName tests out whether or not the location knows what filesystem it is on func (s *memLocationTest) TestFSName() { - s.Equal(s.testFile.Location().FileSystem().Name(), "In-Memory Filesystem") s.Equal(s.testFile.Location().FileSystem().Scheme(), "mem") } @@ -73,7 +72,6 @@ func (s *memLocationTest) TestList_NonExistentDirectory() { // TestListByPrefix creates some files and provides a prefix. Succeeds on correct string slice returned func (s *memLocationTest) TestListByPrefix() { - f1, nerr := s.fileSystem.NewFile("", "/foo.txt") s.NoError(nerr, "unexpected error creating a new file") s.NoError(f1.Touch(), "unexpected error touching file") @@ -108,7 +106,6 @@ func (s *memLocationTest) TestListByPrefix() { // TestListByRegex provides a simple regular expression and ensures that the correct fileNames matched that regEx func (s *memLocationTest) TestListByRegex() { - newFile, nerr := s.fileSystem.NewFile("", "/test_files/test.txt") s.NoError(nerr, "unexpected error creating a new file") @@ -129,7 +126,6 @@ func (s *memLocationTest) TestListByRegex() { actual2, err := newFile.Location().ListByRegex(regex2) s.NoError(err, "unexpected error listing by regEx") s.Equal(expected, actual2) - } // TestExists ensures that a real location exists, and one that was simply created does not @@ -142,7 +138,6 @@ func (s *memLocationTest) TestExists() { // TestNewLocation ensures that we can create new locations, even with relative dot paths func (s *memLocationTest) TestNewLocation() { - otherFile, nerr := s.fileSystem.NewFile("", "/foo/foo.txt") s.NoError(nerr, "unexpected error creating a new file") fileLocation := otherFile.Location() @@ -159,7 +154,6 @@ func (s *memLocationTest) TestNewLocation() { // TestNewLocationRelativePath tests to see whether a file can be made by passing a // relative path to a location object that technically does not exist func (s *memLocationTest) TestNewLocationRelativePath() { - newFile, nerr := s.fileSystem.NewFile("C", "/newLocTest/dir/file.txt") s.NoError(nerr, "unexpected error creating a file") @@ -177,7 +171,6 @@ func (s *memLocationTest) TestNewLocationRelativePath() { s.NoError(otherFile.Touch(), "unexpected error touching file") s.Equal(newFile.Location().Path(), otherFile.Location().Path(), "absolute location paths should be equal") - } // TestNewFile tests that location can create a file at its current path @@ -218,12 +211,10 @@ func (s *memLocationTest) TestNewFileSameName() { s.NoError(err, "unexpected read error") s.Equal(expectedText, string(expectedSlice)) - } // TestChangeDir tests that we can change the directory on a location but that it doesn't change the file's location func (s *memLocationTest) TestChangeDir() { - newFile, nerr := s.fileSystem.NewFile("", "/dir/to/change/change.txt") s.NoError(nerr, "unexpected error creating a new file") @@ -240,7 +231,6 @@ func (s *memLocationTest) TestChangeDir() { // TestVolume makes sure that the mem-fs returns the empty string for its volume func (s *memLocationTest) TestVolume() { - newFile, nerr := s.fileSystem.NewFile("D:", "/path/to/file/example.txt") s.NoError(nerr, "unexpected error creating a file") s.NoError(newFile.Touch(), "unexpected error touching file") @@ -289,7 +279,6 @@ func (s *memLocationTest) TestStringer() { // TestDeleteFile makes files, writes to them, deletes them, all while asserting things like existence and errors func (s *memLocationTest) TestDeleteFile() { - newFile, err := s.fileSystem.NewFile("", "/home/bar.txt") s.NoError(err, "unexpected error creating a new file") // attempt to delete newFile @@ -311,13 +300,11 @@ func (s *memLocationTest) TestDeleteFile() { existence1, eerr1 := otherFile.Exists() s.False(existence1) s.NoError(eerr1, "unexpected existence error") - } // TestWriteExistingFile tests that initializing a pre-existing file from a location, using a relative path will not result // in a blank file func (s *memLocationTest) TestWriteExistingFile() { - newFile, err := s.fileSystem.NewFile("", "/path/to/file/bar.txt") s.NoError(err, "unexpected error creating a new file") diff --git a/backend/mem/readwriteseeker.go b/backend/mem/readwriteseeker.go index 17347240..56080632 100644 --- a/backend/mem/readwriteseeker.go +++ b/backend/mem/readwriteseeker.go @@ -53,7 +53,6 @@ func (rws *ReadWriteSeeker) Read(p []byte) (n int, err error) { // Seek sets the cursor position. func (rws *ReadWriteSeeker) Seek(offset int64, whence int) (int64, error) { - var position int64 switch whence { case io.SeekStart: // io.SeekStart diff --git a/backend/os/file.go b/backend/os/file.go index 6cc98a46..91985b93 100644 --- a/backend/os/file.go +++ b/backend/os/file.go @@ -121,7 +121,6 @@ func (f *File) Close() error { // Read implements the io.Reader interface. It returns the bytes read and an error, if any. func (f *File) Read(p []byte) (int, error) { - // if we have not written to this file, ensure the original file exists if !f.useTempFile { if exists, err := f.Exists(); err != nil { @@ -397,7 +396,6 @@ func (f *File) openFile() (*os.File, error) { } func openOSFile(filePath string) (*os.File, error) { - // Ensure the path exists before opening the file, NoOp if dir already exists. var fileMode os.FileMode = 0666 if err := os.MkdirAll(path.Dir(filePath), os.ModeDir|0750); err != nil { diff --git a/backend/os/file_test.go b/backend/os/file_test.go index bd36e727..815907a5 100644 --- a/backend/os/file_test.go +++ b/backend/os/file_test.go @@ -66,7 +66,6 @@ func (s *osFileTest) TestExists() { } func (s *osFileTest) TestTouch() { - // set up testfile testfile, err := s.tmploc.NewFile("test_files/foo.txt") s.NoError(err) @@ -267,7 +266,6 @@ func (s *osFileTest) TestCopyToLocationIgnoreExtraSeparator() { location := Location{"/some/path/", otherFs} _, err := s.testFile.CopyToLocation(&location) - if err != nil { s.Fail(err.Error()) } @@ -723,7 +721,6 @@ func TestOSFile(t *testing.T) { Setup TEST FILES */ func setupTestFiles(baseLoc vfs.Location) { - // setup "test_files" dir createDir(baseLoc, "test_files") diff --git a/backend/s3/doc.go b/backend/s3/doc.go index 9460ca0c..75c235e4 100644 --- a/backend/s3/doc.go +++ b/backend/s3/doc.go @@ -28,7 +28,6 @@ s3 can be augmented with the following implementation-specific methods. Backend would have to be cast as s3.FileSystem to use the following: func DoSomething() { - ... // cast if fs was created using backend.Backend(). Not necessary if created directly from s3.NewFileSystem(). diff --git a/backend/s3/file.go b/backend/s3/file.go index af322f3a..6c6d1ddb 100644 --- a/backend/s3/file.go +++ b/backend/s3/file.go @@ -710,7 +710,6 @@ func (f *File) getReader() (io.ReadCloser, error) { // can't set range on empty file, so just return an empty ReadCloser f.reader = io.NopCloser(strings.NewReader("")) } else { - // Create the request to get the object input := new(s3.GetObjectInput). SetBucket(f.bucket). diff --git a/backend/s3/fileSystem_test.go b/backend/s3/fileSystem_test.go index 38e1b098..22589726 100644 --- a/backend/s3/fileSystem_test.go +++ b/backend/s3/fileSystem_test.go @@ -116,7 +116,6 @@ func (ts *fileSystemTestSuite) TestClient() { ts.NoError(err, "no error") ts.NotNil(client, "client was set") ts.NotNil(s3fs.client, "client was set") - } func TestFileSystem(t *testing.T) { diff --git a/backend/s3/file_test.go b/backend/s3/file_test.go index 03019966..d25162cf 100644 --- a/backend/s3/file_test.go +++ b/backend/s3/file_test.go @@ -49,7 +49,6 @@ func (ts *fileTestSuite) SetupTest() { testFileName = "/some/path/to/file.txt" bucket = "bucket" testFile, err = fs.NewFile(bucket, testFileName) - if err != nil { ts.Fail("Shouldn't return error creating test s3.File instance.") } @@ -426,7 +425,6 @@ func (ts *fileTestSuite) TestCopyToLocation() { // no error "copying" objects _, err := f.CopyToLocation(l) ts.NoError(err, "Shouldn't return error for this call to CopyToLocation") - } func (ts *fileTestSuite) TestTouch() { @@ -488,7 +486,6 @@ func (ts *fileTestSuite) TestTouch() { ts.NoError(terr2, "Shouldn't return error creating test s3.File instance.") s3Mock2.AssertExpectations(ts.T()) - } func (ts *fileTestSuite) TestMoveToLocation() { @@ -547,7 +544,6 @@ func (ts *fileTestSuite) TestMoveToLocation() { } func (ts *fileTestSuite) TestMoveToLocationFail() { - // If CopyToLocation fails we need to ensure DeleteObject isn't called. otherFs := new(vfsmocks.FileSystem) location := new(vfsmocks.Location) @@ -763,7 +759,6 @@ func (ts *fileTestSuite) TestCloseWithWrite() { ts.Error(err, "file doesn't exists , retired 5 times ") s3Mock.AssertExpectations(ts.T()) - } type fileTestCase struct { @@ -776,7 +771,6 @@ type fileTestCase struct { } func (ts *fileTestSuite) TestWriteOperations() { - // setup fake uploader oldfunc := getUploader defer func() { getUploader = oldfunc }() diff --git a/backend/s3/options.go b/backend/s3/options.go index a5039ad6..f859a07a 100644 --- a/backend/s3/options.go +++ b/backend/s3/options.go @@ -35,7 +35,6 @@ type Options struct { // getClient setup S3 client func getClient(opt Options) (s3iface.S3API, error) { - // setup default config awsConfig := defaults.Config() diff --git a/backend/sftp/doc.go b/backend/sftp/doc.go index 2908c34e..c221be23 100644 --- a/backend/sftp/doc.go +++ b/backend/sftp/doc.go @@ -37,7 +37,6 @@ These methods are chainable: (*FileSystem) WithOptions(opts vfs.Options) *FileSystem func DoSomething() { - // cast if fs was created using backend.Backend(). Not necessary if created directly from sftp.NewFilesystem(). fs := backend.Backend(sftp.Scheme) fs = fs.(*sftp.Filesystem) diff --git a/backend/sftp/file.go b/backend/sftp/file.go index cc800328..656405ab 100644 --- a/backend/sftp/file.go +++ b/backend/sftp/file.go @@ -195,7 +195,6 @@ func (f *File) MoveToFile(t vfs.File) error { // MoveToLocation works by creating a new file on the target location then calling MoveToFile() on it. func (f *File) MoveToLocation(location vfs.Location) (vfs.File, error) { - newFile, err := location.NewFile(f.Name()) if err != nil { return nil, err @@ -206,7 +205,6 @@ func (f *File) MoveToLocation(location vfs.Location) (vfs.File, error) { // CopyToFile puts the contents of File into the targetFile passed. func (f *File) CopyToFile(file vfs.File) (err error) { - // Close file (f) reader regardless of an error defer func() { // close writer @@ -244,7 +242,6 @@ func (f *File) CopyToFile(file vfs.File) (err error) { // CopyToLocation creates a copy of *File, using the file's current path as the new file's // path at the given location. func (f *File) CopyToLocation(location vfs.Location) (vfs.File, error) { - newFile, err := location.NewFile(f.Name()) if err != nil { return nil, err @@ -383,7 +380,6 @@ func (f *File) String() string { // openFile wrapper allows us to inject a file opener (for mocking) vs the defaultOpenFile. func (f *File) openFile(flags int) (ReadWriteSeekCloser, error) { //nolint:gocyclo // this function is complex by nature if f.sftpfile != nil { - // this case shouldn't normally exist except when we've set our own ReadWriteSeekCloser in tests if f.flagsUsed == 0 && !f.readCalled && !f.seekCalled { return f.sftpfile, nil @@ -392,7 +388,6 @@ func (f *File) openFile(flags int) (ReadWriteSeekCloser, error) { //nolint:gocyc needRw := false // check if the file is not already open in read-write mode if (f.flagsUsed & os.O_RDWR) == 0 { - // check if currently open for read only but now need write if f.flagsUsed == os.O_RDONLY && (flags&(os.O_WRONLY|os.O_RDWR)) != 0 { needRw = true diff --git a/backend/sftp/fileSystem.go b/backend/sftp/fileSystem.go index 3c2fdbee..bcfbab46 100644 --- a/backend/sftp/fileSystem.go +++ b/backend/sftp/fileSystem.go @@ -153,7 +153,6 @@ func (fs *FileSystem) connTimerStop() { // WithOptions sets options for client and returns the filesystem (chainable) func (fs *FileSystem) WithOptions(opts vfs.Options) *FileSystem { - // only set options if vfs.Options is sftp.Options if opts, ok := opts.(Options); ok { fs.options = opts diff --git a/backend/sftp/file_test.go b/backend/sftp/file_test.go index f071557c..2251d730 100644 --- a/backend/sftp/file_test.go +++ b/backend/sftp/file_test.go @@ -46,7 +46,6 @@ func (nopWriteCloser) Close() error { return nil } func (nopWriteCloser) Write(_ []byte) (n int, err error) { return 0, nil } func (ts *fileTestSuite) TestRead() { - // set up sftpfile filepath := "/some/path.txt" client := &mocks.Client{} @@ -77,7 +76,6 @@ func (ts *fileTestSuite) TestRead() { } func (ts *fileTestSuite) TestSeek() { - // set up sftpfile filepath := "/some/path.txt" client := &mocks.Client{} diff --git a/backend/sftp/location.go b/backend/sftp/location.go index f3c20603..ebbe162e 100644 --- a/backend/sftp/location.go +++ b/backend/sftp/location.go @@ -23,7 +23,6 @@ type Location struct { // List calls SFTP ReadDir to list all files in the location's path. // If you have many thousands of files at the given location, this could become quite expensive. func (l *Location) List() ([]string, error) { - var filenames []string client, err := l.fileSystem.Client(l.Authority) if err != nil { @@ -50,7 +49,6 @@ func (l *Location) List() ([]string, error) { // ListByPrefix calls SFTP ReadDir with the location's path modified relatively by the prefix arg passed to the function. func (l *Location) ListByPrefix(prefix string) ([]string, error) { - var filenames []string client, err := l.fileSystem.Client(l.Authority) if err != nil { @@ -91,7 +89,6 @@ func (l *Location) ListByPrefix(prefix string) ([]string, error) { // ListByRegex retrieves the filenames of all the files at the location's current path, then filters out all those // that don't match the given regex. The resource considerations of List() apply here as well. func (l *Location) ListByRegex(regex *regexp.Regexp) ([]string, error) { - filenames, err := l.List() if err != nil { return []string{}, err @@ -118,7 +115,6 @@ func (l *Location) Path() string { // Exists returns true if the remote SFTP file exists. func (l *Location) Exists() (bool, error) { - client, err := l.fileSystem.Client(l.Authority) if err != nil { return false, err diff --git a/backend/sftp/location_test.go b/backend/sftp/location_test.go index ae17f627..ba7723b0 100644 --- a/backend/sftp/location_test.go +++ b/backend/sftp/location_test.go @@ -70,7 +70,6 @@ func (lt *locationTestSuite) TestList() { } func (lt *locationTestSuite) TestListByPrefix() { - expectedFileList := []string{"file.txt", "file2.txt"} file1 := &mocks.FileInfo{} @@ -192,7 +191,6 @@ func (lt *locationTestSuite) TestVolume() { } func (lt *locationTestSuite) TestPath() { - loc, err := lt.sftpfs.NewLocation("host.com", "/path/") lt.NoError(err) lt.Equal("/path/", loc.Path(), "Path() should return the path on location.") diff --git a/backend/sftp/options.go b/backend/sftp/options.go index 071495e9..4f7a1f3a 100644 --- a/backend/sftp/options.go +++ b/backend/sftp/options.go @@ -105,7 +105,6 @@ var defaultSSHConfig = &ssh.ClientConfig{ } func getClient(authority utils.Authority, opts Options) (Client, io.Closer, error) { - // setup Authentication authMethods, err := getAuthMethods(opts) if err != nil { @@ -170,7 +169,6 @@ func getSShConfig(opts Options) *ssh.ClientConfig { func getHostKeyCallback(opts Options) (ssh.HostKeyCallback, error) { var knownHostsFiles []string switch { - // use explicit callback in Options case opts.KnownHostsCallback != nil: return opts.KnownHostsCallback, nil @@ -307,7 +305,6 @@ func getAuthMethods(opts Options) ([]ssh.AuthMethod, error) { } func getKeyFile(file, passphrase string) (key ssh.Signer, err error) { - buf, err := os.ReadFile(file) //nolint:gosec if err != nil { return diff --git a/backend/sftp/options_test.go b/backend/sftp/options_test.go index 67ec2726..4ba327c2 100644 --- a/backend/sftp/options_test.go +++ b/backend/sftp/options_test.go @@ -106,7 +106,6 @@ type getFileTest struct { } func (o *optionsSuite) TestGetKeyFile() { - tests := []getFileTest{ { keyfile: o.keyFiles.SSHPrivateKey, @@ -167,7 +166,6 @@ type hostkeyTest struct { } func (o *optionsSuite) TestGetHostKeyCallback() { - knwonHosts := filepath.Join(o.tmpdir, "known_hosts") f, err := os.Create(knwonHosts) //nolint:gosec o.NoError(err, "create file for getHostKeyCallback test") @@ -269,7 +267,6 @@ type authTest struct { } func (o *optionsSuite) TestGetAuthMethods() { - tests := []authTest{ { options: Options{ @@ -409,7 +406,6 @@ type getClientTest struct { } func (o *optionsSuite) TestGetClient() { - auth, err := utils.NewAuthority("someuser@badhost") o.NoError(err) diff --git a/backend/testsuite/backend_integration_test.go b/backend/testsuite/backend_integration_test.go index 5cd81111..2842378b 100644 --- a/backend/testsuite/backend_integration_test.go +++ b/backend/testsuite/backend_integration_test.go @@ -62,7 +62,6 @@ func (s *vfsTestSuite) SetupSuite() { panic(fmt.Sprintf("unknown scheme: %s", l.FileSystem().Scheme())) } } - } // Test File @@ -280,7 +279,6 @@ func (s *vfsTestSuite) Location(baseLoc vfs.Location) { myfile.Write("write some text") myfile.Close() - Now consider if the context is os/sftp OR gcs/s3/mem. ==== Exists() (bool, error) @@ -404,7 +402,6 @@ func (s *vfsTestSuite) Location(baseLoc vfs.Location) { // should error if file doesn't exist s.Error(srcLoc.DeleteFile(f1.Path()), "deleteFile trying to delete a file already deleted") - } // Test File @@ -855,7 +852,6 @@ func (s *vfsTestSuite) File(baseLoc vfs.Location) { s.Error(err, "expected error because file does not exist") // end existence tests - } // gs-specific test cases @@ -920,7 +916,6 @@ func (s *vfsTestSuite) gsList(baseLoc vfs.Location) { } func sftpRemoveAll(location *sftp.Location) error { - // get sftp client from Filesystem client, err := location.FileSystem().(*sftp.FileSystem).Client(location.Authority) if err != nil { @@ -932,7 +927,6 @@ func sftpRemoveAll(location *sftp.Location) error { } func recursiveSFTPRemove(absPath string, client sftp.Client) error { - // we can return early if we can just remove it err := client.Remove(absPath) // if we succeeded or it didn't exist, just return diff --git a/backend/testsuite/io_integration_test.go b/backend/testsuite/io_integration_test.go index d305de8d..ffe211c9 100644 --- a/backend/testsuite/io_integration_test.go +++ b/backend/testsuite/io_integration_test.go @@ -49,7 +49,7 @@ func (o *OSWrapper) Read(b []byte) (int, error) { return 0, errors.New("file not found") } if o.file == nil { - file, err := os.OpenFile(o.filename, os.O_RDWR, 0600) + file, err := os.OpenFile(o.filename, os.O_RDWR, 0o600) if err != nil { return 0, err } @@ -64,7 +64,7 @@ func (o *OSWrapper) Write(b []byte) (int, error) { if o.seekCalled { flags = os.O_RDWR | os.O_CREATE } - file, err := os.OpenFile(o.filename, flags, 0600) //nolint:gosec + file, err := os.OpenFile(o.filename, flags, 0o600) //nolint:gosec if err != nil { return 0, err } @@ -81,7 +81,7 @@ func (o *OSWrapper) Seek(offset int64, whence int) (int64, error) { } if o.file == nil { - file, err := os.OpenFile(o.filename, os.O_RDWR, 0600) + file, err := os.OpenFile(o.filename, os.O_RDWR, 0o600) if err != nil { return 0, err } @@ -224,7 +224,8 @@ func (s *ioTestSuite) testFileOperations(testPath string) { }, // Read, Seek, Read, Close - {"Read, Seek, Read, Close, file exists", + { + "Read, Seek, Read, Close, file exists", "R(4);S(0,0);R(4);C()", true, false, @@ -358,7 +359,6 @@ func (s *ioTestSuite) testFileOperations(testPath string) { // run in a closure so we can defer teardown func() { - // Setup vfs environment file, err := s.setupTestFile(tc.fileAlreadyExists, testPath, testFileName) // Implement this setup function defer func() { @@ -484,7 +484,6 @@ SEQ: t.Fatalf("error reading file: %s", err.Error()) } return string(contents), nil - } var commandArgsRegex = regexp.MustCompile(`^([a-zA-Z0-9]+)\((.*)\)$`) @@ -538,7 +537,6 @@ func (s *ioTestSuite) teardownTestLocation(t *testing.T, testPath string) { t.Fatal(err) } } else { - scheme := strings.Split(testPath, ":")[0] // Write something to the file loc := s.testLocations[scheme] diff --git a/docs/azure.md b/docs/azure.md index 87cbee66..ce2d05a4 100644 --- a/docs/azure.md +++ b/docs/azure.md @@ -5,7 +5,6 @@ Package azure Microsoft Azure Blob Storage VFS Implementation - ### Usage Rely on github.com/c2fo/vfs/backend @@ -39,7 +38,6 @@ azure.Filesystem to use the following: ```go func DoSomething() { - ... // cast if fs was created using backend.Backend(). Not necessary if created directly from azure.NewFilesystem(). @@ -202,7 +200,6 @@ func (a *DefaultClient) Delete(file vfs.File) error Deletes the file blob using Azure's delete blob api, then each version of the blob is deleted using Azure's delete api. NOTE that if soft deletion is enabled for the blobs in the storage account, each version will be marked as deleted and will get permanently deleted by Azure as per the soft deletion policy. Returns any error returned by the API. - #### func (*DefaultClient) Download ```go diff --git a/docs/backend.md b/docs/backend.md index b387ca78..e6b37df6 100644 --- a/docs/backend.md +++ b/docs/backend.md @@ -2,7 +2,6 @@ --- - Package backend provides a means of allowing backend file systems to self-register on load via an init() call to backend.Register("some scheme", vfs.FileSystem) @@ -45,7 +44,7 @@ In this way, a caller of vfs backends can simply load the backend file system ### Development To create your own backend, you must create a package that implements the interfaces: -[vfs.FileSystem](../README.md#type-filesystem), [vfs.Location](../README.md#type-location), and +[vfs.FileSystem](../README.md#type-filesystem), [vfs.Location](../README.md#type-location), and [vfs.File](../README.md#type-file). Then ensure it registers itself on load: ```go diff --git a/docs/delete_options.md b/docs/delete_options.md index 777b2425..ec626009 100644 --- a/docs/delete_options.md +++ b/docs/delete_options.md @@ -17,7 +17,7 @@ Delete file using file.delete(): "github.com/c2fo/vfs/v6/options" "github.com/c2fo/vfs/v6/options/delete" ) - + func DeleteFile() error { file, err := fs.NewFile(bucketName, fileName) ... @@ -35,9 +35,9 @@ Delete file using location.delete(): "github.com/c2fo/vfs/v6/options" "github.com/c2fo/vfs/v6/options/delete" ) - + func DeleteFileUsingLocation() error { err = location.DeleteFile("filename.txt", delete.WithDeleteAllVersions()) ... } -``` \ No newline at end of file +``` diff --git a/docs/ftp.md b/docs/ftp.md index 2d4804dc..f8a3c774 100644 --- a/docs/ftp.md +++ b/docs/ftp.md @@ -2,10 +2,8 @@ --- - Package ftp - FTP VFS implementation. - ### Usage Rely on [github.com/c2fo/vfs/v6/backend](backend.md) @@ -47,7 +45,6 @@ These methods are chainable: (*FileSystem) WithClient(client interface{}) ```go func DoSomething() { - // cast if fs was created using backend.Backend(). Not necessary if created directly from ftp.NewFilesystem(). fs := backend.Backend(ftp.Scheme) fs = fs.(*ftp.Filesystem) @@ -90,7 +87,6 @@ The provided CopyToFile and CopyToLocation functions should be used instead in t ```go func DoSomething() { - // cast if fs was created using backend.Backend(). Not necessary if created directly from ftp.NewFilesystem(). fs := backend.Backend(ftp.Scheme) fs = fs.(*ftp.Filesystem) @@ -178,14 +174,13 @@ overridden(recommended) with Options.TLSConfig: See https://pkg.go.dev/crypto/tls#Config for all TLS configuration options. - ### Other Options DebugWriter *io.Writer* - captures FTP command details to any writer. DialTimeout *time.Duration - sets timeout for connecting only. -DisableEPSV bool - Extended Passive mode (EPSV) is attempted by default. Set to true to use regular Passive mode (PASV). +DisableEPSV bool - Extended Passive mode (EPSV) is attempted by default. Set to true to use regular Passive mode (PASV). ## Usage diff --git a/docs/gs.md b/docs/gs.md index 8b87c75a..1029c0d4 100644 --- a/docs/gs.md +++ b/docs/gs.md @@ -2,10 +2,8 @@ --- - Package gs Google Cloud Storage VFS implementation. - ### Usage Rely on [github.com/c2fo/vfs/v6/backend](backend.md) @@ -39,7 +37,6 @@ use the following: ```go func DoSomething() { - ... // cast if fs was created using backend.Backend(). Not necessary if created directly from gs.NewFilsystem(). @@ -80,7 +77,6 @@ found: See https://cloud.google.com/docs/authentication/production for more auth info - ### See Also See: https://github.com/googleapis/google-cloud-go/tree/master/storage @@ -134,8 +130,8 @@ to the new file. func (f *File) Delete(opts ...options.DeleteOption) error ``` Delete clears any local temp file, or write buffer from read/writes to the file, -then makes a DeleteObject call to GCS for the file. If opts is of type DeleteAllVersions, DeleteObject call is made to -GCS for each version of the file. Returns any error returned by the API. +then makes a DeleteObject call to GCS for the file. If opts is of type DeleteAllVersions, DeleteObject call is made to +GCS for each version of the file. Returns any error returned by the API. #### func (*File) Exists diff --git a/docs/mem.md b/docs/mem.md index f05949a7..f039912f 100644 --- a/docs/mem.md +++ b/docs/mem.md @@ -1,11 +1,10 @@ -# mem +#vfsSimpleSuitemem --- -Package mem, in-memory backend VFS implementation. +Package mem, in-memory backend VFS implementation. - -### Usage +### Usage Rely on github.com/c2fo/vfs/v6/backend @@ -24,7 +23,7 @@ Or call directly: ```go import _mem "github.com/c2fo/vfs/v6/backend/mem" - + func DoSomething() { fs := _mem.NewFileSystem() ... @@ -205,13 +204,11 @@ FileSystem implements vfs.FileSystem for an in-memory file system. #### func NewFileSystem - ```go func NewFileSystem() *FileSystem ``` NewFileSystem is used to initialize the file system struct for an in-memory FileSystem. - #### func (*FileSystem) Name ```go diff --git a/docs/options.md b/docs/options.md index c1c36246..3f7c9b76 100644 --- a/docs/options.md +++ b/docs/options.md @@ -2,8 +2,7 @@ --- - -Package options provides a means of creating custom options that can be used with operations that are performed on components of filesystem. +Package options provides a means of creating custom options that can be used with operations that are performed on components of filesystem. ## DeleteOption Currently, we define DeleteOption interface that can be used to implement custom options that can be used for delete operation. One such implementation is the [DeleteAllVersions](./delete_options.md#DeleteAllVersions) option. @@ -36,7 +35,7 @@ Now, in each implementation of file.Delete(... options.DeleteOptions), implement case delete.DeleteAllVersions: deleteAllVersions = true case delete.MyTakeBackupDeleteOption: - // do something to take backup + // do something to take backup default: } } diff --git a/docs/os.md b/docs/os.md index 15f40c26..2afbc5af 100644 --- a/docs/os.md +++ b/docs/os.md @@ -4,7 +4,6 @@ Package os built-in os lib VFS implementation. - ### Usage Rely on github.com/c2fo/vfs/v6/backend @@ -112,7 +111,7 @@ func (f *File) MoveToFile(target vfs.File) error ``` MoveToFile move a file. It accepts a target vfs.File and returns an error, if any. - + __TODO:__ we might consider using os.Rename() for efficiency when target.Location().FileSystem().Scheme equals f.Location().FileSystem().Scheme() @@ -122,7 +121,7 @@ target.Location().FileSystem().Scheme equals f.Location().FileSystem().Scheme() func (f *File) MoveToLocation(location vfs.Location) (vfs.File, error) ``` MoveToLocation moves a file to a new Location. It accepts a target vfs.Location -and returns a vfs.File and an error, if any. +and returns a vfs.File and an error, if any. __TODO:__ we might consider using os.Rename() for efficiency when location.FileSystem().Scheme() equals f.Location().FileSystem().Scheme() diff --git a/docs/s3.md b/docs/s3.md index 168664f8..8b167668 100644 --- a/docs/s3.md +++ b/docs/s3.md @@ -4,7 +4,6 @@ Package s3 AWS S3 VFS implementation. - ### Usage Rely on github.com/c2fo/vfs/v6/backend @@ -38,7 +37,6 @@ use the following: ```go func DoSomething() { - ... // cast if fs was created using backend.Backend(). Not necessary if created directly from s3.NewFilsystem(). @@ -64,7 +62,6 @@ use the following: } ``` - ### Object ACL Canned ACL's can be passed in as an Option. This string will be applied to all writes, moves, and copies. @@ -97,7 +94,6 @@ See the following for more auth info: https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-envvars.html and https://docs.aws.amazon.com/sdk-for-go/v1/developer-guide/configuring-sdk.html - ### See Also See: https://github.com/aws/aws-sdk-go/tree/master/service/s3 diff --git a/docs/sftp.md b/docs/sftp.md index 7709e496..b8a17620 100644 --- a/docs/sftp.md +++ b/docs/sftp.md @@ -2,13 +2,11 @@ --- - Package sftp SFTP VFS implementation. In this backend, any new FileSystem instance is a new connection to the remote server. It may be impolite to take up a large number of a server's available connections, so better to use the same filesystem. - ### Usage Rely on github.com/c2fo/vfs/v6/backend @@ -52,7 +50,6 @@ These methods are chainable: ```go func DoSomething() { - // cast if fs was created using backend.Backend(). Not necessary if created directly from sftp.NewFilesystem(). fs := backend.Backend(sftp.Scheme) fs = fs.(*sftp.Filesystem) @@ -94,7 +91,6 @@ These methods are chainable: } ``` - ### Authentication Authentication, by default, occurs automatically when [Client()](#func-filesystem-client) is called. Since @@ -103,11 +99,10 @@ differently than other vfs [backends](backend.md). A client is initialized lazily, meaning we only make a connection to the server at the last moment so we are free to modify options until then. The -authenticated session is closed any time [WithOption()](#func-filesystem-withoptions), [WithClient()](#func-filesystem-withclient), +authenticated session is closed any time [WithOption()](#func-filesystem-withoptions), [WithClient()](#func-filesystem-withclient), or [Close()](#func-file-close) occurs. Currently, that means that closing a file belonging to an fs will break the connection of any other open file on the same fs. - #### USERNAME User may only be set in the [URI authority](https://tools.ietf.org/html/rfc3986#section-3.2) section (Volume in vfs parlance). @@ -133,18 +128,17 @@ SSH keys may be passed via [Options](#type-options).KeyFilePath and (optionally) [Options](#type-options).KeyPassphrase. They can also be passed via environmental variables `VFS_SFTP_KEYFILE` and `VFS_SFTP_KEYFILE_PASSPHRASE`, respectively. - ### Known Hosts Known hosts ensures that the server you're connecting to hasn't been somehow redirected to another server, collecting your info (man-in-the-middle attack). -Handling for this can be accomplished via: +Handling for this can be accomplished via: -1. [Options](#type-options).KnownHostsString which accepts a string. +1. [Options](#type-options).KnownHostsString which accepts a string. 2. [Options](#type-options).KnownHostsFile or environmental variable `VFS_SFTP_KNOWN_HOSTS_FILE` which accepts a path to a known_hosts file. 3. [Options](#type-options).KnownHostsCallback which allows you to specify any of the [ssh.AuthMethod](https://godoc.org/golang.org/x/crypto/ssh#AuthMethod) -functions. Environmental variable `VFS_SFTP_INSECURE_KNOWN_HOSTS` will set this callback function to -[ssh.InsecureIgnoreHostKey](https://godoc.org/golang.org/x/crypto/ssh#InsecureIgnoreHostKey) which may be helpful for +functions. Environmental variable `VFS_SFTP_INSECURE_KNOWN_HOSTS` will set this callback function to +[ssh.InsecureIgnoreHostKey](https://godoc.org/golang.org/x/crypto/ssh#InsecureIgnoreHostKey) which may be helpful for testing but should not be used in production. 4. Defaults to trying to find and use /.ssh/known_hosts. For unix, system-wide location /etc/ssh/.ssh/known hosts is also checked. SSH doesn't exist natively on Windows and each third-party implementation has a different location for known_hosts. Because of this, no attempt is made to find a system-wide file for Windows. It's better to specify in KnownHostsFile in that case. @@ -207,7 +201,7 @@ should be the most desirable behavior. ``` NOTE: AutoDisconnect has nothing to do with "keep alive". Here we're only concerned with releasing resources, not keeping -the server from disconnecting us. If that is something you want, you'd have to implement yourself, injecting your own +the server from disconnecting us. If that is something you want, you'd have to implement yourself, injecting your own client using WithClient(). ## Usage diff --git a/docs/utils.md b/docs/utils.md index 91fdc8b5..66ae77d6 100644 --- a/docs/utils.md +++ b/docs/utils.md @@ -2,7 +2,6 @@ --- - ```go import "github.com/c2fo/vfs/v6/utils" ``` @@ -61,9 +60,9 @@ GetLocationURI returns a Location URI ```go func PathToURI(p string) (string, error) ``` -PathToURI takes a relative or absolute path and returns an OS URI. -* We assume non-scheme path is an OS File or Location. -* We assume volume(URI authority) is empty. +PathToURI takes a relative or absolute path and returns an OS URI. +* We assume non-scheme path is an OS File or Location. +* We assume volume(URI authority) is empty. * We assume relative paths are relative to the pwd (program's working directory) * We assum an empty path is equal to the root path: "/" diff --git a/docs/vfscp.md b/docs/vfscp.md index 25baa668..5a0b7d79 100644 --- a/docs/vfscp.md +++ b/docs/vfscp.md @@ -6,7 +6,6 @@ vfscp copies a file from one place to another, even between supported remote systems. Complete URI (scheme:// authority/path) required except for local file system. See github.com/c2fo/vfs docs for authentication. - ### Usage vfscp's usage is extremely simple: @@ -14,7 +13,6 @@ vfscp's usage is extremely simple: vfscp -help prints help message - ### Examples Local OS URI's can be expressed without a scheme: @@ -28,4 +26,4 @@ But may also be use the full scheme uri: Copy a file from Google Cloud Storage to Amazon S3 ```bash vfscp gs://googlebucket/some/path/photo.jpg s3://awsS3bucket/path/to/photo.jpg -``` \ No newline at end of file +``` diff --git a/docs/vfssimple.md b/docs/vfssimple.md index c631daa5..eecbaaae 100644 --- a/docs/vfssimple.md +++ b/docs/vfssimple.md @@ -9,7 +9,6 @@ supported backend file system by using full URI's: * Amazon S3: s3://mybucket/path/to/file.txt * Google Cloud Storage: gs://mybucket/path/to/file.txt - ### Usage Just import vfssimple. @@ -131,16 +130,16 @@ when calling remote file systems. This adds some flexibility in how a retry on f ```go package main - + import( "time" - + "github.com/c2fo/vfs/v6/backend" "github.com/c2fo/vfs/v6/backend/gs" ) - + ... - + func InitializeWithRetry() error { bucketAuth := gs.NewFileSystem().WithOptions(gs.Options{ Retry: func(wrapper func() error) error { diff --git a/utils/utils.go b/utils/utils.go index a1954583..d29ce761 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -92,7 +92,6 @@ func GetFileURI(f vfs.File) string { // GetLocationURI returns a Location URI func GetLocationURI(l vfs.Location) string { - return fmt.Sprintf("%s://%s%s", l.FileSystem().Scheme(), l.Volume(), l.Path()) } @@ -228,7 +227,6 @@ func UpdateLastModifiedByMoving(file vfs.File) error { // SeekTo is a helper function for Seek. It takes the current position, offset, whence, and length of the file // and returns the new position. It also checks for invalid offsets and returns an error if one is found. func SeekTo(length, position, offset int64, whence int) (int64, error) { - switch whence { default: return 0, vfs.ErrSeekInvalidWhence diff --git a/utils/utils_test.go b/utils/utils_test.go index 9f2be70a..c6f58a75 100644 --- a/utils/utils_test.go +++ b/utils/utils_test.go @@ -615,7 +615,6 @@ func (s *utilsSuite) TestPathToURI() { } func (s *utilsSuite) TestGetURI() { - // set up mocks mockFs1 := new(mocks.FileSystem) mockFs1.On("Scheme", mock.Anything).Return("file") @@ -651,7 +650,6 @@ func (s *utilsSuite) TestGetURI() { } func (s *utilsSuite) TestTouchCopy() { - // write out blank file tmpfile, err := os.CreateTemp("", "utils_test") if err != nil { @@ -728,11 +726,9 @@ func (s *utilsSuite) TestTouchCopy() { s.NoError(err, "unexpected error creating vfs.File reader for non-existent file") err = utils.TouchCopy(writer, noFile) s.Error(err, "expected error running TouchCopy() using non-existent reader") - } func (s *utilsSuite) TestTouchCopyBufferedDefaultBufferSize() { - // write out blank file tmpfile, err := os.CreateTemp("", "utils_test") if err != nil { @@ -809,11 +805,9 @@ func (s *utilsSuite) TestTouchCopyBufferedDefaultBufferSize() { s.NoError(err, "unexpected error creating vfs.File reader for non-existent file") err = utils.TouchCopyBuffered(writer, noFile, 0) s.Error(err, "expected error running TouchCopyBuffered() using non-existent reader") - } func (s *utilsSuite) TestTouchCopyBufferedNonDefaultBufferSize() { - // write out blank file tmpfile, err := os.CreateTemp("", "utils_test") if err != nil { @@ -890,7 +884,6 @@ func (s *utilsSuite) TestTouchCopyBufferedNonDefaultBufferSize() { s.NoError(err, "unexpected error creating vfs.File reader for non-existent file") err = utils.TouchCopyBuffered(writer, noFile, 1048576) s.Error(err, "expected error running TouchCopyBuffered() using non-existent reader") - } // TestSeekTo tests the seekTo function with various cases diff --git a/vfscp/vfscp.go b/vfscp/vfscp.go index 0075e205..e8b9a76b 100644 --- a/vfscp/vfscp.go +++ b/vfscp/vfscp.go @@ -78,7 +78,6 @@ func copyFiles(srcFileURI, targetFileURI string) { } fmt.Print(green.Sprint("done\n\n")) - } func failMessage(err error) { diff --git a/vfssimple/vfssimple_test.go b/vfssimple/vfssimple_test.go index 04555a67..9c8d3b33 100644 --- a/vfssimple/vfssimple_test.go +++ b/vfssimple/vfssimple_test.go @@ -305,6 +305,7 @@ func (s *vfssimplesuite) TestParseSupportedURI() { } } } + func (s *vfssimplesuite) TestNewFile() { backend.Register("s3://filetest/path/", s3.NewFileSystem().WithClient(getS3NamedClientMock("filetest-path"))) backend.Register("s3://filetest/", s3.NewFileSystem().WithClient(getS3NamedClientMock("filetest-bucket")))