Files
bdrclone/internal/mount/recovery.go
2026-08-13 23:02:49 +08:00

30 lines
755 B
Go

package mount
import (
"fmt"
"os"
"path/filepath"
"strings"
"time"
)
func preserveFailedWrite(tempPath, remotePath string) (string, error) {
cacheDir, err := os.UserCacheDir()
if err != nil {
return tempPath, err
}
recoveryDir := filepath.Join(cacheDir, "bdrclone", "failed-writes")
if err := os.MkdirAll(recoveryDir, 0o700); err != nil {
return tempPath, err
}
name := strings.ReplaceAll(filepath.Base(remotePath), string(filepath.Separator), "_")
if name == "" || name == "." {
name = "remote-file"
}
destination := filepath.Join(recoveryDir, fmt.Sprintf("%s-%s", time.Now().Format("20060102-150405.000000000"), name))
if err := os.Rename(tempPath, destination); err != nil {
return tempPath, err
}
return destination, nil
}