func restoreDepFiles(dfiles []api.DependencyFile) error {
	fmt.Printf("%d file(s) to be restored.\n", len(dfiles))
	for _, df := range dfiles {
		fmt.Printf("Restoring file %s: ", df.Path)
		err := ioutil.WriteFile(df.Path, df.Content, 0644)
		if err != nil {
			return err
		}
		fmt.Printf("done\n")
	}
	return nil
}
Restore original files.
Needed after each run
package autoupdate
import (
	"errors"
	"fmt"
	"io/ioutil"
	"os"
	"os/exec"
	"strings"
	"time"
	"github.com/gemnasium/toolbelt/utils"
	"github.com/gemnasium/toolbelt/api"
	"github.com/gemnasium/toolbelt/config"
	"github.com/gemnasium/toolbelt/project"
)
const (
	UPDATE_SET_INVALID = "invalid"
	UPDATE_SET_SUCCESS = "test_passed"
	UPDATE_SET_FAIL    = "test_failed"
)
var ErrProjectRevisionEmpty error = fmt.Errorf("The current revision (%s) is unknown on Gemnasium, please push your dependency files before running autoupdate.\nSee `gemnasium df help push`.\n", utils.GetCurrentRevision())
func Apply(projectSlug string, testSuite []string) error {
	err := checkProject(projectSlug)
	if err != nil {
		return err
	}
	dfiles, err := fetchDependencyFiles(projectSlug)
	if err != nil {
		return err
	}
	err = updateDepFiles(dfiles)
	if err != nil {
		fmt.Printf("Error while restoring files: %s\n", err)
		return err
	}
	return nil
}
func fetchDependencyFiles(projectSlug string) (dfiles []api.DependencyFile, err error) {
	revision, err := getRevision()
	if err != nil {
		return nil, err
	}
	dfiles, err = api.APIImpl.AutoUpdateStepsBest(projectSlug, revision)
	return dfiles, err
}
func updateDepFiles(dfiles []api.DependencyFile) error {
	fmt.Printf("%d file(s) to be updated.\n", len(dfiles))
	for _, df := range dfiles {
		fmt.Printf("Updating file %s: ", df.Path)
		err := ioutil.WriteFile(df.Path, df.Content, 0644)
		if err != nil {
			return err
		}
		fmt.Printf("done\n")
	}
	return nil
}
func Run(projectSlug string, testSuite []string) error {
	err := checkProject(projectSlug)
	if err != nil {
		return err
	}
	if envTS := os.Getenv(config.ENV_GEMNASIUM_TESTSUITE); envTS != "" {
		testSuite = strings.Fields(envTS)
	}
	if len(testSuite) == 0 {
		return errors.New("Arg [testSuite] can't be empty")
	}
	out, err := executeTestSuite(testSuite)
	if err != nil {
		fmt.Println("Aborting, initial test suite run is failing:")
		fmt.Printf("%s\n", out)
		return err
	}
	for {
		updateSet, err := fetchUpdateSet(projectSlug)
		if err != nil {
			return err
		}
		if updateSet.ID == 0 {
			fmt.Println("Job done!")
			break
		}
		fmt.Printf("\n========= [UpdateSet #%d] =========\n", updateSet.ID)
		orgDepFiles, uptDepFiles, err := applyUpdateSet(updateSet)
		resultSet := &api.UpdateSetResult{UpdateSetID: updateSet.ID, ProjectSlug: projectSlug, DependencyFiles: uptDepFiles}
		if err == cantInstallRequirements || err == cantUpdateVersions {
			resultSet.State = UPDATE_SET_INVALID
			err := pushUpdateSetResult(resultSet)
			if err != nil {
				return err
			}
			err = restoreDepFiles(orgDepFiles)
			if err != nil {
				fmt.Printf("Error while restoring files: %s\n", err)
			}
			continue
		}
		if err != nil {
			return err
		}
		out, err := executeTestSuite(testSuite)
		if err == nil {
			resultSet.State = UPDATE_SET_SUCCESS
			err := pushUpdateSetResult(resultSet)
			if err != nil {
				return err
			}
			err = restoreDepFiles(orgDepFiles)
			if err != nil {
				return err
			}
			continue
		}
		fmt.Printf("%s\n", out)
		resultSet.State = UPDATE_SET_FAIL
		err = pushUpdateSetResult(resultSet)
		if err != nil {
			return err
		}
		err = restoreDepFiles(orgDepFiles)
		if err != nil {
			fmt.Printf("Error while restoring files: %s\n", err)
		}
	}
	return nil
}
func fetchUpdateSet(projectSlug string) (updateSet *api.UpdateSet, err error) {
	revision, err := getRevision()
	if err != nil {
		return nil, err
	}
	updateSet, err = api.APIImpl.AutoUpdateStepsNext(projectSlug, revision)
	return updateSet, err
}
func applyUpdateSet(updateSet *api.UpdateSet) (orgDepFiles, uptDepFiles []api.DependencyFile, err error) {
	for packageType, reqUpdates := range updateSet.RequirementUpdates {
		installer, err := NewRequirementsInstaller(packageType)
		if err != nil {
			return orgDepFiles, uptDepFiles, err
		}
		err = installer(reqUpdates, &orgDepFiles, &uptDepFiles)
		if err != nil {
			return orgDepFiles, uptDepFiles, err
		}
	}
	for packageType, versionUpdates := range updateSet.VersionUpdates {
		updater, err := NewUpdater(packageType)
		if err != nil {
			return orgDepFiles, uptDepFiles, err
		}
		err = updater(versionUpdates, &orgDepFiles, &uptDepFiles)
		if err != nil {
			return orgDepFiles, uptDepFiles, err
		}
	}
	fmt.Println("Done")
	return orgDepFiles, uptDepFiles, nil
}
func pushUpdateSetResult(rs *api.UpdateSetResult) error {
	fmt.Printf("Pushing result (status='%s'): ", rs.State)
	if rs.UpdateSetID == 0 || rs.State == "" {
		return errors.New("Missing updateSet ID and/or State args")
	}
	revision, err := getRevision()
	if err != nil {
		return err
	}
	err = api.APIImpl.AutoUpdateStepsPush(revision, rs)
	if err != nil {
		return err
	}
	fmt.Printf("done\n")
	return nil
}