Skip to content

Commit

Permalink
Fixed an issue where an re-uploaded file would remain in the database…
Browse files Browse the repository at this point in the history
… and be uploaded again, and where a failed screenshot could be removed from the database while not having been uploaded.
  • Loading branch information
apognu committed Jan 13, 2023
1 parent 9f7f4bc commit ab686aa
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 10 deletions.
11 changes: 10 additions & 1 deletion Cargo.lock

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

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ log = "*"
notify = "5.0.0"
oauth2 = "4.3.0"
onedrive-api = { version = "0.9.0", default-features = false }
pickledb = "0.5.1"
pickledb = { version = "0.5.1", default-features = false, features = ["bincode"] }
reqwest = { version = "0.11.13", default-features = false, features = ["rustls-tls"] }
rust-s3 = {version = "0.32.3", default-features = false, features = ["tokio-rustls-tls"] }
serde = "^1.0"
serde_json = "^1.0"
serde_yaml = "0.9.16"
serenity = { version = "0.11", default-features = false, features = ["builder", "client", "gateway", "http", "model", "rustls_backend"] }
tokio = { version = "^1.23", features = ["macros", "rt-multi-thread", "sync", "io-util"] }

rand = "0.8.5"

[dev-dependencies]
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ The Google Drive integration requires a service account created from the [Google
To do so, note the service account email address (`xxx@[email protected]`), and share the folder with that email address, with write permissions. Also note the folder ID from the URL, you will need to indicate it in the configuration.

Finally, you will need to enable the [Google Drive API](https://console.cloud.google.com/marketplace/product/google/drive.googleapis.com).

```yaml
uploader:
kind: GoogleDrive
Expand Down
6 changes: 3 additions & 3 deletions src/database.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::sync::Arc;

use anyhow::Context;
use pickledb::PickleDb;
use pickledb::{PickleDb, SerializationMethod};
use tokio::{
fs::{create_dir_all, File},
io::{AsyncReadExt, AsyncWriteExt},
Expand All @@ -26,14 +26,14 @@ pub fn init_db(config: &Config) -> Result<Db, anyhow::Error> {
}

fn create_db(config: &Config) -> PickleDb {
PickleDb::new(config.deckshot_path.join("deckshot.db"), pickledb::PickleDbDumpPolicy::AutoDump, pickledb::SerializationMethod::Json)
PickleDb::new(config.deckshot_path.join("deckshot.db"), pickledb::PickleDbDumpPolicy::AutoDump, SerializationMethod::Bin)
}

fn load_db(config: &Config) -> Result<PickleDb, anyhow::Error> {
Ok(PickleDb::load(
config.deckshot_path.join("deckshot.db"),
pickledb::PickleDbDumpPolicy::AutoDump,
pickledb::SerializationMethod::Json,
SerializationMethod::Bin,
)?)
}

Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ async fn main() -> Result<(), anyhow::Error> {
}
}

for (index, path) in paths.iter().enumerate() {
for path in paths.iter() {
let screenshot: GameScreenshot = PathBuf::from(path).into();

match screenshot.upload(&**uploader, db.clone()).await {
Expand All @@ -104,7 +104,7 @@ async fn main() -> Result<(), anyhow::Error> {
}
}

db.lock().await.lpop::<String>("screenshots", index);
let _ = db.lock().await.lrem_value("screenshots", path);
}

tokio::time::sleep(Duration::from_secs(config.retrier_interval)).await;
Expand Down
10 changes: 8 additions & 2 deletions src/uploaders/noop.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use anyhow::anyhow;
use rand::{thread_rng, Rng};

use crate::{GameScreenshot, Uploader};

#[derive(Clone)]
Expand All @@ -15,7 +18,10 @@ impl Uploader for NoopUploader {
"noop"
}

async fn upload<'a>(&'a self, _screenshot: &'a GameScreenshot) -> Result<&'a GameScreenshot, anyhow::Error> {
unimplemented!();
async fn upload<'a>(&'a self, screenshot: &'a GameScreenshot) -> Result<&'a GameScreenshot, anyhow::Error> {
match thread_rng().gen::<bool>() {
true => Ok(screenshot),
false => Err(anyhow!("upload failed!")),
}
}
}

0 comments on commit ab686aa

Please sign in to comment.