Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

internal/provider: fix memFile implement #162

Merged
merged 2 commits into from
Sep 16, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions internal/provider/atlas_migration_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -693,10 +693,9 @@ type (
migrate.Dir
latestIndex int
}
// memFile implements fs.File.
// memFile implements the File interface for a file in memory.
memFile struct {
io.Reader
fs.FileInfo
io.ReadCloser
}
)

Expand All @@ -707,11 +706,20 @@ var (

// NewMemFile returns a new in-memory file.
func NewMemFile(f io.Reader) fs.File {
return &memFile{Reader: f}
if c, ok := f.(io.ReadCloser); ok {
return &memFile{ReadCloser: c}
}
return &memFile{ReadCloser: io.NopCloser(f)}
}

func (f *memFile) Close() error { return nil }
func (f *memFile) Stat() (fs.FileInfo, error) { return f.FileInfo, nil }
// Stat returns a zero FileInfo.
func (m *memFile) Stat() (fs.FileInfo, error) { return m, nil }
func (m *memFile) Name() string { return "" }
func (m *memFile) Size() int64 { return 0 }
func (m *memFile) Mode() fs.FileMode { return 0 }
func (m *memFile) ModTime() time.Time { return time.Time{} }
func (m *memFile) IsDir() bool { return false }
func (m *memFile) Sys() interface{} { return nil }

// NewChunkedDir returns a new Dir that only contains migrations up to the
// given version. (inclusive)
Expand Down
Loading