Skip to content

Commit

Permalink
added optional interface AppendableRepository extending WritableRepos…
Browse files Browse the repository at this point in the history
…itory
  • Loading branch information
mbaklor committed Nov 2, 2024
1 parent eeb8511 commit ed1fd11
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 deletions.
3 changes: 1 addition & 2 deletions internal/driver/mobile/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ var _ repository.Repository = (*mobileFileRepo)(nil)
var _ repository.HierarchicalRepository = (*mobileFileRepo)(nil)
var _ repository.ListableRepository = (*mobileFileRepo)(nil)
var _ repository.WritableRepository = (*mobileFileRepo)(nil)
var _ repository.AppendableRepository = (*mobileFileRepo)(nil)

type mobileFileRepo struct {
}
Expand Down Expand Up @@ -70,8 +71,6 @@ func (m *mobileFileRepo) Writer(u fyne.URI) (fyne.URIWriteCloser, error) {
return fileWriterForURI(u, true)
}

// TODO: need someone who understands native code to write this, I'm not sure
// how it works
func (m *mobileFileRepo) Appender(u fyne.URI) (fyne.URIWriteCloser, error) {
return fileWriterForURI(u, false)
}
3 changes: 2 additions & 1 deletion internal/repository/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const fileSchemePrefix string = "file://"
// declare conformance with repository types
var _ repository.Repository = (*FileRepository)(nil)
var _ repository.WritableRepository = (*FileRepository)(nil)
var _ repository.AppendableRepository = (*FileRepository)(nil)
var _ repository.HierarchicalRepository = (*FileRepository)(nil)
var _ repository.ListableRepository = (*FileRepository)(nil)
var _ repository.MovableRepository = (*FileRepository)(nil)
Expand Down Expand Up @@ -130,7 +131,7 @@ func (r *FileRepository) Writer(u fyne.URI) (fyne.URIWriteCloser, error) {
return openFile(u, true, true)
}

// Appender implements repository.WritableRepository.Appender
// Appender implements repository.AppendableRepository.Appender
//
// Since: 2.6
func (r *FileRepository) Appender(u fyne.URI) (fyne.URIWriteCloser, error) {
Expand Down
3 changes: 2 additions & 1 deletion internal/repository/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var _ fyne.URIWriteCloser = (*nodeReaderWriter)(nil)
// declare conformance with repository types
var _ repository.Repository = (*InMemoryRepository)(nil)
var _ repository.WritableRepository = (*InMemoryRepository)(nil)
var _ repository.AppendableRepository = (*InMemoryRepository)(nil)
var _ repository.HierarchicalRepository = (*InMemoryRepository)(nil)
var _ repository.CopyableRepository = (*InMemoryRepository)(nil)
var _ repository.MovableRepository = (*InMemoryRepository)(nil)
Expand Down Expand Up @@ -210,7 +211,7 @@ func (m *InMemoryRepository) Writer(u fyne.URI) (fyne.URIWriteCloser, error) {
return &nodeReaderWriter{path: path, repo: m}, nil
}

// Appender implements repository.WritableRepository.Appender
// Appender implements repository.AppendableRepository.Appender
//
// Since: 2.6
func (m *InMemoryRepository) Appender(u fyne.URI) (fyne.URIWriteCloser, error) {
Expand Down
20 changes: 14 additions & 6 deletions storage/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,6 @@ type WritableRepository interface {
// Since: 2.0
Writer(u fyne.URI) (fyne.URIWriteCloser, error)

// Appender will be used to call a Writer without truncating the
// file if it exists
//
// Since: 2.6
Appender(u fyne.URI) (fyne.URIWriteCloser, error)

// CanWrite will be used to implement calls to storage.CanWrite() for
// the registered scheme of this repository.
//
Expand All @@ -127,6 +121,20 @@ type WritableRepository interface {
Delete(u fyne.URI) error
}

// AppendableRepository is an extension of the WritableRepository interface which also
// supports opening a writer for URIs in append mode, without truncating their contents
//
// Since: 2.0
type AppendableRepository interface {
WritableRepository

// Appender will be used to call a Writer without truncating the
// file if it exists
//
// Since: 2.6
Appender(u fyne.URI) (fyne.URIWriteCloser, error)
}

// ListableRepository is an extension of the Repository interface which also
// supports obtaining directory listings (generally analogous to a directory
// listing) for URIs of the scheme it is registered to.
Expand Down
4 changes: 2 additions & 2 deletions storage/uri.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ func Writer(u fyne.URI) (fyne.URIWriteCloser, error) {
// in some way.
//
// - If the scheme of the given URI does not have a registered
// WritableRepository instance, then this method will fail with a
// AppendableRepository instance, then this method will fail with a
// repository.ErrOperationNotSupported.
//
// Appender is backed by the repository system - this function calls into a
Expand All @@ -318,7 +318,7 @@ func Appender(u fyne.URI) (fyne.URIWriteCloser, error) {
return nil, err
}

wrepo, ok := repo.(repository.WritableRepository)
wrepo, ok := repo.(repository.AppendableRepository)
if !ok {
return nil, repository.ErrOperationNotSupported
}
Expand Down

0 comments on commit ed1fd11

Please sign in to comment.