Made upgrade-system smarter (fixes #2446)

This commit is contained in:
Stefan Kuntz 2015-11-09 23:32:26 +01:00
parent e3c55ef307
commit 2abb2de753

View File

@ -190,11 +190,7 @@ func readTarGz(dir string, r io.Reader) (string, error) {
return "", err return "", err
} }
shortName := path.Base(hdr.Name) err = archiveFileVisitor(dir, &tempName, &sig, hdr.Name, tr)
l.Debugf("considering file %q", shortName)
err = archiveFileVisitor(dir, &tempName, &sig, shortName, tr)
if err != nil { if err != nil {
return "", err return "", err
} }
@ -227,16 +223,12 @@ func readZip(dir string, r io.Reader) (string, error) {
// Iterate through the files in the archive. // Iterate through the files in the archive.
for _, file := range archive.File { for _, file := range archive.File {
shortName := path.Base(file.Name)
l.Debugf("considering file %q", shortName)
inFile, err := file.Open() inFile, err := file.Open()
if err != nil { if err != nil {
return "", err return "", err
} }
err = archiveFileVisitor(dir, &tempName, &sig, shortName, inFile) err = archiveFileVisitor(dir, &tempName, &sig, file.Name, inFile)
inFile.Close() inFile.Close()
if err != nil { if err != nil {
return "", err return "", err
@ -256,18 +248,26 @@ func readZip(dir string, r io.Reader) (string, error) {
// archiveFileVisitor is called for each file in an archive. It may set // archiveFileVisitor is called for each file in an archive. It may set
// tempFile and signature. // tempFile and signature.
func archiveFileVisitor(dir string, tempFile *string, signature *[]byte, filename string, filedata io.Reader) error { func archiveFileVisitor(dir string, tempFile *string, signature *[]byte, archivePath string, filedata io.Reader) error {
var err error var err error
filename := path.Base(archivePath)
archiveDir := path.Dir(archivePath)
archiveDirs := strings.Split(archiveDir, "/")
if len(archiveDirs) > 1 {
//don't consider files in subfolders
return nil
}
l.Debugf("considering file %s", archivePath)
switch filename { switch filename {
case "syncthing", "syncthing.exe": case "syncthing", "syncthing.exe":
l.Debugln("reading binary") l.Debugf("found upgrade binary %s", archivePath)
*tempFile, err = writeBinary(dir, filedata) *tempFile, err = writeBinary(dir, filedata)
if err != nil { if err != nil {
return err return err
} }
case "syncthing.sig", "syncthing.exe.sig": case "syncthing.sig", "syncthing.exe.sig":
l.Debugln("reading signature") l.Debugf("found signature %s", archivePath)
*signature, err = ioutil.ReadAll(filedata) *signature, err = ioutil.ReadAll(filedata)
if err != nil { if err != nil {
return err return err