Skip to content

Commit

Permalink
Revert "Revert "temp dir""
Browse files Browse the repository at this point in the history
This reverts commit b47f294.
  • Loading branch information
rob-maron committed Sep 24, 2024
1 parent b47f294 commit a82b0f3
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 7 deletions.
64 changes: 63 additions & 1 deletion 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
Expand Up @@ -66,7 +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"
tempdir = "0.3"

# Dependencies enabled by feature `testing`
async-compatibility-layer = { version = "1.1", features = ["logging-utils"], optional = true }
Expand Down
9 changes: 4 additions & 5 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ 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 All @@ -36,6 +35,7 @@ use std::{
ops::{Deref, DerefMut},
path::PathBuf,
};
use tempdir::TempDir;
use tide::{
http::headers::HeaderValue,
security::{CorsMiddleware, Origin},
Expand Down Expand Up @@ -270,14 +270,13 @@ 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();
// Create a randomly generated temporary directory to extract the public directory into
let temp_dir = TempDir::new("tide-disco").expect("failed to create temporary directory");

// 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(format!("/tmp/tide-disco/{}/public/media", index));
let path = temp_dir.path().to_path_buf();
// 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 a82b0f3

Please sign in to comment.