Skip to content

fix: correct KeyCount and IsTruncated semantics for ListObjects#4

Open
Amahdip wants to merge 2 commits into
mysamimi:mainfrom
Amahdip:fix-list-objects
Open

fix: correct KeyCount and IsTruncated semantics for ListObjects#4
Amahdip wants to merge 2 commits into
mysamimi:mainfrom
Amahdip:fix-list-objects

Conversation

@Amahdip

@Amahdip Amahdip commented Jun 9, 2026

Copy link
Copy Markdown

Description

This PR focuses strictly on a few correctness issues regarding the S3 ListObjects APIs (v1 and v2), specifically addressing metadata accuracy (KeyCount and IsTruncated).

Note: This PR does not attempt to fully implement S3 pagination (NextMarker / NextContinuationToken). It intentionally leaves tokens empty to avoid promising incomplete/broken pagination to clients, keeping the scope narrow to metadata correctness.

Changes Made:

  • KeyCount Fix: For ListObjectsV2, KeyCount is now dynamically calculated as the sum of emitted files (Contents) plus emitted directories (CommonPrefixes), instead of returning a hardcoded 0.
  • IsTruncated Lookahead Logic: Fixed a bug where IsTruncated was incorrectly flagged. The loop now processes the max_keys + 1 item. If the limit is reached and another valid, emit-able item exists, the loop halts without emitting it and accurately sets is_truncated = true. This handles edge cases where the files match exactly max_keys.
  • Cleaned Up Dead Code: Removed walker.skip_current_dir(). Since it was unconditionally applied to file entries (directories were filtered out earlier in the loop), it was a no-op that just created logical confusion.
  • Automated Tests: Added focused unit tests simulating filesystem behavior to verify KeyCount and IsTruncated bounds, including delimiter semantics.

توضیحات فارسی

این PR به طور مشخص روی برطرف کردن باگ‌های مربوط به صحت متادیتا (مثل KeyCount و IsTruncated) در API مربوط به ListObjects تمرکز دارد و شامل پیاده‌سازی کامل سیستم صفحه‌بندی (Pagination) نیست. توکن‌های بازگشتی موقتاً خالی گذاشته شده‌اند تا به کلاینت‌ها وعده صفحه‌بندی خراب داده نشود.

تغییرات اعمال شده:

  • تصحیح KeyCount: مقدار KeyCount از این به بعد مجموع دقیقی از فایل‌ها (Contents) و پوشه‌های بازگردانده شده (CommonPrefixes) است و دیگر عدد صفر به صورت هاردکد ارسال نمی‌شود.
  • تغییر منطق IsTruncated: منطق پایان یافتن لیست تغییر کرد تا باگ مرزی برطرف شود. حالا سیستم برای آیتم N+1 اُم که کاندیدای معتبری باشد یک جستجوی آینده‌نگر (Lookahead) انجام می‌دهد تا تشخیص دهد آیا لیست واقعاً به انتها رسیده یا خیر.
  • حذف کدهای اضافی: دستور بی‌تأثیر walker.skip_current_dir() حذف شد.
  • تست‌ها: چندین Unit Test جدید برای بررسی عملکرد صحیح سیستم صفحه‌بندی و پوشه‌ها (Delimiter) اضافه شد.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant