Topics
Recent articles

DevOps & Cloud

Prevent Draft Raster Filename Collisions

Learn how to prevent filename collisions when managing reviewed raster assets by comparing Git blob hashes instead of relying on static file paths.

Table of Contents1 sections
A modern creative workspace featuring a laptop and monitor displaying digital images and editing software.
A modern creative workspace featuring a laptop and monitor displaying digital images and editing software.

When your build pipeline uses repeatable filenames for raster assets, a collision occurs if a new draft overwrites an approved file that shares the same path. Relying on file existence alone can lead to inconsistent state where your metadata points to the wrong bytes. To ensure integrity, you must verify the content before committing.

Quick solution:

if [ "$(git hash-object current.jpg)" != "$(git hash-object new.jpg)" ]; then
  mv new.jpg "asset-$(git hash-object new.jpg | cut -c1-7).jpg"
fi

Understanding Git Object Identity

Git stores data as content-addressed objects. As detailed in the Git Internals documentation, the object ID is a SHA-1 hash of the content itself. When you manage assets, you should treat the blob hash as the source of truth rather than the filename. If you need to interact with these objects programmatically, the GitHub Git blob REST API provides methods to retrieve specific blobs by their hash, ensuring you are always working with the exact bytes approved during review.

Handling Collision Scenarios

When a draft filename collision occurs, you must decide whether to overwrite or preserve the asset. You can Validate Raster Images in CI Beyond Metadata to ensure that the file is not only correctly named but also structurally sound. Use the following logic to manage your storage:

Scenario Action Result
New path Write file New asset added to catalog
Same blob hash Skip write Existing file remains valid
Occupied path, different bytes Rename to hash Both versions preserved

Implementation Checklist

You Might Also Like

View all articles
Preventing Old Draft Starvation in Publishers
4 min read

Preventing Old Draft Starvation in Publishers

Learn how to prevent older ready drafts from being starved by newly created items in single-item batch publishing workflows using a snapshot-based priority rule.