cache,chunker,combine,compress,crypt,hasher,union: implement MkdirMetadata and related Features

This commit is contained in:
Nick Craig-Wood
2024-02-28 16:09:04 +00:00
parent 0297542f6b
commit 39db8caff1
9 changed files with 315 additions and 81 deletions
+51 -1
View File
@@ -27,6 +27,7 @@ type Object struct {
// This is a wrapped object contains all candidates
type Directory struct {
*upstream.Directory
fs *Fs // what this directory is part of
cd []upstream.Entry
}
@@ -227,7 +228,56 @@ func (d *Directory) Size() (s int64) {
return s
}
// SetMetadata sets metadata for an DirEntry
//
// It should return fs.ErrorNotImplemented if it can't set metadata
func (d *Directory) SetMetadata(ctx context.Context, metadata fs.Metadata) error {
entries, err := d.fs.actionEntries(d.candidates()...)
if err != nil {
return err
}
var wg sync.WaitGroup
errs := Errors(make([]error, len(entries)))
multithread(len(entries), func(i int) {
if d, ok := entries[i].(*upstream.Directory); ok {
err := d.SetMetadata(ctx, metadata)
if err != nil {
errs[i] = fmt.Errorf("%s: %w", d.UpstreamFs().Name(), err)
}
} else {
errs[i] = fs.ErrorIsFile
}
})
wg.Wait()
return errs.Err()
}
// SetModTime sets the metadata on the DirEntry to set the modification date
//
// If there is any other metadata it does not overwrite it.
func (d *Directory) SetModTime(ctx context.Context, t time.Time) error {
entries, err := d.fs.actionEntries(d.candidates()...)
if err != nil {
return err
}
var wg sync.WaitGroup
errs := Errors(make([]error, len(entries)))
multithread(len(entries), func(i int) {
if d, ok := entries[i].(*upstream.Directory); ok {
err := d.SetModTime(ctx, t)
if err != nil {
errs[i] = fmt.Errorf("%s: %w", d.UpstreamFs().Name(), err)
}
} else {
errs[i] = fs.ErrorIsFile
}
})
wg.Wait()
return errs.Err()
}
// Check the interfaces are satisfied
var (
_ fs.FullObject = (*Object)(nil)
_ fs.FullObject = (*Object)(nil)
_ fs.FullDirectory = (*Directory)(nil)
)