Skip to content

Commit

Permalink
Merge pull request #239 from EspressoSystems/rand-in-public
Browse files Browse the repository at this point in the history
Add rand to public dir
  • Loading branch information
rob-maron authored Sep 24, 2024
2 parents d632236 + e2b1214 commit 36bccf5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ tracing-log = "0.2"
tracing-subscriber = { version = "0.3.18", features = ["env-filter", "json"] }
url = "2.5.0"
vbs = "0.1"
rand = "0.8"

# Dependencies enabled by feature `testing`
async-compatibility-layer = { version = "1.1", features = ["logging-utils"], optional = true }
Expand Down
7 changes: 6 additions & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use futures::future::{BoxFuture, FutureExt};
use include_dir::{include_dir, Dir};
use lazy_static::lazy_static;
use maud::{html, PreEscaped};
use rand::Rng;
use semver::Version;
use serde::{Deserialize, Serialize};
use serde_with::{serde_as, DisplayFromStr};
Expand Down Expand Up @@ -269,10 +270,14 @@ impl<State: Send + Sync + 'static, Error: 'static> App<State, Error> {
static DEFAULT_PUBLIC_DIR: Dir<'_> = include_dir!("$CARGO_MANIFEST_DIR/public/media");
lazy_static! {
static ref DEFAULT_PUBLIC_PATH: PathBuf = {
// Generate a random number to index into `/tmp` with
let mut rng = rand::thread_rng();
let index: u64 = rng.gen();

// The contents of the default public directory are included in the binary. The first time
// the default directory is used, if ever, we extract them to a directory on the host file
// system and return the path to that directory.
let path = PathBuf::from("/tmp/tide-disco/public/media");
let path = PathBuf::from(format!("/tmp/tide-disco/{}/public/media", index));
// If the path already exists, move it aside so we can update it.
let _ = fs::rename(&path, path.with_extension("old"));
DEFAULT_PUBLIC_DIR.extract(&path).unwrap();
Expand Down

0 comments on commit 36bccf5

Please sign in to comment.