Skip to content

Open-source LLM knowledge platform: turn raw documents into a queryable RAG, an autonomous reasoning agent, and a self-maintaining Wiki.

fix(feishu-drive): skip OS metadata files instead of failing the sync (#4738)

u7-u7184cec1ac51d
diff --git a/internal/datasource/connector/feishu/drive/connector.go b/internal/datasource/connector/feishu/drive/connector.go
index 3ad219078..784232335 100644
--- a/internal/datasource/connector/feishu/drive/connector.go
+++ b/internal/datasource/connector/feishu/drive/connector.go
@@ -338,6 +338,12 @@ func (o *driveOps) EditTime(n core.DriveFile) string {
func (o *driveOps) Fetch(
ctx context.Context, client *core.Client, n core.DriveFile, resourceID string,
) ([]*types.FetchedItem, error) {
+ // OS bookkeeping files are not documents. Fetching one fails as an
+ // unsupported type and turns an otherwise clean incremental round into a
+ // failure; an empty result is reported as skipped by the engine (#4712).
+ if isSystemJunkFileName(n.Name) {
+ return nil, nil
+ }
items, err := fetchDriveFileContent(ctx, client, n, resourceID, o.region, o.parseMode)
if err != nil {
return nil, err
@@ -348,6 +354,18 @@ func (o *driveOps) Fetch(
return items, nil
}
+// isSystemJunkFileName reports OS metadata that Finder, Windows Explorer and
+// Office drop into shared folders. These names carry no user content, so a
+// drive sync skips them instead of counting every copy as a failed document.
+func isSystemJunkFileName(name string) bool {
+ base := strings.ToLower(strings.TrimSpace(name))
+ switch base {
+ case ".ds_store", "thumbs.db", "desktop.ini":
+ return true
+ }
+ return strings.HasPrefix(base, "._") || strings.HasPrefix(base, "~$")
+}
+
func (o *driveOps) ListFailureItems(resourceID string, partial error) []types.FetchedItem {
var pe *core.PartialDriveFileListError
if errors.As(partial, &pe) {
diff --git a/internal/datasource/connector/feishu/drive/junk_test.go b/internal/datasource/connector/feishu/drive/junk_test.go
new file mode 100644
index 000000000..7e4a31054
--- /dev/null
+++ b/internal/datasource/connector/feishu/drive/junk_test.go
@@ -0,0 +1,33 @@
+package drive
+
+import (
+ "context"
+ "testing"
+
+ "github.com/Tencent/WeKnora/internal/datasource/connector/feishu/core"
+ "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
+)
+
+func TestIsSystemJunkFileName(t *testing.T) {
+ for _, name := range []string{
+ ".DS_Store", " .DS_Store ", "Thumbs.db", "desktop.ini",
+ "._resource-fork", "~$budget.xlsx",
+ } {
+ assert.True(t, isSystemJunkFileName(name), "want junk: %q", name)
+ }
+ for _, name := range []string{
+ "notes.md", "DS_Store", "Thumbs.db.bak", "report.pdf", "",
+ } {
+ assert.False(t, isSystemJunkFileName(name), "want document: %q", name)
+ }
+}
+
+// Fetch must short-circuit before touching the client: passing nil proves no
+// export/download request is made for a junk file.
+func TestDriveFetchSkipsSystemJunkWithoutFetching(t *testing.T) {
+ o := &driveOps{}
+ items, err := o.Fetch(context.Background(), nil, core.DriveFile{Name: ".DS_Store"}, "resource")
+ require.NoError(t, err)
+ assert.Empty(t, items)
+}