mirror of
https://github.com/versity/versitygw.git
synced 2026-09-26 09:54:49 +00:00
The previous logic was not allowing put-object on windows when the parent directory did not already exist, and would not always return the correct error if an ancestor in the path already existed as a file. The problem is the different behavior of the os.Stat command in Windows compared to *nix in backend/posix/posix.go in function PutObjectWithPostFunc. The os.Stat returns ENOTDIR on *nix if the parent object is a file instead of a directory. On Windows, if the parent object does not exist at all, the return code of such os.Stat is ERROR_PATH_NOT_FOUND which is mapped to ENOTDIR. However this is inappropriate in this case. As a result, the return code of the os.Stat is incorrectly interpreted as if the parent object is a file instead of the parent object does not exist. Which then leads to a failed upload. This fix validates the existing parent structure on put to make sure the correct error is returned or the put is successful. Fixes #1702
47 lines
1.3 KiB
Go
47 lines
1.3 KiB
Go
// Copyright 2026 Versity Software
|
|
// This file is licensed under the Apache License, Version 2.0
|
|
// (the "License"); you may not use this file except in compliance
|
|
// with the License. You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing,
|
|
// software distributed under the License is distributed on an
|
|
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
// KIND, either express or implied. See the License for the
|
|
// specific language governing permissions and limitations
|
|
// under the License.
|
|
|
|
//go:build windows
|
|
|
|
package posix
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"github.com/versity/versitygw/s3err"
|
|
)
|
|
|
|
func handleParentDirError(name string) error {
|
|
dir := filepath.Dir(name)
|
|
|
|
// Walk up the directory hierarchy
|
|
for dir != "." && dir != "/" {
|
|
d, statErr := os.Stat(dir)
|
|
if statErr == nil {
|
|
// Path component exists
|
|
if !d.IsDir() {
|
|
// Found a file in the ancestor path
|
|
return s3err.GetAPIError(s3err.ErrObjectParentIsFile)
|
|
}
|
|
// Found a valid directory ancestor, parent truly doesn't exist
|
|
break
|
|
}
|
|
// Continue checking parent directories
|
|
dir = filepath.Dir(dir)
|
|
}
|
|
// Parent doesn't exist or is a directory, treat as ENOENT
|
|
return nil
|
|
}
|