Added implementation to cover the new `Mkdir` & `MkdirAll` cases

This commit is contained in:
VOvchinnikov 2021-08-05 18:38:36 +02:00
parent 13ee679c8e
commit c1220175da
1 changed files with 20 additions and 0 deletions

View File

@ -161,6 +161,15 @@ func (fs *GcsFs) Mkdir(name string, _ os.FileMode) error {
if err := validateName(name); err != nil { if err := validateName(name); err != nil {
return err return err
} }
// folder creation logic has to additionally check for folder name presence
bucketName, path := fs.splitName(name)
if bucketName == "" {
return ErrNoBucketInName
}
if path == "" {
// the API would throw "googleapi: Error 400: No object name, required", but this one is more consistent
return ErrEmptyObjectName
}
obj, err := fs.getObj(name) obj, err := fs.getObj(name)
if err != nil { if err != nil {
@ -175,6 +184,15 @@ func (fs *GcsFs) MkdirAll(path string, perm os.FileMode) error {
if err := validateName(path); err != nil { if err := validateName(path); err != nil {
return err return err
} }
// folder creation logic has to additionally check for folder name presence
bucketName, splitPath := fs.splitName(path)
if bucketName == "" {
return ErrNoBucketInName
}
if splitPath == "" {
// the API would throw "googleapi: Error 400: No object name, required", but this one is more consistent
return ErrEmptyObjectName
}
root := "" root := ""
folders := strings.Split(path, fs.separator) folders := strings.Split(path, fs.separator)
@ -186,7 +204,9 @@ func (fs *GcsFs) MkdirAll(path string, perm os.FileMode) error {
if root != "" { if root != "" {
root = root + fs.separator + f root = root + fs.separator + f
} else { } else {
// we have to have at least bucket name + folder name to create successfully
root = f root = f
continue
} }
if err := fs.Mkdir(root, perm); err != nil { if err := fs.Mkdir(root, perm); err != nil {