Skip to content

Commit

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

# Dependencies enabled by feature `testing`
async-compatibility-layer = { version = "1.1", features = ["logging-utils"], optional = true }
Expand Down
9 changes: 5 additions & 4 deletions 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 All @@ -35,7 +36,6 @@ use std::{
ops::{Deref, DerefMut},
path::PathBuf,
};
use tempdir::TempDir;
use tide::{
http::headers::HeaderValue,
security::{CorsMiddleware, Origin},
Expand Down Expand Up @@ -270,13 +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 = {
// 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");
// 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 = temp_dir.path().to_path_buf();
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 e2b1214

Please sign in to comment.