Source File
tempfile.go
Belonging Package
os
package os
import
func (, string) (*File, error) {
if == "" {
= TempDir()
}
, , := prefixAndSuffix()
if != nil {
return nil, &PathError{Op: "createtemp", Path: , Err: }
}
= joinPath(, )
:= 0
for {
:= + nextRandom() +
, := OpenFile(, O_RDWR|O_CREATE|O_EXCL, 0600)
if IsExist() {
if ++; < 10000 {
continue
}
return nil, &PathError{Op: "createtemp", Path: + string(PathSeparator) + + "*" + , Err: ErrExist}
}
return ,
}
}
var errPatternHasSeparator = errors.New("pattern contains path separator")
func ( string) (, string, error) {
for := 0; < len(); ++ {
if IsPathSeparator([]) {
return "", "", errPatternHasSeparator
}
}
if := lastIndex(, '*'); != -1 {
, = [:], [+1:]
} else {
=
}
return , , nil
}
func (, string) (string, error) {
if == "" {
= TempDir()
}
, , := prefixAndSuffix()
if != nil {
return "", &PathError{Op: "mkdirtemp", Path: , Err: }
}
= joinPath(, )
:= 0
for {
:= + nextRandom() +
:= Mkdir(, 0700)
if == nil {
return , nil
}
if IsExist() {
if ++; < 10000 {
continue
}
return "", &PathError{Op: "mkdirtemp", Path: + string(PathSeparator) + + "*" + , Err: ErrExist}
}
if IsNotExist() {
if , := Stat(); IsNotExist() {
return "",
}
}
return "",
}
}
func (, string) string {
if len() > 0 && IsPathSeparator([len()-1]) {
return +
}
return + string(PathSeparator) +
}
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |