From 6b4160f2a57487f277c42bf06fd280195dfdb278 Mon Sep 17 00:00:00 2001 From: Jae Kwon Date: Mon, 21 Nov 2016 20:01:11 -0800 Subject: [PATCH] Add Tempdir --- os.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/os.go b/os.go index 9f38027fa..e8943c0c5 100644 --- a/os.go +++ b/os.go @@ -113,6 +113,19 @@ func Tempfile(prefix string) (*os.File, string) { return file, file.Name() } +func Tempdir(prefix string) (*os.File, string) { + tempDir := os.TempDir() + "/" + prefix + RandStr(12) + err := EnsureDir(tempDir, 0700) + if err != nil { + panic(Fmt("Error creating temp dir: %v", err)) + } + dir, err := os.Open(tempDir) + if err != nil { + panic(Fmt("Error opening temp dir: %v", err)) + } + return dir, tempDir +} + //-------------------------------------------------------------------------------- func Prompt(prompt string, defaultValue string) (string, error) {