mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-09 23:00:58 +00:00
Cleanup temporary files (fixes #1239)
This commit is contained in:
parent
5ac7564bfe
commit
a53facf709
@ -264,6 +264,7 @@ func (w *Wrapper) Save() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
defer os.Remove(fd.Name())
|
||||||
|
|
||||||
err = w.cfg.WriteXML(fd)
|
err = w.cfg.WriteXML(fd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -95,7 +95,7 @@ func upgradeToURL(binary string, url string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
old := binary + ".old"
|
old := binary + ".old"
|
||||||
_ = os.Remove(old)
|
os.Remove(old)
|
||||||
err = os.Rename(binary, old)
|
err = os.Rename(binary, old)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -193,20 +193,16 @@ fileLoop:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if tempName != "" && actualMD5 != "" {
|
if tempName != "" {
|
||||||
// We found and saved something to disk.
|
// We found and saved something to disk.
|
||||||
if expectedMD5 == "" {
|
if expectedMD5 == "" || actualMD5 == expectedMD5 {
|
||||||
if debug {
|
return tempName, nil
|
||||||
l.Debugln("there is no md5 to compare with")
|
|
||||||
}
|
}
|
||||||
} else if actualMD5 != expectedMD5 {
|
os.Remove(tempName)
|
||||||
// There was an md5 file included in the archive, and it doesn't
|
// There was an md5 file included in the archive, and it doesn't
|
||||||
// match what we just wrote to disk.
|
// match what we just wrote to disk.
|
||||||
return "", fmt.Errorf("incorrect MD5 checksum")
|
return "", fmt.Errorf("incorrect MD5 checksum")
|
||||||
}
|
}
|
||||||
return tempName, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return "", fmt.Errorf("no upgrade found")
|
return "", fmt.Errorf("no upgrade found")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -274,20 +270,16 @@ fileLoop:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if tempName != "" && actualMD5 != "" {
|
if tempName != "" {
|
||||||
// We found and saved something to disk.
|
// We found and saved something to disk.
|
||||||
if expectedMD5 == "" {
|
if expectedMD5 == "" || actualMD5 == expectedMD5 {
|
||||||
if debug {
|
return tempName, nil
|
||||||
l.Debugln("there is no md5 to compare with")
|
|
||||||
}
|
}
|
||||||
} else if actualMD5 != expectedMD5 {
|
os.Remove(tempName)
|
||||||
// There was an md5 file included in the archive, and it doesn't
|
// There was an md5 file included in the archive, and it doesn't
|
||||||
// match what we just wrote to disk.
|
// match what we just wrote to disk.
|
||||||
return "", fmt.Errorf("incorrect MD5 checksum")
|
return "", fmt.Errorf("incorrect MD5 checksum")
|
||||||
}
|
}
|
||||||
return tempName, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return "", fmt.Errorf("No upgrade found")
|
return "", fmt.Errorf("No upgrade found")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user