With -l/--links the local backend recreates a source ".rclonelink" as a real symlink at the destination. Remove and Rmdir deleted by path, which follows a symlink in any parent component, so when the destination contained a planted symlink "pwn" pointing outside the root, an object or directory named through it such as "pwn/secret" resolved to the outside file or directory and was deleted there. rclone's own sync never names destination paths through a symlink as the listing shows it as a ".rclonelink" file, but the clean up of a failed copy looks up and removes a ".partial" name derived from the source, and callers of the rc API or the Go API may pass such a name directly. Delete through os.Root when translating symlinks so a planted symlink can no longer redirect the removal out of the destination. This also covers the removal of a partially written file after a failed write. In-tree removals and the Windows sharing violation retry are unchanged.
35 lines
691 B
Go
35 lines
691 B
Go
//go:build windows
|
|
|
|
package local
|
|
|
|
import (
|
|
"os"
|
|
"time"
|
|
|
|
"github.com/rclone/rclone/fs"
|
|
"golang.org/x/sys/windows"
|
|
)
|
|
|
|
// remove removes name with removeFn, retrying on a sharing violation
|
|
func remove(name string, removeFn func(string) error) (err error) {
|
|
const maxTries = 10
|
|
var sleepTime = 1 * time.Millisecond
|
|
for i := range maxTries {
|
|
err = removeFn(name)
|
|
if err == nil {
|
|
break
|
|
}
|
|
pathErr, ok := err.(*os.PathError)
|
|
if !ok {
|
|
break
|
|
}
|
|
if pathErr.Err != windows.ERROR_SHARING_VIOLATION {
|
|
break
|
|
}
|
|
fs.Logf(name, "Remove detected sharing violation - retry %d/%d sleeping %v", i+1, maxTries, sleepTime)
|
|
time.Sleep(sleepTime)
|
|
sleepTime <<= 1
|
|
}
|
|
return err
|
|
}
|