Initial release of bdrclone

This commit is contained in:
2026-08-13 23:02:25 +08:00
commit d6d1956050
23 changed files with 3042 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
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
}