diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..0057c68 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +target +resources +bin diff --git a/Cargo.lock b/Cargo.lock index 6755723..6911d17 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -72,7 +72,7 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bob-nvim" -version = "2.1.2" +version = "2.1.3" dependencies = [ "anyhow", "async-recursion", @@ -150,9 +150,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.23" +version = "0.4.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16b0a3d9ed01224b22057780a37bb8c5dbfe1be8ba48678e7bf57ec4b385411f" +checksum = "4e3c5919066adf22df73762e50cffcde3a758f2a848b113b586d1f86728b673b" dependencies = [ "iana-time-zone", "js-sys", @@ -868,18 +868,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.51" +version = "1.0.52" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d727cae5b39d21da60fa540906919ad737832fe0b1c165da3a34d6548c849d6" +checksum = "1d0e1ae9e836cc3beddd63db0df682593d7e2d3d891ae8c9083d2113e1744224" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.23" +version = "1.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" +checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc" dependencies = [ "proc-macro2", ] @@ -1070,18 +1070,18 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.155" +version = "1.0.156" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71f2b4817415c6d4210bfe1c7bfcf4801b2d904cb4d0e1a8fdb651013c9e86b8" +checksum = "314b5b092c0ade17c00142951e50ced110ec27cea304b1037c6969246c2469a4" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.155" +version = "1.0.156" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d071a94a3fac4aff69d023a7f411e33f40f3483f8c5190b1953822b6b76d7630" +checksum = "d7e29c4601e36bcec74a223228dce795f4cd3616341a4af93520ca1a837c087d" dependencies = [ "proc-macro2", "quote", @@ -1646,9 +1646,9 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.42.1" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e2522491fbfcd58cc84d47aeb2958948c4b8982e9a2d8a2a35bbaed431390e7" +checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" dependencies = [ "windows_aarch64_gnullvm", "windows_aarch64_msvc", @@ -1661,45 +1661,45 @@ dependencies = [ [[package]] name = "windows_aarch64_gnullvm" -version = "0.42.1" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c9864e83243fdec7fc9c5444389dcbbfd258f745e7853198f365e3c4968a608" +checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" [[package]] name = "windows_aarch64_msvc" -version = "0.42.1" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c8b1b673ffc16c47a9ff48570a9d85e25d265735c503681332589af6253c6c7" +checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" [[package]] name = "windows_i686_gnu" -version = "0.42.1" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de3887528ad530ba7bdbb1faa8275ec7a1155a45ffa57c37993960277145d640" +checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" [[package]] name = "windows_i686_msvc" -version = "0.42.1" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf4d1122317eddd6ff351aa852118a2418ad4214e6613a50e0191f7004372605" +checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" [[package]] name = "windows_x86_64_gnu" -version = "0.42.1" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1040f221285e17ebccbc2591ffdc2d44ee1f9186324dd3e84e99ac68d699c45" +checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" [[package]] name = "windows_x86_64_gnullvm" -version = "0.42.1" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "628bfdf232daa22b0d64fdb62b09fcc36bb01f05a3939e20ab73aaf9470d0463" +checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" [[package]] name = "windows_x86_64_msvc" -version = "0.42.1" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd" +checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" [[package]] name = "winreg" diff --git a/Cargo.toml b/Cargo.toml index fbc2b93..b1139fd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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"] diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4951f1e --- /dev/null +++ b/Dockerfile @@ -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"] diff --git a/src/handlers/sync_handler.rs b/src/handlers/sync_handler.rs index 03abbe5..e28e30c 100644 --- a/src/handlers/sync_handler.rs +++ b/src/handlers/sync_handler.rs @@ -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.")); } @@ -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, diff --git a/src/helpers/version/mod.rs b/src/helpers/version/mod.rs index e77b74d..3bac8ee 100644 --- a/src/helpers/version/mod.rs +++ b/src/helpers/version/mod.rs @@ -66,10 +66,8 @@ pub async fn parse_version_type(client: &Client, version: &str) -> Result Result> { 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)) }