Skip to content

Append suffix of duplicate file names#387

Open
eric-pSAP wants to merge 17 commits intomainfrom
fileSuffixCount
Open

Append suffix of duplicate file names#387
eric-pSAP wants to merge 17 commits intomainfrom
fileSuffixCount

Conversation

@eric-pSAP
Copy link
Contributor

Duplicate file names added are given a suffix of -1, -2, etc. before adding the metadata

@hyperspace-insights
Copy link
Contributor

Summary

The following content is AI-generated and provides a summary of the pull request:


Append Suffix to Duplicate File Names

✨ New Feature

Implemented automatic handling of duplicate filenames in attachments by appending numerical suffixes (-1, -2, etc.) before the file extension. When multiple files with the same name are uploaded, the system now automatically renames them to prevent conflicts while preserving the original file extension.

Changes

  • lib/helper.js: Added handleDuplicateFilename() function that checks for existing filenames within the same parent entity and appends incremental suffixes to duplicates before insertion. The function extracts the file extension, generates a new filename with a counter, and ensures uniqueness by checking against all existing attachments.

  • lib/plugin.js: Modified the CREATE handler to be asynchronous and integrated the duplicate filename handling logic. The handler now processes both single entries and arrays, applying the deduplication logic to each entry before proceeding with attachment preparation.

  • tests/incidents-app/db/attachments.cds: Updated the @Validation.MaxItems annotation from 2 to 3 to accommodate testing scenarios with multiple duplicate attachments.

  • tests/integration/attachments.test.js: Added comprehensive test suite with three test cases:

    • Uploading three attachments with identical names in the same draft session, verifying they are renamed to sample.pdf, sample-1.pdf, and sample-2.pdf
    • Uploading a duplicate after the first attachment has been saved, confirming proper renaming behavior across draft sessions
    • Handling edge cases where filenames already contain numerical suffixes (e.g., sample-1.pdf becomes sample-1-1.pdf, sample-1-2.pdf)

  • 🔄 Regenerate and Update Summary
  • ✏️ Insert as PR Description (deletes this comment)
  • 🗑️ Delete comment
PR Bot Information

Version: 1.17.80 | 📖 Documentation | 🚨 Create Incident | 💬 Feedback

  • Event Trigger: pull_request.opened
  • LLM: anthropic--claude-4.5-sonnet
  • Output Template: Default Template
  • Correlation ID: 69a04400-13e7-11f1-97f8-6be3cbe6ab4b
  • Summary Prompt: Default Prompt

💌 Have ideas or want to contribute? Create an issue and share your thoughts with us!
📑 Check out the documentation for more information.
📬 Subscribe to the Hyperspace PR Bot DL to get the latest announcements and pilot features!

Made with ❤️ by Hyperspace.

Copy link
Contributor

@hyperspace-insights hyperspace-insights bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pull request adds functionality to automatically rename duplicate attachment filenames by appending suffixes (-1, -2, etc.). I've identified several substantive issues including a logic error with extension-less files, a potential race condition with concurrent operations, a missing null check, and performance concerns with large attachment lists. The author should address these issues to ensure correct and robust handling of duplicate filenames.

PR Bot Information

Version: 1.17.80 | 📖 Documentation | 🚨 Create Incident | 💬 Feedback

  • Event Trigger: pull_request.opened
  • LLM: anthropic--claude-4.5-sonnet
  • Correlation ID: 69a04400-13e7-11f1-97f8-6be3cbe6ab4b

@eric-pSAP eric-pSAP marked this pull request as ready for review February 27, 2026 15:45
@eric-pSAP eric-pSAP requested a review from a team as a code owner February 27, 2026 15:45
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.

2 participants