2021-09-09 12:25:25 +00:00
|
|
|
//go:build windows
|
2018-04-04 13:24:04 +00:00
|
|
|
|
|
|
|
package local
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"time"
|
|
|
|
|
2019-07-28 17:47:38 +00:00
|
|
|
"github.com/rclone/rclone/fs"
|
2024-04-17 14:40:07 +00:00
|
|
|
"golang.org/x/sys/windows"
|
2018-04-04 13:24:04 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Removes name, retrying on a sharing violation
|
|
|
|
func remove(name string) (err error) {
|
|
|
|
const maxTries = 10
|
|
|
|
var sleepTime = 1 * time.Millisecond
|
|
|
|
for i := 0; i < maxTries; i++ {
|
|
|
|
err = os.Remove(name)
|
|
|
|
if err == nil {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
pathErr, ok := err.(*os.PathError)
|
|
|
|
if !ok {
|
|
|
|
break
|
|
|
|
}
|
2024-04-17 14:40:07 +00:00
|
|
|
if pathErr.Err != windows.ERROR_SHARING_VIOLATION {
|
2018-04-04 13:24:04 +00:00
|
|
|
break
|
|
|
|
}
|
|
|
|
fs.Logf(name, "Remove detected sharing violation - retry %d/%d sleeping %v", i+1, maxTries, sleepTime)
|
|
|
|
time.Sleep(sleepTime)
|
|
|
|
sleepTime <<= 1
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|