@@ -129,7 +129,7 @@ func (f *Fs) Rmdir(ctx context.Context, dir string) error {
129129 if err != nil {
130130 // If none of the backends can have empty directories then
131131 // don't complain about directories not being found
132- if ! f .features .CanHaveEmptyDirectories && err == fs .ErrorObjectNotFound {
132+ if ! f .features .CanHaveEmptyDirectories && errors . Is ( err , fs .ErrorObjectNotFound ) {
133133 return nil
134134 }
135135 return err
@@ -150,12 +150,12 @@ func (f *Fs) Hashes() hash.Set {
150150}
151151
152152// mkdir makes the directory passed in and returns the upstreams used
153- func (f * Fs ) mkdir (ctx context.Context , dir string ) ([]* upstream.Fs , error ) {
153+ func (f * Fs ) mkdir (ctx context.Context , dir string , withMetadata bool ) ([]* upstream.Fs , error ) {
154154 upstreams , err := f .create (ctx , dir )
155- if err == fs .ErrorObjectNotFound {
155+ if errors . Is ( err , fs .ErrorObjectNotFound ) {
156156 parent := parentDir (dir )
157157 if dir != parent {
158- upstreams , err = f .mkdir (ctx , parent )
158+ upstreams , err = f .mkdir (ctx , parent , withMetadata )
159159 } else if dir == "" {
160160 // If root dirs not created then create them
161161 upstreams , err = f .upstreams , nil
@@ -164,17 +164,38 @@ func (f *Fs) mkdir(ctx context.Context, dir string) ([]*upstream.Fs, error) {
164164 if err != nil {
165165 return nil , err
166166 }
167+
168+ metadataSet := fs .GetConfig (ctx ).MetadataSet
169+
167170 errs := Errors (make ([]error , len (upstreams )))
168171 multithread (len (upstreams ), func (i int ) {
169- err := upstreams [i ].Mkdir (ctx , dir )
170- if err != nil {
171- errs [i ] = fmt .Errorf ("%s: %w" , upstreams [i ].Name (), err )
172+ u := upstreams [i ]
173+ if withMetadata && metadataSet != nil {
174+ if do := u .Features ().MkdirMetadata ; do != nil {
175+ _ , err := do (ctx , dir , metadataSet )
176+ if err != nil {
177+ errs [i ] = fmt .Errorf ("%s: %w" , u .Name (), err )
178+ }
179+
180+ } else {
181+ // Just do Mkdir on upstreams which don't support MkdirMetadata
182+ err := u .Mkdir (ctx , dir )
183+ if err != nil {
184+ errs [i ] = fmt .Errorf ("%s: %w" , u .Name (), err )
185+ }
186+ }
187+ } else {
188+ err := u .Mkdir (ctx , dir )
189+ if err != nil {
190+ errs [i ] = fmt .Errorf ("%s: %w" , u .Name (), err )
191+ }
172192 }
173193 })
174194 err = errs .Err ()
175195 if err != nil {
176196 return nil , err
177197 }
198+
178199 // If created roots then choose one
179200 if dir == "" {
180201 upstreams , err = f .create (ctx , dir )
@@ -184,7 +205,7 @@ func (f *Fs) mkdir(ctx context.Context, dir string) ([]*upstream.Fs, error) {
184205
185206// Mkdir makes the root directory of the Fs object
186207func (f * Fs ) Mkdir (ctx context.Context , dir string ) error {
187- _ , err := f .mkdir (ctx , dir )
208+ _ , err := f .mkdir (ctx , dir , false )
188209 return err
189210}
190211
@@ -201,19 +222,19 @@ func (f *Fs) MkdirMetadata(ctx context.Context, dir string, metadata fs.Metadata
201222 if do := u .Features ().MkdirMetadata ; do != nil {
202223 newDir , err := do (ctx , dir , metadata )
203224 if err != nil {
204- errs [i ] = fmt .Errorf ("%s: %w" , upstreams [ i ] .Name (), err )
225+ errs [i ] = fmt .Errorf ("%s: %w" , u .Name (), err )
205226 } else {
206227 entries [i ], err = u .WrapEntry (newDir )
207228 if err != nil {
208- errs [i ] = fmt .Errorf ("%s: %w" , upstreams [ i ] .Name (), err )
229+ errs [i ] = fmt .Errorf ("%s: %w" , u .Name (), err )
209230 }
210231 }
211232
212233 } else {
213234 // Just do Mkdir on upstreams which don't support MkdirMetadata
214235 err := u .Mkdir (ctx , dir )
215236 if err != nil {
216- errs [i ] = fmt .Errorf ("%s: %w" , upstreams [ i ] .Name (), err )
237+ errs [i ] = fmt .Errorf ("%s: %w" , u .Name (), err )
217238 }
218239 }
219240 })
@@ -533,8 +554,8 @@ func multiReader(n int, in io.Reader) ([]io.Reader, <-chan error) {
533554func (f * Fs ) put (ctx context.Context , in io.Reader , src fs.ObjectInfo , stream bool , options ... fs.OpenOption ) (fs.Object , error ) {
534555 srcPath := src .Remote ()
535556 upstreams , err := f .create (ctx , srcPath )
536- if err == fs .ErrorObjectNotFound {
537- upstreams , err = f .mkdir (ctx , parentDir (srcPath ))
557+ if errors . Is ( err , fs .ErrorObjectNotFound ) {
558+ upstreams , err = f .mkdir (ctx , parentDir (srcPath ), true )
538559 }
539560 if err != nil {
540561 return nil , err
@@ -593,10 +614,10 @@ func (f *Fs) put(ctx context.Context, in io.Reader, src fs.ObjectInfo, stream bo
593614// nil and the error
594615func (f * Fs ) Put (ctx context.Context , in io.Reader , src fs.ObjectInfo , options ... fs.OpenOption ) (fs.Object , error ) {
595616 o , err := f .NewObject (ctx , src .Remote ())
596- switch err {
597- case nil :
617+ switch {
618+ case err == nil :
598619 return o , o .Update (ctx , in , src , options ... )
599- case fs .ErrorObjectNotFound :
620+ case errors . Is ( err , fs .ErrorObjectNotFound ) :
600621 return f .put (ctx , in , src , false , options ... )
601622 default :
602623 return nil , err
@@ -610,10 +631,10 @@ func (f *Fs) Put(ctx context.Context, in io.Reader, src fs.ObjectInfo, options .
610631// nil and the error
611632func (f * Fs ) PutStream (ctx context.Context , in io.Reader , src fs.ObjectInfo , options ... fs.OpenOption ) (fs.Object , error ) {
612633 o , err := f .NewObject (ctx , src .Remote ())
613- switch err {
614- case nil :
634+ switch {
635+ case err == nil :
615636 return o , o .Update (ctx , in , src , options ... )
616- case fs .ErrorObjectNotFound :
637+ case errors . Is ( err , fs .ErrorObjectNotFound ) :
617638 return f .put (ctx , in , src , true , options ... )
618639 default :
619640 return nil , err
@@ -782,7 +803,7 @@ func (f *Fs) NewObject(ctx context.Context, remote string) (fs.Object, error) {
782803 multithread (len (f .upstreams ), func (i int ) {
783804 u := f .upstreams [i ]
784805 o , err := u .NewObject (ctx , remote )
785- if err != nil && err != fs .ErrorObjectNotFound {
806+ if err != nil && ! errors . Is ( err , fs .ErrorObjectNotFound ) {
786807 errs [i ] = fmt .Errorf ("%s: %w" , u .Name (), err )
787808 return
788809 }
@@ -832,7 +853,7 @@ func (f *Fs) searchEntries(entries ...upstream.Entry) (upstream.Entry, error) {
832853}
833854
834855func (f * Fs ) mergeDirEntries (entriesList [][]upstream.Entry ) (fs.DirEntries , error ) {
835- entryMap := make (map [string ]( []upstream.Entry ) )
856+ entryMap := make (map [string ][]upstream.Entry )
836857 for _ , en := range entriesList {
837858 if en == nil {
838859 continue
@@ -846,8 +867,8 @@ func (f *Fs) mergeDirEntries(entriesList [][]upstream.Entry) (fs.DirEntries, err
846867 }
847868 }
848869 var entries fs.DirEntries
849- for path := range entryMap {
850- e , err := f .wrapEntries (entryMap [path ]... )
870+ for entryPath := range entryMap {
871+ e , err := f .wrapEntries (entryMap [entryPath ]... )
851872 if err != nil {
852873 return nil , err
853874 }
@@ -929,11 +950,11 @@ func NewFs(ctx context.Context, name, root string, m configmap.Mapper) (fs.Fs, e
929950 var usedUpstreams []* upstream.Fs
930951 var fserr error
931952 for i , err := range errs {
932- if err != nil && err != fs .ErrorIsFile {
953+ if err != nil && ! errors . Is ( err , fs .ErrorIsFile ) {
933954 return nil , err
934955 }
935956 // Only the upstreams returns ErrorIsFile would be used if any
936- if err == fs .ErrorIsFile {
957+ if errors . Is ( err , fs .ErrorIsFile ) {
937958 usedUpstreams = append (usedUpstreams , upstreams [i ])
938959 fserr = fs .ErrorIsFile
939960 }
@@ -949,7 +970,7 @@ func NewFs(ctx context.Context, name, root string, m configmap.Mapper) (fs.Fs, e
949970 upstreams : usedUpstreams ,
950971 }
951972 // Correct root if definitely pointing to a file
952- if fserr == fs .ErrorIsFile {
973+ if errors . Is ( fserr , fs .ErrorIsFile ) {
953974 f .root = path .Dir (f .root )
954975 if f .root == "." || f .root == "/" {
955976 f .root = ""
0 commit comments