-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
⭐️ go package to create
tmp.File()
(#4453)
This go package should be used across `cnquery` to generate temporary files and directories. `tmp.File()` creates a new temporary file. By default `File()` uses the default directory to create a new temporary file, to change the temporary directory use the environment variable `MONDOO_TMP_DIR` Signed-off-by: Salim Afiune Maya <afiune@mondoo.com>
- Loading branch information
Showing
6 changed files
with
44 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright (c) Mondoo, Inc. | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
|
||
package tmp | ||
|
||
// This go package should be used across cnquery to generate temporary files | ||
// and directories. | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/rs/zerolog/log" | ||
) | ||
|
||
// File creates a new temporary file. | ||
// | ||
// By default `File()` uses the default directory to create a new temporary file, | ||
// to change the temporary directory use the environment variable `MONDOO_TMP_DIR` | ||
func File() (*os.File, error) { | ||
tmpDir := "" | ||
if os.Getenv("MONDOO_TMP_DIR") != "" { | ||
tmpDir = os.Getenv("MONDOO_TMP_DIR") | ||
log.Debug(). | ||
Str("custom_tmp_dir", tmpDir). | ||
Msg("creating temp file in custom temp directory") | ||
} | ||
return os.CreateTemp(tmpDir, "mondoo.tmp") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters