Skip to content
This repository was archived by the owner on Jan 5, 2023. It is now read-only.

Commit 8de188a

Browse files
committed
Restore repo layout post-autobuild
1 parent be64f3e commit 8de188a

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

extractor/cli/go-autobuilder/go-autobuilder.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,18 @@ func getImportPathFromRepoURL(repourl string) string {
143143
return host + "/" + path
144144
}
145145

146+
func restoreRepoLayout(fromDir string, dirEntries []string, scratchDirName string, toDir string) {
147+
for _, dirEntry := range dirEntries {
148+
if dirEntry != scratchDirName {
149+
log.Printf("Restoring %s/%s to %s/%s.\n", fromDir, dirEntry, toDir, dirEntry)
150+
err := os.Rename(filepath.Join(fromDir, dirEntry), filepath.Join(toDir, dirEntry))
151+
if err != nil {
152+
log.Fatalf("Failed to move file/directory %s from directory %s to directory %s: %s\n", dirEntry, fromDir, toDir, err.Error())
153+
}
154+
}
155+
}
156+
}
157+
146158
// DependencyInstallerMode is an enum describing how dependencies should be installed
147159
type DependencyInstallerMode int
148160

@@ -345,6 +357,10 @@ func main() {
345357
if err != nil {
346358
log.Fatalf("Failed to rename %s to %s: %s\n", scratch, newdir, err.Error())
347359
}
360+
361+
// schedule restoring the contents of newdir to their original location after this function completes:
362+
defer restoreRepoLayout(newdir, files, filepath.Base(scratch), srcdir)
363+
348364
err = os.Chdir(newdir)
349365
if err != nil {
350366
log.Fatalf("Failed to chdir into %s: %s\n", newdir, err.Error())

0 commit comments

Comments
 (0)