1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use crate::bundle::{
  poller::{BundlePoller, PollResult, Result},
  Bundle,
};
use async_trait::async_trait;
use std::path::PathBuf;

pub struct LocalBundlePoller {
  dir: PathBuf,
}

impl LocalBundlePoller {
  pub fn new(dir: PathBuf) -> LocalBundlePoller {
    LocalBundlePoller { dir }
  }
}

#[async_trait]
impl BundlePoller for LocalBundlePoller {
  async fn poll(&self, active_bundle: &Option<Bundle>) -> Result<PollResult> {
    if active_bundle.is_none() {
      log::info!(
        "LocalBundlePoller: Updating bundle (Local dir: {}).",
        self.dir.display()
      );

      return Ok(PollResult::StaticUpdateReady {
        etag: None,
        path: self.dir.clone(),
      });
    }

    log::info!("LocalBundlePoller: Local dir. No update needed.");

    Ok(PollResult::Skip)
  }

  async fn retrieve(&self, _bundle_id: &str, _path: PathBuf) -> Result<()> {
    log::warn!("LocalBundlePoller: retrieve is not supported. Ignoring.");

    Ok(())
  }
}