Add --strip-uuid flag to remove UUIDs from exported filenames#19
Add --strip-uuid flag to remove UUIDs from exported filenames#19davidbean-hash wants to merge 1 commit into
Conversation
Implements ChargePoint#42: Option to remove UUID from image filenames. - Add stripUUID property to AttachmentExportOptions - Add --strip-uuid CLI flag to both ScreenshotsCommand and AttachmentsCommand - Add XCPParser.filenameByStrippingUUID(from:) static method using regex - Handle filename collisions by appending _2, _3, etc. counter suffix - Add StripUUIDTests with 11 test cases covering various filename patterns Co-Authored-By: david.bean <david.bean@cognition.ai>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
| let count = usedFilenames[strippedFilename, default: 0] | ||
| usedFilenames[strippedFilename] = count + 1 | ||
| if count > 0 { | ||
| let nameWithoutExtension = (strippedFilename as NSString).deletingPathExtension | ||
| let fileExtension = (strippedFilename as NSString).pathExtension | ||
| if fileExtension.isEmpty { | ||
| strippedFilename = "\(nameWithoutExtension)_\(count + 1)" | ||
| } else { | ||
| strippedFilename = "\(nameWithoutExtension)_\(count + 1).\(fileExtension)" | ||
| } | ||
| } |
There was a problem hiding this comment.
🟡 Deduplication suffix can collide with another file's natural stripped name, causing silent overwrite
The usedFilenames dictionary tracks only the pre-dedup stripped filename, not the actual output filename after a _N suffix is appended. This means a collision-avoidance name can overwrite a different file that naturally has that name.
Concrete collision scenario
Consider three attachments in the same directory:
- File A:
Screenshot_UUID1.png→ strips toScreenshot.png - File B:
Screenshot_UUID2.png→ strips toScreenshot.png - File C:
Screenshot_2_UUID3.png→ strips toScreenshot_2.png
Processing:
- File A →
usedFilenames["Screenshot.png"] = 1→ output:Screenshot.png - File B → count=1 → suffix
_2→ output:Screenshot_2.png - File C →
usedFilenames["Screenshot_2.png"] = 1, count=0 → no suffix → output:Screenshot_2.png← overwrites File B!
The suffixed output filenames are never checked against or added to usedFilenames, so the code cannot detect that Screenshot_2.png is already in use.
Prompt for agents
In XCPParser.exportAttachments (around lines 312-331), the usedFilenames dictionary tracks stripped base filenames, but the collision-avoidance suffixed filenames (like Screenshot_2.png) are never registered in the dictionary. This means another file that naturally strips to that same name will silently overwrite it.
The fix is to track the actual output filenames rather than just the pre-dedup base names. One approach: change usedFilenames to a Set<String> that stores the final output filenames. When generating a dedup suffix, keep incrementing the counter until the resulting filename is not in the set. Always insert the final output filename into the set. For example:
var usedFilenames = Set<String>()
...
var candidate = strippedFilename
var counter = 2
while usedFilenames.contains(candidate) {
// generate candidate with _counter suffix
counter += 1
}
usedFilenames.insert(candidate)
strippedFilename = candidate
Was this helpful? React with 👍 or 👎 to provide feedback.
Change Description:
Implements ChargePoint/xcparse#42: Option to remove UUID from image filenames.
Currently exported screenshots have UUIDs embedded in their names like
Screenshot_1_BC641069-A876-42D7-AD9E-54D7CB3B984D.heic. This PR adds a--strip-uuidflag to thescreenshotsandattachmentscommands that strips the_<UUID>portion from filenames during export, producing cleaner names likeScreenshot_1.heic.Changes
AttachmentExportOptions(XCPParser.swift): AddedstripUUID: BoolpropertyXCPParser(XCPParser.swift):filenameByStrippingUUID(from:)static method using regex pattern_[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}exportAttachmentsto acceptstripUUIDparameter and handle collision resolution (appends_2,_3, etc.)stripUUIDis enabled, usesXCResultToolCommand.Export(id:outputPath:type:)with the modified filename instead of the attachment-based initializerScreenshotsCommand: Registered--strip-uuidCLI flagAttachmentsCommand: Registered--strip-uuidCLI flagUsage
Collision handling
When stripping UUIDs produces duplicate filenames (e.g., two
Screenshot_1.heic), a counter suffix is appended:Screenshot_1.heic,Screenshot_1_2.heic,Screenshot_1_3.heic, etc.Test Plan/Testing Performed:
Added
StripUUIDTests.swiftwith 11 unit test cases covering:Screenshot_1_BC641069-...) →Screenshot_1.heic.heic,.png,.jpeg)Link to Devin session: https://app.devin.ai/sessions/a11e28d22c614743849b525b99f64aef
Requested by: @davidbean-hash