avformat/shared: hash cache version into filename

Changing version implies a non-backwards compatible disk layout.
Alternatively, we could detect a version mismatch and delete + rebuild the
cache file, but that's nontrivial to get right because of existing processes
that might be concurrently trying to open the same cache file with the old
version.

Overall, cleaner and safer to just separate them by version.

Sponsored-by: nxtedition AB
Signed-off-by: Niklas Haas <git@haasn.dev>
This commit is contained in:
Niklas Haas
2026-07-01 14:41:42 +02:00
committed by Niklas Haas
parent aa8fc9f946
commit cce1b4f228
+4 -3
View File
@@ -59,6 +59,8 @@
*/
#define HASH_METHOD "SHA512/256"
#define HASH_SIZE 32
#define HEADER_MAGIC MKTAG(u'\xFF', 'S', 'h', '$')
#define HEADER_VERSION 3
static int hash_uri(uint8_t hash[HASH_SIZE], const char *uri)
{
@@ -67,8 +69,10 @@ static int hash_uri(uint8_t hash[HASH_SIZE], const char *uri)
if (ret < 0)
return ret;
const int16_t version = HEADER_VERSION;
av_assert0(av_hash_get_size(ctx) == HASH_SIZE);
av_hash_init(ctx);
av_hash_update(ctx, (const uint8_t *) &version, sizeof(version));
av_hash_update(ctx, (const uint8_t *) uri, strlen(uri));
av_hash_final(ctx, hash);
av_hash_freep(&ctx);
@@ -78,9 +82,6 @@ static int hash_uri(uint8_t hash[HASH_SIZE], const char *uri)
return 0;
}
#define HEADER_MAGIC MKTAG(u'\xFF', 'S', 'h', '$')
#define HEADER_VERSION 3
enum BlockState {
/* Reserved block state values */
BLOCK_NONE = 0, ///< block is not cached