fix SeaweedFS rename compatibility

Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
Nicola Murino 2022-11-20 13:06:58 +01:00
parent 0a8edcd811
commit a66d207291
No known key found for this signature in database
GPG key ID: 935D2952DEC4EECF

View file

@ -295,29 +295,20 @@ func (fs *S3Fs) Rename(source, target string) error {
if err != nil {
return err
}
copySource := fs.Join(fs.config.Bucket, source)
if fi.IsDir() {
hasContents, err := fs.hasContents(source)
if err != nil {
return err
}
if hasContents {
return fmt.Errorf("cannot rename non empty directory: %#v", source)
return fmt.Errorf("cannot rename non empty directory: %q", source)
}
if !strings.HasSuffix(copySource, "/") {
copySource += "/"
if err := fs.mkdirInternal(target); err != nil {
return err
}
if !strings.HasSuffix(target, "/") {
target += "/"
}
}
var contentType string
if fi.IsDir() {
contentType = s3DirMimeType
} else {
contentType = mime.TypeByExtension(path.Ext(source))
}
copySource = pathEscape(copySource)
contentType := mime.TypeByExtension(path.Ext(source))
copySource := pathEscape(fs.Join(fs.config.Bucket, source))
if fi.Size() > 500*1024*1024 {
fsLog(fs, logger.LevelDebug, "renaming file %q with size %d using multipart copy",
@ -351,7 +342,6 @@ func (fs *S3Fs) Rename(source, target string) error {
return err
}
if plugin.Handler.HasMetadater() {
if !fi.IsDir() {
err = plugin.Handler.SetModificationTime(fs.getStorageID(), ensureAbsPath(target),
util.GetTimeAsMsSinceEpoch(fi.ModTime()))
if err != nil {
@ -399,14 +389,7 @@ func (fs *S3Fs) Mkdir(name string) error {
if !fs.IsNotExist(err) {
return err
}
if !strings.HasSuffix(name, "/") {
name += "/"
}
_, w, _, err := fs.Create(name, -1)
if err != nil {
return err
}
return w.Close()
return fs.mkdirInternal(name)
}
// Symlink creates source as a symbolic link to target.
@ -784,6 +767,17 @@ func (fs *S3Fs) setConfigDefaults() {
}
}
func (fs *S3Fs) mkdirInternal(name string) error {
if !strings.HasSuffix(name, "/") {
name += "/"
}
_, w, _, err := fs.Create(name, -1)
if err != nil {
return err
}
return w.Close()
}
func (fs *S3Fs) hasContents(name string) (bool, error) {
prefix := fs.getPrefix(name)
paginator := s3.NewListObjectsV2Paginator(fs.svc, &s3.ListObjectsV2Input{