mirror of
https://github.com/gocsaf/csaf.git
synced 2025-12-22 11:55:40 +01:00
Fix transaction part two
This commit is contained in:
parent
9a7fbea7b6
commit
00a0fb68d2
1 changed files with 18 additions and 9 deletions
|
|
@ -9,6 +9,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
|
|
@ -71,16 +72,24 @@ func (lt *lazyTransaction) commit() error {
|
|||
}
|
||||
defer func() { lt.dst = "" }()
|
||||
|
||||
// Switch directories.
|
||||
symlink := filepath.Join(lt.dstDir, filepath.Base(lt.src))
|
||||
if err := os.Symlink(lt.dstDir, symlink); err != nil {
|
||||
os.RemoveAll(lt.dstDir)
|
||||
return err
|
||||
}
|
||||
if err := os.Rename(symlink, lt.src); err != nil {
|
||||
os.RemoveAll(lt.dstDir)
|
||||
// The expanded path of the original link.
|
||||
orig, err := filepath.EvalSymlinks(lt.src)
|
||||
if err != nil {
|
||||
os.RemoveAll(lt.dst)
|
||||
return err
|
||||
}
|
||||
|
||||
return os.RemoveAll(lt.src)
|
||||
// Switch directories.
|
||||
symlink := filepath.Join(lt.dst, filepath.Base(lt.src))
|
||||
if err := os.Symlink(lt.dst, symlink); err != nil {
|
||||
os.RemoveAll(lt.dst)
|
||||
return err
|
||||
}
|
||||
log.Printf("Move %q -> %q\n", symlink, lt.src)
|
||||
if err := os.Rename(symlink, lt.src); err != nil {
|
||||
os.RemoveAll(lt.dst)
|
||||
return err
|
||||
}
|
||||
|
||||
return os.RemoveAll(orig)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue