Initial release of bdrclone
This commit is contained in:
29
internal/mount/recovery.go
Normal file
29
internal/mount/recovery.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user