Skip to content

Commit

Permalink
sharded: prefix cache subdirectory names with .kismet_
Browse files Browse the repository at this point in the history
The dot means these internal subdirectories are guaranteed not to
collide with any file left from plain unsharded caching in the same
directory.  It's unfortunate that it also makes the files hidden by
default, but hopefully this can discourage direct uninformed
manipulation of the cache directory.

The `.kismet_` prefix also makes it easier to map directories back to
this library, and leaves the rest of the `.` namespace to the
application.

TESTED=existing tests.
  • Loading branch information
pkhuong committed Sep 12, 2021
1 parent b871478 commit 466a276
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/sharded.rs
Expand Up @@ -56,9 +56,16 @@ pub struct Cache {
shard_capacity: usize,
}

/// Converts a shard id to a subdirectory name.
///
/// We use a dot prefix because the resulting subdirectory names are
/// guaranteed not to collide with "plain" cache filenames. This
/// means we can switch between the sharded and plain (unsharded)
/// strategy for the same directory, without any chance of
/// misinterpreted file name.
#[inline]
fn format_id(shard: usize) -> String {
format!("{:04x}", shard)
format!(".kismet_{:04x}", shard)
}

/// We create short-lived Shard objects whenever we want to work with
Expand Down

0 comments on commit 466a276

Please sign in to comment.