mirror of
https://github.com/minio/minio.git
synced 2025-02-27 13:29:15 -05:00
Moving os.MkdirAll() inside atomic for auto parent directory creates
This commit is contained in:
parent
5fc377ae57
commit
11b893804c
@ -153,13 +153,7 @@ func (disk Disk) CreateFile(filename string) (*atomic.File, error) {
|
|||||||
return nil, iodine.New(InvalidArgument{}, nil)
|
return nil, iodine.New(InvalidArgument{}, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
filePath := filepath.Join(disk.path, filename)
|
f, err := atomic.FileCreate(filepath.Join(disk.path, filename))
|
||||||
// Create directories if they don't exist
|
|
||||||
if err := os.MkdirAll(filepath.Dir(filePath), 0700); err != nil {
|
|
||||||
return nil, iodine.New(err, nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
f, err := atomic.FileCreate(filePath)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, iodine.New(err, nil)
|
return nil, iodine.New(err, nil)
|
||||||
}
|
}
|
||||||
|
@ -58,8 +58,13 @@ func (f *File) CloseAndPurge() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// FileCreate creates a new file at filePath for atomic writes
|
// FileCreate creates a new file at filePath for atomic writes, it also creates parent directories if they don't exist
|
||||||
func FileCreate(filePath string) (*File, error) {
|
func FileCreate(filePath string) (*File, error) {
|
||||||
|
// if parent directories do not exist, ioutil.TempFile doesn't create them
|
||||||
|
// handle such a case with os.MkdirAll()
|
||||||
|
if err := os.MkdirAll(filepath.Dir(filePath), 0700); err != nil {
|
||||||
|
return nil, iodine.New(err, nil)
|
||||||
|
}
|
||||||
f, err := ioutil.TempFile(filepath.Dir(filePath), filepath.Base(filePath))
|
f, err := ioutil.TempFile(filepath.Dir(filePath), filepath.Base(filePath))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, iodine.New(err, nil)
|
return nil, iodine.New(err, nil)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user