mirror of https://github.com/databricks/cli.git
Fix temporary directory cleanup for init repository downloading (#760)
## Changes This PR fixes a bug where the temp directory created to download the template would not be cleaned up. ## Tests Tested manually. The exact process is described in a comment below.
This commit is contained in:
parent
a4e94e1b36
commit
ad84abf415
|
@ -74,22 +74,21 @@ func newInitCommand() *cobra.Command {
|
|||
return template.Materialize(ctx, configFile, templatePath, outputDir)
|
||||
}
|
||||
|
||||
// Download the template in a temporary directory
|
||||
tmpDir := os.TempDir()
|
||||
templateURL := templatePath
|
||||
repoDir := filepath.Join(tmpDir, repoName(templateURL))
|
||||
err := os.MkdirAll(repoDir, 0755)
|
||||
// Create a temporary directory with the name of the repository. The '*'
|
||||
// character is replaced by a random string in the generated temporary directory.
|
||||
repoDir, err := os.MkdirTemp("", repoName(templatePath)+"-*")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// TODO: Add automated test that the downloaded git repo is cleaned up.
|
||||
err = git.Clone(ctx, templateURL, "", repoDir)
|
||||
// Clone the repository in the temporary directory
|
||||
err = git.Clone(ctx, templatePath, "", repoDir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer os.RemoveAll(templateDir)
|
||||
// Clean up downloaded repository once the template is materialized.
|
||||
defer os.RemoveAll(repoDir)
|
||||
return template.Materialize(ctx, configFile, filepath.Join(repoDir, templateDir), outputDir)
|
||||
}
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue