zoho: remove simple file names complication which is no longer needed

This commit is contained in:
Nick Craig-Wood 2024-06-11 20:22:59 +01:00
parent 00f0e9df9d
commit edf6537c61

View File

@ -639,15 +639,6 @@ func (f *Fs) createObject(ctx context.Context, remote string, size int64, modTim
return
}
func isSimpleName(s string) bool {
for _, r := range s {
if (r < 'a' || r > 'z') && (r < 'A' || r > 'Z') && (r != '.') {
return false
}
}
return true
}
func (f *Fs) upload(ctx context.Context, name string, parent string, size int64, in io.Reader, options ...fs.OpenOption) (*api.Item, error) {
params := url.Values{}
params.Set("filename", name)
@ -718,7 +709,7 @@ func (f *Fs) Put(ctx context.Context, in io.Reader, src fs.ObjectInfo, options .
return nil, err
}
if isSimpleName(leaf) {
// Upload the file
info, err := f.upload(ctx, f.opt.Enc.FromStandardName(leaf), directoryID, size, in, options...)
if err != nil {
return nil, err
@ -726,19 +717,6 @@ func (f *Fs) Put(ctx context.Context, in io.Reader, src fs.ObjectInfo, options .
return f.newObjectWithInfo(ctx, remote, info)
}
tempName := "rcloneTemp" + random.String(8)
info, err := f.upload(ctx, tempName, directoryID, size, in, options...)
if err != nil {
return nil, err
}
o, err := f.newObjectWithInfo(ctx, remote, info)
if err != nil {
return nil, err
}
return o, o.(*Object).rename(ctx, leaf)
}
// Mkdir creates the container if it doesn't exist
func (f *Fs) Mkdir(ctx context.Context, dir string) error {
_, err := f.dirCache.FindDir(ctx, dir, true)
@ -1200,8 +1178,7 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op
return err
}
if isSimpleName(leaf) {
// Simple name we can just overwrite the old file
// Overwrite the old file
info, err := o.fs.upload(ctx, o.fs.opt.Enc.FromStandardName(leaf), directoryID, size, in, options...)
if err != nil {
return err
@ -1209,25 +1186,6 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op
return o.setMetaData(info)
}
// We have to fall back to upload + rename
tempName := "rcloneTemp" + random.String(8)
info, err := o.fs.upload(ctx, tempName, directoryID, size, in, options...)
if err != nil {
return err
}
// upload was successful, need to delete old object before rename
if err = o.Remove(ctx); err != nil {
return fmt.Errorf("failed to remove old object: %w", err)
}
if err = o.setMetaData(info); err != nil {
return err
}
// rename also updates metadata
return o.rename(ctx, leaf)
}
// Remove an object
func (o *Object) Remove(ctx context.Context) error {
return o.fs.deleteObject(ctx, o.id)