-/// Check that the errors in `err_map` aren't present in any metadata files in the
-/// metadata directory except the metadata file corresponding to `name`.
-pub fn check_uniqueness(name: &str, err_map: &ErrorMap) -> Result<Uniqueness, Box<Error>> {
- let metadata_dir = get_metadata_dir();
- let metadata_path = get_metadata_path(name);
-
- // Create the error directory if it does not exist.
- try!(create_dir_all(&metadata_dir));
-
- // Check each file in the metadata directory.
- for entry in try!(read_dir(&metadata_dir)) {
- let path = try!(entry).path();
-
- // Skip any existing file for this set.
- if path == metadata_path {
- continue;
- }
-
- // Read the metadata file into a string.
- let mut metadata_str = String::new();
- try!(
- File::open(&path).and_then(|mut f|
- f.read_to_string(&mut metadata_str))
- );
-
- // Parse the JSON contents.
- let metadata: ErrorMetadataMap = try!(json::decode(&metadata_str));
-
- // Check for duplicates.
- for err in err_map.keys() {
- let err_code = err.as_str();
- if metadata.contains_key(err_code) {
- return Ok(Duplicate(
- err_code.to_string(),
- path.to_string_lossy().into_owned()
- ));
- }
- }
- }
-
- Ok(Unique)
+/// Map `name` to a path in the given directory: <directory>/<name>.json
+fn get_metadata_path(directory: PathBuf, name: &str) -> PathBuf {
+ directory.join(format!("{}.json", name))