mirror of
https://github.com/gocsaf/csaf.git
synced 2025-12-22 18:15:42 +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
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
|
|
@ -71,16 +72,24 @@ func (lt *lazyTransaction) commit() error {
|
||||||
}
|
}
|
||||||
defer func() { lt.dst = "" }()
|
defer func() { lt.dst = "" }()
|
||||||
|
|
||||||
// Switch directories.
|
// The expanded path of the original link.
|
||||||
symlink := filepath.Join(lt.dstDir, filepath.Base(lt.src))
|
orig, err := filepath.EvalSymlinks(lt.src)
|
||||||
if err := os.Symlink(lt.dstDir, symlink); err != nil {
|
if err != nil {
|
||||||
os.RemoveAll(lt.dstDir)
|
os.RemoveAll(lt.dst)
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := os.Rename(symlink, lt.src); err != nil {
|
|
||||||
os.RemoveAll(lt.dstDir)
|
|
||||||
return err
|
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