Skip to content

Commit

Permalink
Merge pull request #110 from MordechaiHadad/fix/sync
Browse files Browse the repository at this point in the history
  • Loading branch information
MordechaiHadad authored Mar 14, 2023
2 parents 7210bb1 + b660c87 commit 0395d4d
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 34 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
target
resources
bin
54 changes: 27 additions & 27 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "bob-nvim"
edition = "2021"
version = "2.1.2"
version = "2.1.3"
description = "A version manager for neovim"
readme = "README.md"
keywords = ["neovim", "version-manager"]
Expand Down
23 changes: 23 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM rust:latest

RUN useradd -m -s /bin/bash bobuser

WORKDIR /app

COPY . .

RUN cargo build

USER bobuser

RUN mkdir -p ~/.config/bob && echo '{"version_sync_file_location": "/home/bobuser/.config/nvim/nvim.version"}' > ~/.config/bob/config.json
RUN mkdir -p ~/.config/nvim

USER root

RUN cp target/debug/bob /usr/local/bin/

USER bobuser
ENV USER=bobuser

CMD ["echo", "Use 'bob' to start the project"]
9 changes: 7 additions & 2 deletions src/handlers/sync_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ pub async fn start(client: &Client, config: Config) -> Result<()> {
.ok_or_else(|| anyhow!("sync_version_file_path needs to be set to use bob sync"))?;

let version = fs::read_to_string(&sync_version_file_path).await?;
if version.contains("nightly-") {
if version.is_empty() {
return Err(anyhow!("Sync file is empty"));
}
let trimmed_version = version.trim();

if trimmed_version.contains("nightly-") {
return Err(anyhow!("Cannot sync nightly rollbacks."));
}

Expand All @@ -26,7 +31,7 @@ pub async fn start(client: &Client, config: Config) -> Result<()> {
);

use_handler::start(
version::parse_version_type(client, &version).await?,
version::parse_version_type(client, trimmed_version).await?,
true,
client,
config,
Expand Down
6 changes: 2 additions & 4 deletions src/helpers/version/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,8 @@ pub async fn parse_version_type(client: &Client, version: &str) -> Result<Parsed
pub async fn get_sync_version_file_path(config: &Config) -> Result<Option<PathBuf>> {
let path = match &config.version_sync_file_location {
Some(path) => {
if let Err(e) = tokio::fs::metadata(path).await {
return Err(anyhow!(
"Error when trying to retrieve sync_version_file_path {path}: {e}"
));
if tokio::fs::metadata(path).await.is_err() {
fs::write(path, b"").await?;
}
Some(PathBuf::from(path))
}
Expand Down

0 comments on commit 0395d4d

Please sign in to comment.