Preserve explicit directory markers with octet-stream MIME (#8726)

* Preserve octet-stream MIME on explicit directory markers

* Run empty directory marker regression in CI

* Run S3 Spark workflow for filer changes
This commit is contained in:
Chris Lu
2026-03-21 19:31:56 -07:00
committed by GitHub
parent 7f0cf72574
commit d6a872c4b9
5 changed files with 127 additions and 6 deletions

View File

@@ -128,9 +128,7 @@ func (fsw *FilerStoreWrapper) InsertEntry(ctx context.Context, entry *Entry) err
}()
filer_pb.BeforeEntrySerialization(entry.GetChunks())
if entry.Mime == "application/octet-stream" {
entry.Mime = ""
}
normalizeEntryMimeForStore(entry)
if err := fsw.handleUpdateToHardLinks(ctx, entry); err != nil {
return err
@@ -150,9 +148,7 @@ func (fsw *FilerStoreWrapper) UpdateEntry(ctx context.Context, entry *Entry) err
}()
filer_pb.BeforeEntrySerialization(entry.GetChunks())
if entry.Mime == "application/octet-stream" {
entry.Mime = ""
}
normalizeEntryMimeForStore(entry)
if err := fsw.handleUpdateToHardLinks(ctx, entry); err != nil {
return err
@@ -162,6 +158,15 @@ func (fsw *FilerStoreWrapper) UpdateEntry(ctx context.Context, entry *Entry) err
return actualStore.UpdateEntry(ctx, entry)
}
func normalizeEntryMimeForStore(entry *Entry) {
if entry == nil {
return
}
if !entry.IsDirectory() && entry.Mime == "application/octet-stream" {
entry.Mime = ""
}
}
func (fsw *FilerStoreWrapper) FindEntry(ctx context.Context, fp util.FullPath) (entry *Entry, err error) {
ctx = context.WithoutCancel(ctx)
actualStore := fsw.getActualStore(fp)

View File

@@ -0,0 +1,71 @@
package filer
import (
"context"
"os"
"testing"
"github.com/seaweedfs/seaweedfs/weed/util"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestFilerStoreWrapperMimeNormalization(t *testing.T) {
tests := []struct {
name string
mode os.FileMode
wantMime string
}{
{
name: "files strip octet-stream",
mode: 0o660,
wantMime: "",
},
{
name: "directories keep octet-stream",
mode: os.ModeDir | 0o770,
wantMime: "application/octet-stream",
},
}
operations := []struct {
name string
run func(*FilerStoreWrapper, context.Context, *Entry) error
}{
{
name: "insert",
run: func(fsw *FilerStoreWrapper, ctx context.Context, entry *Entry) error {
return fsw.InsertEntry(ctx, entry)
},
},
{
name: "update",
run: func(fsw *FilerStoreWrapper, ctx context.Context, entry *Entry) error {
return fsw.UpdateEntry(ctx, entry)
},
},
}
for _, tt := range tests {
for _, op := range operations {
t.Run(tt.name+"/"+op.name, func(t *testing.T) {
store := newStubFilerStore()
wrapper := NewFilerStoreWrapper(store)
entry := &Entry{
FullPath: util.FullPath("/buckets/test/object"),
Attr: Attr{
Mode: tt.mode,
Mime: "application/octet-stream",
},
}
err := op.run(wrapper, context.Background(), entry)
require.NoError(t, err)
storedEntry, findErr := store.FindEntry(context.Background(), entry.FullPath)
require.NoError(t, findErr)
assert.Equal(t, tt.wantMime, storedEntry.Mime)
})
}
}
}