2020-11-09 20:27:03 +00:00
package testdata
import (
"crypto/rand"
"fmt"
"io/ioutil"
"math/big"
"os"
"path/filepath"
)
func tempDir ( ) string {
d := os . Getenv ( "TEST_TMPDIR" )
if d == "" {
return os . TempDir ( )
}
return d
}
2021-04-23 12:06:05 +00:00
// UseOsMkdirAllAndWriteFile --
2020-11-09 20:27:03 +00:00
func UseOsMkdirAllAndWriteFile ( ) {
randPath , _ := rand . Int ( rand . Reader , big . NewInt ( 1000000 ) )
p := filepath . Join ( tempDir ( ) , fmt . Sprintf ( "/%d" , randPath ) )
2021-09-17 21:55:24 +00:00
_ = os . MkdirAll ( p , os . ModePerm ) // want "os and ioutil dir and file writing functions are not permissions-safe, use shared/file"
2020-11-09 20:27:03 +00:00
someFile := filepath . Join ( p , "some.txt" )
2021-09-17 21:55:24 +00:00
_ = ioutil . WriteFile ( someFile , [ ] byte ( "hello" ) , os . ModePerm ) // want "os and ioutil dir and file writing functions are not permissions-safe, use shared/file"
2020-11-09 20:27:03 +00:00
}