Repository: rclone/rclone (language: go)

Issue:
uloz backend, copyto doesn't work (Error 60001 (422): Validation failed)
#### What is the problem you are having with rclone?
sync and copy works, but trying to use the copyto command with the new uloz backend errors out before the upload starts

#### What is your rclone version (output from `rclone version`)
rclone v1.67.0-beta.7908.29ed17d19
- os/version: darwin 14.4.1 (64 bit)
- os/kernel: 23.4.0 (x86_64)
- os/type: darwin
- os/arch: amd64
- go/version: go1.22.2
- go/linking: dynamic
- go/tags: cmount


#### Which OS you are using and how many bits (e.g. Windows 7, 64 bit)
macOS 14.4.1 (23E224)


#### Which cloud storage system are you using? (e.g. Google Drive)
ulozto


#### The command you were trying to run (e.g. `rclone copy /tmp remote:tmp`)
rclone copyto ./linuxmint-21.3-cinnamon-64bit.iso uloz:/iso/linuxmint-21.3-64bit.iso --progress -vv


#### A log from the command with the `-vv` flag (e.g. output from `rclone -vv copy /tmp remote:tmp`)
```
2024/04/24 11:27:02 DEBUG : rclone: Version "v1.67.0-beta.7908.29ed17d19" starting with parameters ["rclone" "copyto" "./linuxmint-21.3-cinnamon-64bit.iso" "uloz:/iso/linuxmint-21.3-64bit.iso" "-vv"]
2024/04/24 11:27:02 DEBUG : Creating backend with remote "./linuxmint-21.3-cinnamon-64bit.iso"
2024/04/24 11:27:02 DEBUG : Using config file from "/Users/tin/.config/rclone/rclone.conf"
2024/04/24 11:27:02 DEBUG : fs cache: adding new entry for parent of "./linuxmint-21.3-cinnamon-64bit.iso", "/Users/tin/Downloads"
2024/04/24 11:27:02 DEBUG : Creating backend with remote "uloz:/iso/"
2024/04/24 11:27:05 DEBUG : linuxmint-21.3-cinnamon-64bit.iso: Need to transfer - File not found at Destination
2024/04/24 11:27:06 ERROR : linuxmint-21.3-cinnamon-64bit.iso: Failed to copy: failed to make directory: Error 60001 (422): Validation failed.
2024/04/24 11:27:06 ERROR : Attempt 1/3 failed with 1 errors and: failed to make directory: Error 60001 (422): Validation failed.
2024/04/24 11:27:07 DEBUG : linuxmint-21.3-cinnamon-64bit.iso: Need to transfer - File not found at Destination
2024/04/24 11:27:08 ERROR : linuxmint-21.3-cinnamon-64bit.iso: Failed to copy: failed to make directory: Error 60001 (422): Validation failed.
2024/04/24 11:27:08 ERROR : Attempt 2/3 failed with 1 errors and: failed to make directory: Error 60001 (422): Validation failed.
2024/04/24 11:27:09 DEBUG : linuxmint-21.3-cinnamon-64bit.iso: Need to transfer - File not found at Destination
2024/04/24 11:27:10 ERROR : linuxmint-21.3-cinnamon-64bit.iso: Failed to copy: failed to make directory: Error 60001 (422): Validation failed.
2024/04/24 11:27:10 ERROR : Attempt 3/3 failed with 1 errors and: failed to make directory: Error 60001 (422): Validation failed.
2024/04/24 11:27:10 INFO  : 
Transferred:   	          0 B / 0 B, -, 0 B/s, ETA -
Errors:                 1 (retrying may help)
Elapsed time:         7.6s

2024/04/24 11:27:10 DEBUG : 7 go routines active
2024/04/24 11:27:10 Failed to copyto: failed to make directory: Error 60001 (422): Validation failed.
```




#### How to use GitHub

* Please use the 👍 [reaction](https://blog.github.com/2016-03-10-add-reactions-to-pull-requests-issues-and-comments/) to show that you are affected by the same issue.
* Please don't comment if you have no relevant information to add. It's just extra noise for everyone subscribed to this issue.
* Subscribe to receive notifications on status change and new comments.



Discussion / hints:
The folders of the destination path do get created in the remote, but no file is uploaded.
I got the same error if i mount uloz and try to copy something into this mount.

2024/04/29 22:21:08 ERROR : /: Dir.Mkdir failed to create directory: failed to make directory: Error 60001 (422): Validation failed.
2024/04/29 22:21:08 ERROR : IO error: failed to make directory: Error 60001 (422): Validation failed.
@iotmaestro , can you confirm that bug?
Thanks for the report and apologies for the late reply, a lot of IRL stuff happening right now. Let me take a look.
This is a leading / trailing slash handling issue. If in any capacity we attempt to ask dircache for a path with a trailing slash such as `iso/` (which copyto automatically does), dircache will attempt to retrieve an ID of a folder with an empty name under `iso` folder and not the ISO folder itself. In uloz.to's case it obviously fails to find it and tries to create it, which fails because empty folder names are disallowed.

By eyeballing other backends, this is something they tend to deal with on their own, such as with the [canonical Box example](https://github.com/rclone/rclone/blob/master/backend/box/box.go#L344), so I'll add handling it in the uloz.to backend as well. It may be worth considering this issue on the dircache level at some point to centralize the logic and simplify the backends. 

Fix patch:
diff --git a/backend/ulozto/ulozto.go b/backend/ulozto/ulozto.go
index 063f465db311a..1cdeefd749758 100644
--- a/backend/ulozto/ulozto.go
+++ b/backend/ulozto/ulozto.go
@@ -121,6 +121,9 @@ func NewFs(ctx context.Context, name, root string, m configmap.Mapper) (fs.Fs, e
 		return nil, err
 	}
 
+	// Strip leading and trailing slashes, see https://github.com/rclone/rclone/issues/7796 for details.
+	root = strings.Trim(root, "/")
+
 	client := fshttp.NewClient(ctx)
 
 	f := &Fs{


Test patch: