# Using a checksum to identify a unique directory

**URL:** <https://discuss.circleci.com/t/using-a-checksum-to-identify-a-unique-directory/33737>\
**Category:** Running Tests\
**Created:** [December 13, 2019, 1:56pm UTC](https://discuss.circleci.com/t/using-a-checksum-to-identify-a-unique-directory/33737 "2019-12-13T13:56:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![abe](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/abe/32/23803_2.png) [@abe](https://discuss.circleci.com/u/abe)\
**Post date:** [December 13, 2019, 1:56pm UTC](https://discuss.circleci.com/t/using-a-checksum-to-identify-a-unique-directory/33737/1 "2019-12-13T13:56:57Z")

</div>

I have a rails app that compiles assets as part of the test suite. What was working before is no longer working:

```auto
steps:
      - checkout
      - run: mkdir -p tmp/test/cache/assets
      - attach_workspace:
          at: ~/fworkspace
      - run: tar -cf - app/assets | md5sum > asset_checksum.txt
      - restore_cache:
          keys:
            - v4-app-assets-{{ checksum "asset_checksum.txt" }}
            - v4-app-assets-
      - run: npm install
      - run: bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3
      - run: bundle exec rake assets:precompile
      - save_cache:
          key: v4-app-assets-{{ checksum "asset_checksum.txt" }}
          paths:
            - tmp/test/cache/assets
            - public/assets
      - persist_to_workspace:
          root: ~/fworkspace
          paths:
            - tmp/test/cache/assets
            - public/assets

```

This _used_ to check if there are any changes in the app/assets folder, and if not restore from cache, but if there are, go ahead and compile assets without restoring from cache.

I also tried a second suggestion found on the discussion boards:  
`- run: | echo $(find ./app/assets -type f -exec md5sum {} \; | md5sum | cut -d' ' -f1) >> ASSET_CACHE_KEY`

This also does not see to generate the same key for the same app/assets. Any suggests what I may be doing wrong here?

---

<div class="post-metadata">

**Author:** ![Kurt-von-Laven](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/kurt-von-laven/32/26911_2.png) [@Kurt-von-Laven](https://discuss.circleci.com/u/Kurt-von-Laven)\
**Post date:** [May 16, 2021, 2:52am UTC](https://discuss.circleci.com/t/using-a-checksum-to-identify-a-unique-directory/33737/3 "2021-05-16T02:52:06Z")

</div>

[Checksum different before and after bundle install - #11 by PADomine](https://discuss.circleci.com/t/checksum-different-before-and-after-bundle-install/17334/11) or [Caching Dependencies - CircleCI](https://circleci.com/docs/2.0/caching/#using-caching-in-monorepos) may address the issue you encountered, @abe.

---

<div class="post-metadata">

**Author:** ![abepetrillo](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/abepetrillo/32/2420_2.png) [@abepetrillo](https://discuss.circleci.com/u/abepetrillo)\
**Post date:** [August 29, 2025, 1:04am UTC](https://discuss.circleci.com/t/using-a-checksum-to-identify-a-unique-directory/33737/4 "2025-08-29T01:04:30Z")

</div>

This wasn’t relevant. Tar is taking into account more than just file contents, like creation date and other meta datawhich would be different on each checkout. Ended up going with an alternative.

---

<div class="post-metadata">

**Author:** ![abepetrillo](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/abepetrillo/32/2420_2.png) [@abepetrillo](https://discuss.circleci.com/u/abepetrillo)\
**Post date:** [August 29, 2025, 1:06am UTC](https://discuss.circleci.com/t/using-a-checksum-to-identify-a-unique-directory/33737/5 "2025-08-29T01:06:39Z")

</div>

find app/assets -type f -exec md5sum {} \; | sort -k 2 | md5sum \> asset\_checksum.txt
