summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorsharkdp <davidpeter@web.de>2020-04-21 17:19:07 +0200
committerDavid Peter <sharkdp@users.noreply.github.com>2020-04-21 18:14:31 +0200
commit2e9cf63a5fd63bd5bcf16cfce67b5999042b89cb (patch)
tree72a36926a56ae37f09243df15a15eeb5ee3a1cb7 /src
parent886b22e0ee082d1096e6c8bc71e10270a9bd1d7a (diff)
Fix compilation of library
Diffstat (limited to 'src')
-rw-r--r--src/assets.rs4
-rw-r--r--src/assets_metadata.rs9
-rw-r--r--src/bin/bat/assets.rs2
-rw-r--r--src/bin/bat/main.rs6
4 files changed, 10 insertions, 11 deletions
diff --git a/src/assets.rs b/src/assets.rs
index c75641de..f5bb7c4e 100644
--- a/src/assets.rs
+++ b/src/assets.rs
@@ -117,7 +117,7 @@ impl HighlightingAssets {
}
}
- pub fn save_to_cache(&self, target_dir: &Path) -> Result<()> {
+ pub fn save_to_cache(&self, target_dir: &Path, current_version: &str) -> Result<()> {
let _ = fs::create_dir_all(target_dir);
let theme_set_path = target_dir.join("themes.bin");
let syntax_set_path = target_dir.join("syntaxes.bin");
@@ -150,7 +150,7 @@ impl HighlightingAssets {
"Writing metadata to folder {} ... ",
target_dir.to_string_lossy()
);
- AssetsMetadata::new().save_to_folder(target_dir)?;
+ AssetsMetadata::new(current_version).save_to_folder(target_dir)?;
println!("okay");
Ok(())
diff --git a/src/assets_metadata.rs b/src/assets_metadata.rs
index ca5443c3..d4aaaea1 100644
--- a/src/assets_metadata.rs
+++ b/src/assets_metadata.rs
@@ -2,7 +2,6 @@ use std::fs::File;
use std::path::Path;
use std::time::SystemTime;
-use clap::crate_version;
use semver::Version;
use serde::{Deserialize, Serialize};
@@ -17,9 +16,9 @@ pub struct AssetsMetadata {
const FILENAME: &'static str = "metadata.yaml";
impl AssetsMetadata {
- pub(crate) fn new() -> AssetsMetadata {
+ pub(crate) fn new(current_version: &str) -> AssetsMetadata {
AssetsMetadata {
- bat_version: Some(crate_version!().into()),
+ bat_version: Some(current_version.to_owned()),
creation_time: Some(SystemTime::now()),
}
}
@@ -64,9 +63,9 @@ impl AssetsMetadata {
}
}
- pub fn is_compatible(&self) -> bool {
+ pub fn is_compatible_with(&self, current_version: &str) -> bool {
let current_version =
- Version::parse(crate_version!()).expect("bat follows semantic versioning");
+ Version::parse(current_version).expect("bat follows semantic versioning");
let stored_version = self
.bat_version
.as_ref()
diff --git a/src/bin/bat/assets.rs b/src/bin/bat/assets.rs
index 5d15ba1c..bfb3c178 100644
--- a/src/bin/bat/assets.rs
+++ b/src/bin/bat/assets.rs
@@ -37,7 +37,7 @@ pub fn clear_assets() {
pub fn assets_from_cache_or_binary() -> Result<HighlightingAssets> {
let cache_dir = PROJECT_DIRS.cache_dir();
if let Some(metadata) = AssetsMetadata::load_from_folder(&cache_dir)? {
- if !metadata.is_compatible() {
+ if !metadata.is_compatible_with(crate_version!()) {
return Err(format!(
"The binary caches for the user-customized syntaxes and themes \
in '{}' are not compatible with this version of bat ({}). To solve this, \
diff --git a/src/bin/bat/main.rs b/src/bin/bat/main.rs
index ebd13a18..3b59b896 100644
--- a/src/bin/bat/main.rs
+++ b/src/bin/bat/main.rs
@@ -22,13 +22,13 @@ use crate::{
config::{config_file, generate_config_file},
};
use assets::{assets_from_cache_or_binary, cache_dir, clear_assets, config_dir};
-use bat::Controller;
+use clap::crate_version;
use directories::PROJECT_DIRS;
use bat::{
config::{Config, InputFile, OrdinaryFile, StyleComponent, StyleComponents},
errors::*,
- HighlightingAssets,
+ Controller, HighlightingAssets,
};
fn run_cache_subcommand(matches: &clap::ArgMatches) -> Result<()> {
@@ -45,7 +45,7 @@ fn run_cache_subcommand(matches: &clap::ArgMatches) -> Result<()> {
let blank = matches.is_present("blank");
let assets = HighlightingAssets::from_files(source_dir, !blank)?;
- assets.save_to_cache(target_dir)?;
+ assets.save_to_cache(target_dir, crate_version!())?;
} else if matches.is_present("clear") {
clear_assets();
}