mirror of
https://github.com/mjl-/mox.git
synced 2025-07-12 13:04:38 +03:00
move "link or copy" functionality to moxio
and add a bit more logging for unexpected failures when closing files. and make tests pass with a TMPDIR on a different filesystem than the testdata directory.
This commit is contained in:
12
backup.go
12
backup.go
@ -240,15 +240,19 @@ func backupctl(ctx context.Context, ctl *ctl) {
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("open source path %s: %v", srcpath, err)
|
||||
}
|
||||
defer sf.Close()
|
||||
defer func() {
|
||||
err := sf.Close()
|
||||
ctl.log.Check(err, "closing copied source file")
|
||||
}()
|
||||
|
||||
df, err := os.OpenFile(dstpath, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0660)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("open destination path %s: %v", dstpath, err)
|
||||
return false, fmt.Errorf("create destination path %s: %v", dstpath, err)
|
||||
}
|
||||
defer func() {
|
||||
if df != nil {
|
||||
df.Close()
|
||||
err := df.Close()
|
||||
ctl.log.Check(err, "closing partial destination file")
|
||||
}
|
||||
}()
|
||||
if _, err := io.Copy(df, sf); err != nil {
|
||||
@ -257,7 +261,7 @@ func backupctl(ctx context.Context, ctl *ctl) {
|
||||
err = df.Close()
|
||||
df = nil
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("close: %v", err)
|
||||
return false, fmt.Errorf("closing destination file: %v", err)
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user